Skip to content

fix(redact-url): handle malformed percent-encoding without throwing#128

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

fix(redact-url): handle malformed percent-encoding without throwing#128
CryptoJones merged 1 commit into
masterfrom
fix/redact-url-malformed-encoding

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Closes #127.

Summary

decodeURIComponent(rawName) on line 47 isn't try-wrapped. Invalid percent-encoding (%FF, %ZZ, etc.) raises URIError: URI malformed. Because pino-http calls redactUrl once per request, an unhandled URIError there would either skip the log line or fall back to logging the raw URL — leaking the very authkey=… / token=… / password=… value we're meant to redact.

Wrap the decode in try/catch; on URIError fall back to lowercasing the raw (still-encoded) name. The raw bytes are preserved in the output either way, so no value is lost; a percent-malformed name almost certainly isn't a real entry in the sensitive-param allowlist.

Test plan

  • npm run lint — clean
  • npm test — 485 passed (was 484 + new regression test), 15 skipped
  • New test verifies: malformed names don't throw; sensitive params after a malformed one are still redacted (loop recovery doesn't abort)

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

`decodeURIComponent` raises URIError on invalid percent sequences
(incomplete UTF-8 like `%FF`, or non-hex like `%ZZ`). pino-http
invokes `redactUrl` from its request serializer once per request,
so an unhandled URIError here would either skip the log line
entirely or — depending on pino's serializer-error fallback path —
log the raw URL, leaking the very `authkey=…` / `token=…` /
`password=…` value we're meant to redact.

Wrap the `decodeURIComponent(rawName)` call: on URIError, fall back
to lowercasing the raw (still-encoded) name. The raw bytes are
preserved either way in the output, so no value is lost; a
percent-malformed param name is almost certainly not a real
sensitive-list entry anyway.

Regression test verifies:
- malformed-name URLs don't throw (the bug)
- a sensitive param following a malformed one is still redacted
  (the loop must keep going after recovery, not abort)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit 5fbe3fa into master May 19, 2026
3 checks passed
@CryptoJones CryptoJones deleted the fix/redact-url-malformed-encoding branch May 19, 2026 05:54
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(redact-url): URIError on malformed %-encoding may leak query params to logs

1 participant