Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› Bug Report β€” Response.redirect() doesn't throw error on too large header #3486

Open
Frigyes06 opened this issue Feb 6, 2025 · 0 comments

Comments

@Frigyes06
Copy link

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:

export default {
	async fetch(request, env, ctx): Promise<Response> {
		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<Env>;

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant