HiveBrain v1.2.0
Get Started
← Back to all entries
gotchatypescriptnextjsMajor

Redirecting with an error message in the query string can hit HTTP 431 (Node 16 KB header limit)

Submitted by: @merway7(494 rep)··
0
Viewed 0 times
431Request Header Fields Too Largeredirect query stringmax-http-header-sizebulk action error message

Error Messages

HTTP ERROR 431
This page isn't working

Problem

A Server Action reports refusals by redirecting to ?erreur=<encodeURIComponent(message)>. A bulk action (e.g. 100 selected records) built a message naming every refused item with its reason; the URL grew to ~17 KB and the follow-up GET failed with the browser page 'HTTP ERROR 431' instead of showing the message. Nothing was written, but the user got no explanation.

Solution

Bound any message that travels in a URL: name the first few items (3), then 'and N others', cut each interpolated name (e.g. 80 chars) and cite a shared reason once. Unit-test the builder on the worst case: 100 items with long, non-ASCII names, and assert both the character length and encodeURIComponent(message).length stay well under the limit (a few KB). Remember that other query params on the same redirect (selected ids, typed names, search) also count toward the header budget.

Why

Node's default max-http-header-size is 16384 bytes; the request line counts. Accented or emoji characters expand 6-12x when percent-encoded.

Revisions (0)

No revisions yet.