Summary
In @fastify/express, inconsistent handling of Unicode characters between Fastify routing and Express mount-path matching can cause path-scoped middleware to be skipped. When case-insensitive routing is enabled and an affected mount-path letter is involved, an unauthenticated request may reach a handler without the intended authentication, authorization, or rate-limiting checks.
Affected context
The issue affects applications using @fastify/express where Fastify is configured for case-insensitive routing. It becomes relevant when a protected handler is reached through a mount path containing a letter affected by Unicode-to-ASCII case folding, and Express middleware compares the decoded path without applying equivalent normalization.
Exploit preconditions
- Attack surface: An HTTP endpoint served through Fastify with @fastify/express middleware
- Required access: No authentication is required if the affected route is reachable by an unauthenticated client
- Trigger point: Request routing and Express mount-path matching
- Conditions: Case-insensitive routing must be enabled, the mount path must contain an affected letter, and security middleware must be scoped to that path
- Why exploitation is possible: Fastify and Express interpret the request path differently, allowing routing to select a protected handler while the corresponding middleware does not match
Why this happens
The underlying bug is inconsistent case and Unicode normalization across two routing components. Fastify folds certain non-ASCII characters to ASCII letters during case-insensitive route matching, while @fastify/express matches mount paths against the decoded path without equivalent folding. This can cause a security middleware check to be bypassed, mapping primarily to CWE-863: Incorrect Authorization and also relating to CWE-178: Improper Handling of Case Sensitivity.
Potential impact
- An unauthenticated client may reach handlers intended to require authentication
- Authorization checks implemented as path-scoped middleware could be bypassed
- Rate limits or other middleware controls may not apply to affected requests
- Exposed handlers could enable unauthorized access to data or operations, depending on application behavior
General mitigation guidance
Defensive approaches focus on consistent path interpretation and ensuring security checks cannot be skipped because of routing differences.
- Use routing and middleware patterns that apply equivalent normalization and matching rules
- Avoid relying solely on path-scoped middleware for critical authorization decisions; enforce access checks at the handler or service boundary as well
- Reduce input ambiguity by validating and canonicalizing paths consistently before routing and policy checks
- Configure routing securely by default and disable case-insensitive matching when it is not needed
- Apply least privilege to handlers and downstream operations so a missed middleware check has limited consequences
How teams detect issues like this
- Review route and middleware registration for security controls mounted only on specific path prefixes
- Use static analysis or code review checks to flag inconsistent path normalization and case-sensitivity behavior across routing layers
- Test routing policies with Unicode and case-variant paths, verifying that protected handlers always execute their required checks
- Enforce policy checks at handler boundaries and include middleware coverage requirements in automated tests

