diff --git a/src/handlers/get.ts b/src/handlers/get.ts index 9f20a4b..bfcc5c0 100644 --- a/src/handlers/get.ts +++ b/src/handlers/get.ts @@ -32,7 +32,17 @@ const getHandler: Handler = async (request, env, ctx, cache) => { return responses.BAD_REQUEST; } - const bucketPath = mapUrlPathToBucketPath(requestUrl, env); + let bucketPath: string | undefined; + try { + bucketPath = mapUrlPathToBucketPath(requestUrl, env); + } catch (e) { + // decodeURIComponent throws a URIError for malformed URIs + if (e instanceof URIError) { + return responses.BAD_REQUEST; + } + + throw e; + } if (typeof bucketPath === 'undefined') { // Directory listing is restricted and we're not on diff --git a/src/util.ts b/src/util.ts index fed2322..639433c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -45,6 +45,7 @@ export function parseUrl(request: Request): URL | undefined { * @param env Worker env * @returns Mapped path if the resource is accessible, undefined * if the eyeball should not be trying to access the resource + * @throws if decodeURIComponet throws a {@link URIError} */ export function mapUrlPathToBucketPath( url: URL,