cloudflare / cloudflare/workerd
🐛 Bug Report — Response.redirect() doesn't throw error on too large header
- 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:

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
Assessment
This issue has not been assessed yet.