generated from saleor/saleor-app-payment-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add domain whitelist validation to webhooks
- Loading branch information
Showing
6 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { type NextApiRequest } from "next"; | ||
import { BaseError } from "@/errors"; | ||
import { env } from "@/lib/env.mjs"; | ||
|
||
const InvalidDomainError = BaseError.subclass("InvalidDomainError"); | ||
|
||
const MissingRefererError = BaseError.subclass("MissingRefererError"); | ||
|
||
export const ALLOWED_DOMAIN = ""; // todo: replace with domain from env config | ||
|
||
export function validateDomainWhiteList(request: NextApiRequest, whiteListedDomain: string) { | ||
const referer = request.headers.referer ?? env.AUTHORIZE_PAYMENT_FORM_URL; | ||
|
||
if (!referer) { | ||
throw new MissingRefererError( | ||
"Referer not found on the request. Make sure the request is coming from the same domain and 'strict-origin-when-cross-origin' referrerPolicy is set.", | ||
); | ||
} | ||
|
||
const isOriginAllowed = whiteListedDomain.includes(origin); | ||
|
||
if (!isOriginAllowed) { | ||
throw new InvalidDomainError(`Origin ${origin} is not allowed`); | ||
} | ||
} |