Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ALLOWED_DOMAIN_PATTERN env #200

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-bikes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-app-payment-stripe": minor
---

Added "ALLOWED_DOMAIN_PATTERN" env that can be used to allow/disallow specific Saleor instances
2 changes: 2 additions & 0 deletions src/lib/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const env = createEnv({
UPSTASH_TOKEN: z.string().optional(),
REST_APL_ENDPOINT: z.string().optional(),
REST_APL_TOKEN: z.string().optional(),
ALLOWED_DOMAIN_PATTERN: z.string().optional(),
},

/*
Expand Down Expand Up @@ -56,5 +57,6 @@ export const env = createEnv({
UPSTASH_TOKEN: process.env.UPSTASH_TOKEN,
REST_APL_ENDPOINT: process.env.REST_APL_ENDPOINT,
REST_APL_TOKEN: process.env.REST_APL_TOKEN,
ALLOWED_DOMAIN_PATTERN: process.env.ALLOWED_DOMAIN_PATTERN,
},
});
24 changes: 12 additions & 12 deletions src/pages/api/register.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/next";

import { saleorApp } from "../../saleor-app";
import { env } from "@/lib/env.mjs";

const allowedUrlsPattern = env.ALLOWED_DOMAIN_PATTERN;

/**
* Required endpoint, called by Saleor to install app.
Expand All @@ -9,17 +12,14 @@ import { saleorApp } from "../../saleor-app";
export default createAppRegisterHandler({
apl: saleorApp.apl,
allowedSaleorUrls: [
/**
* You may want your app to work only for certain Saleor instances.
*
* Your app can work for every Saleor that installs it, but you can
* limit it here
*
* By default, every url is allowed.
*
* URL should be a full graphQL address, usually starting with https:// and ending with /graphql/
*
* Alternatively pass a function
*/
(url) => {
if (allowedUrlsPattern) {
const regex = new RegExp(allowedUrlsPattern);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Security concern

Will this setting be available to our end users? If yes I'm wondering if there will be the case they provide regex that will cause app to break 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In L6 you can see that this is coming from ENV that is set on the server side.

So, OSS will leave it empty or lock into their own envs. Saleor Cloud sets this to be only Cloud


return regex.test(url);
}

return true;
},
],
});
Loading