Handle invalid CORS origin

This commit is contained in:
William Oldham
2023-12-19 17:41:56 +00:00
parent 341569e8d5
commit 6377a9ccaa

View File

@@ -30,11 +30,16 @@ app.use('*', (context, next) => {
return cors({ return cors({
origin: (origin) => { origin: (origin) => {
const hostname = new URL(origin).hostname; try {
if (allowedCorsHosts.includes(hostname)) { const hostname = new URL(origin).hostname;
return origin; if (allowedCorsHosts.includes(hostname)) {
return origin;
}
return '';
} catch (_) {
// If the Origin URL is not valid, return empty allowed origin
return '';
} }
return '';
}, },
})(context, next); })(context, next);
}); });