Skip to content

fix(error-handler): redact sensitive query params in the 404 echo path#132

Merged
CryptoJones merged 1 commit into
masterfrom
fix/notfound-redact-url
May 19, 2026
Merged

fix(error-handler): redact sensitive query params in the 404 echo path#132
CryptoJones merged 1 commit into
masterfrom
fix/notfound-redact-url

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Closes #131.

Summary

notFound returned path: req.originalUrl verbatim. An SDK bug that puts the authKey on the query string instead of the authKey header (GET /v1/foo?authKey=…) would 404 against an unmatched path and receive its own secret echoed back in the response body — at which point any upstream proxy logging responses, or the client's own error logger capturing 4xx bodies, would persist the secret far from where it was supposed to live.

pino-http's request logger already routes req.url through redactUrl for exactly this reason. Use the same helper in notFound so the 404 echo gets the same treatment.

Test plan

  • npm run lint — clean
  • npm test — 491 passed (was 490 + new regression test), 15 skipped
  • New test asserts ?authKey=… becomes ?authKey=<REDACTED> in the echoed path while non-sensitive params (?q=ok) are preserved

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

`notFound` returned `path: req.originalUrl` verbatim. An SDK bug
that puts the authKey on the query string instead of the
authKey header (`GET /v1/foo?authKey=...`) would 404 against an
unmatched path and receive its own secret echoed back in the
response body — at which point any upstream proxy logging
responses, or the client's own error logger capturing 4xx bodies,
would persist the secret far from where it was supposed to live.

pino-http's request logger already routes `req.url` through
`redactUrl` for exactly this reason. Use the same helper here so
the 404 echo gets the same treatment. Pin behavior with a test
asserting `?authKey=...` becomes `?authKey=<REDACTED>` in the
echoed path while non-sensitive query params (`?q=ok`) are
preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit d5882b9 into master May 19, 2026
3 checks passed
@CryptoJones CryptoJones deleted the fix/notfound-redact-url branch May 19, 2026 06:07
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

Successfully merging this pull request may close these issues.

security(error-handler): notFound echoes raw query string — leaks authKey if a client mis-sends it as ?authKey=

1 participant