Skip to content

fix: preserve URI component case in equality - #207

Merged
mcollina merged 2 commits into
mainfrom
fix/equal-case-sensitive-components
Aug 14, 2026
Merged

mcollina merged 2 commits into
mainfrom
fix/equal-case-sensitive-components

Conversation

@mcollina

Copy link
Copy Markdown
Member

Correct equal() so normalization controls case folding instead of lowercasing the complete URI. This preserves case-sensitive path, query, fragment, userinfo, WebSocket resource, and URN NSS data while retaining scheme, host, and scheme-specific normalization.

This is a correctness and defense-in-depth fix for GHSA-wwpg-6wxh-phxg. No concrete security boundary bypass has been established, so it should not be characterized as a vulnerability.

@Tony133 Tony133 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.

LGTM! Quick question: normalizeComparableURI now also catches malformed object inputs (e.g. port: 99999), which used to slip through unchecked. On main, two identical malformed objects return equal() === true; per the README (https://github.com/fastify/fast-uri/blob/main/README.md?plain=1#L16), this branch correctly returns false. Intentional? Might be worth a regression test either way. For example:

test('URI Equals rejects malformed object input even when identical', (t) => {
  const suite = [
    {
      pair: [
        { scheme: 'http', host: 'example.com', port: 99999, path: '/x' },
        { scheme: 'http', host: 'example.com', port: 99999, path: '/x' }
      ],
      result: false
    }
  ]
  runTest(t, suite)
  t.end()
})

@mcollina

Copy link
Copy Markdown
Member Author

@Tony133 Yes, intentional. Object inputs are serialized and then passed through the same malformed-input validation as strings, so equal() fails closed when either input is invalid rather than treating two invalid values as equal.

I added the suggested regression coverage in 2a6412d. Thanks for catching the missing test!

@mcollina
mcollina merged commit 2372aa3 into main Aug 14, 2026
44 checks passed
@mcollina
mcollina deleted the fix/equal-case-sensitive-components branch August 14, 2026 22:06
mcollina added a commit that referenced this pull request Aug 22, 2026
* fix: preserve URI component case in equality

* test: cover malformed object equality
mcollina added a commit that referenced this pull request Aug 22, 2026
* fix: preserve URI component case in equality

* test: cover malformed object equality

Case-insensitive folding of scheme and host now happens during parse
(scheme validation backport) instead of a blanket toLowerCase.
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.

2 participants