fix(geocoder): reject control chars in :id to prevent NUL-byte 500#13
Merged
Conversation
A NUL byte anywhere in the :id path param passed the PAND / NUMMERAANDUIDING startsWith() branch and reached Postgres as a bind parameter, raising `invalid byte sequence for encoding "UTF8": 0x00`. That error escaped the route handler and surfaced as HTTP 500 instead of a clean 404 — letting a client trivially generate 500s and pollute the error log (no injection risk; queries are parameterized). detectFormat now classifies any input containing a C0 control char or DEL (0x7f) as "unknown", so every product route returns 404. Found via input fuzzing of the live WS (~4.7M requests over 4h; the NUL byte was the only 5xx class observed). Adds 5 regression cases. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A NUL byte (
%00) anywhere in the:idpath parameter caused HTTP 500 instead of a clean 404 on every/v4/product/*route.detectFormatmatched theNL.IMBAG.PAND./NL.IMBAG.NUMMERAANDUIDING.prefix viastartsWith()and passed the NUL-containing id straight into the SQL bind parameter. Postgres rejects it:That error escaped the route handler →
onError→500 {"message":"Internal server error"}. No injection risk (queries are parameterized), but a client could trivially spam 500s and flood the error log.Fix
detectFormatnow classifies any input containing a C0 control character or DEL (0x7f) as"unknown", so the route returns 404. Central guard at the shared classifier — covers analysis / risk / light / statistics in one place.How it was found
Input-fuzzing the live WS — ~4.7M requests over a 4h aggressive run (real-ID corpus + targeted mutators + malformed HTTP). The NUL byte was the only 5xx class observed across the entire run; a Schemathesis property pass found no other server error.
Verification
bun test— 49 pass (5 new regression cases for NUL/tab/DEL).bun run typecheck— clean.🤖 Generated with Claude Code