diff --git a/src/index.ts b/src/index.ts index ff9bddd..3c7e922 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); });