mirror of
https://github.com/movie-web/providers-api.git
synced 2025-09-13 10:43:26 +00:00
Handle invalid CORS origin
This commit is contained in:
@@ -30,11 +30,16 @@ app.use('*', (context, next) => {
|
|||||||
|
|
||||||
return cors({
|
return cors({
|
||||||
origin: (origin) => {
|
origin: (origin) => {
|
||||||
|
try {
|
||||||
const hostname = new URL(origin).hostname;
|
const hostname = new URL(origin).hostname;
|
||||||
if (allowedCorsHosts.includes(hostname)) {
|
if (allowedCorsHosts.includes(hostname)) {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
|
} catch (_) {
|
||||||
|
// If the Origin URL is not valid, return empty allowed origin
|
||||||
|
return '';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})(context, next);
|
})(context, next);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user