Skip to content

normalize: decode %2E in a path segment that isn't a dot-segment - #212

Open
dngr2 wants to merge 1 commit into
fastify:mainfrom
dngr2:decode-path-dot
Open

dngr2 wants to merge 1 commit into
fastify:mainfrom
dngr2:decode-path-dot

Conversation

@dngr2

@dngr2 dngr2 commented Aug 17, 2026

Copy link
Copy Markdown

normalize() leaves %2E percent-encoded everywhere in the path, so http://h/foo%2Ebar stays foo%2Ebar and equal('.../foo%2Ebar', '.../foo.bar') returns false. But . is unreserved (RFC 3986 §2.3) and should be decoded (§6.2.2.2) — the query and fragment normalizers already do, and every other unreserved byte (- _ ~) is decoded in the path.

The blanket decoded !== '.' guard exists to stop %2E%2E from decoding into .. and being collapsed by removeDotSegments (a traversal defense), but it is too broad. This decides per segment: %2E stays encoded only when the segment is exactly . or .., and decodes otherwise. /public/%2E%2E/admin is unchanged and the security-normalization tests still pass.

normalizePathEncoding kept every %2E percent-encoded to stop %2E%2E from
decoding into .. and being collapsed by removeDotSegments. That suppressed %2E
everywhere, so foo%2Ebar and %2Ehidden stayed encoded even though . is
unreserved (RFC 3986 2.3) and should be decoded (6.2.2.2) — the query and
fragment normalizers already do, and equal() reported RFC-equivalent URIs as
unequal. Decide per segment: keep %2E encoded only when the segment is . or ..,
decode it otherwise, so the %2E%2E traversal stays encoded.
@surbex11-alt

Copy link
Copy Markdown

Good

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a direct reintroduction of CVE-2026-6321: exact . and .. segments remain encoded, and the published traversal example still does not collapse or compare equal to /admin.

However, this weakens the fail-safe invariant introduced by that fix. normalizePathSegment() now turns encoded dots into raw traversal-like syntax whenever another character keeps the segment from being exactly . or ..:

/public/%2e%2e%2fadmin -> /public/..%2Fadmin
/public/%2e%2e%5cadmin -> /public/..%5Cadmin
/public/%2e%2e;/admin  -> /public/..;/admin

These values do not traverse inside fast-uri, so this is not a demonstrated fast-uri-local vulnerability. They do, however, increase parser-differential risk when a downstream component later decodes %2F, interprets backslashes, or strips matrix parameters. equal() also starts treating the encoded and mixed forms as equivalent.

This additionally contradicts the current README guarantee that %2E path escapes are preserved during normalization and comparison.

Before merging, please add differential cases for %2E combined with %2F, %5C, raw dots, semicolons, and nested encoding, and either preserve the existing %2E invariant or explicitly document and justify the narrower security boundary.

Validation on the merge result:

  • npm test: 1,704 tests passed
  • npm run lint: passed
  • npm run test:typescript: 7 assertions passed
  • short-segment adversarial check: no idempotence failure or direct traversal collapse

The repository has no package lock, so npm ci was not applicable; dependencies were installed using the repository's lockfile-free workflow.

This branch has not been deployed

No deployments
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.

3 participants