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({
origin: (origin) => {
const hostname = new URL(origin).hostname;
if (allowedCorsHosts.includes(hostname)) {
return origin;
try {
const hostname = new URL(origin).hostname;
if (allowedCorsHosts.includes(hostname)) {
return origin;
}
return '';
} catch (_) {
// If the Origin URL is not valid, return empty allowed origin
return '';
}
return '';
},
})(context, next);
});