cloudflare / cloudflare/workerd

🐛 Bug Report — Response.redirect() doesn't throw error on too large header

Open
#3,486 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

I was working on a page that would take an arbitrary text input from a user and redirect them to a domain with the location header set to the data input. However, this call generates an Internal error when called with a location that exceeds the limit of the location header. It dies not throw an error on the JS/TS side which could be handled.

## Example code:
```ts
export default {
async fetch(request, env, ctx): Promise {
var redirectUrl = String(new URL(request.url + "*long data, like entire bee movie script here*"))
try {
return Response.redirect(redirectUrl)
} catch(err) {
console.log(err)
}
},
} satisfies ExportedHandler;
```

## Expected behavior:
The Response.redirect() throws an error which is handled (in this case logged to console), and the program continues

## Current behavior:
The process throws an internal error:
```
Error: internal error
at async Object.fetch (file:///home/frigyes/qr-code-generator/node_modules/miniflare/dist/src/workers/core/entry.worker.js:1029:22)
```

Wrangler logs:
```

✘ [ERROR] workerd/jsg/util.c++:274: error: e = kj/compat/http.c++:5772: failed: protocolError.description = header too large.

stack:
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@34d3ef1
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@35128db
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@3513752
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@4e501af
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@3519900
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@3530070
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@221dc10
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@2ab51a0
/home/frigyes/qr-code-generator/node_modules/@cloudflare/workerd-linux-64/bin/workerd@29acc60;
sentryErrorContext = jsgInternalError
```

Error when run on CF Workers:

![Image](https://github.com/user-attachments/assets/94e37137-f4dd-4bc9-9a37-a904a1b5cad5)

I might be totally in the wrong here, but I would expect the function to throw at least a generic error instead of crashing and burning.

Please let me know if I'm dumb and/or if you need more details.

Frigyes

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.