Skip to content

Commit 7e776fe

Browse files
authored
Bugfix/allow cors (#941)
* Allowed vercel automatic branch deployments in CORS policy * Reject non-origin requests
1 parent 175271b commit 7e776fe

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

app.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,31 @@ if (!Services.env.isProduction()) {
4343
credentials: true
4444
};
4545
} else {
46-
// TODO: change this when necessary
4746
corsOptions = {
48-
origin: [
49-
`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`,
50-
`https://${process.env.FRONTEND_ADDRESS_BETA}`,
51-
`https://docs.mchacks.ca`
52-
],
47+
origin: (origin, callback) => {
48+
const allowedOrigins = [
49+
`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`,
50+
`https://${process.env.FRONTEND_ADDRESS_BETA}`,
51+
`https://docs.mchacks.ca`
52+
];
53+
54+
const regex = /^https:\/\/dashboard-[\w-]+\.vercel\.app$/;
55+
56+
if (
57+
allowedOrigins.includes(origin) || // Explicitly allowed origins
58+
regex.test(origin) // Matches dashboard subdomains
59+
) {
60+
callback(null, true);
61+
} else {
62+
callback(new Error('Not allowed by CORS'));
63+
}
64+
},
5365
credentials: true
5466
};
5567
}
5668

69+
70+
5771
app.use(cors(corsOptions));
5872
app.use(Services.log.requestLogger);
5973
app.use(Services.log.errorLogger);

0 commit comments

Comments
 (0)