Skip to content

Commit

Permalink
fix: return a 400 for malformed URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
flakey5 committed Nov 12, 2023
1 parent b854489 commit 4a183bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/handlers/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4a183bb

Please sign in to comment.