Summary
In affected @fastify/express configurations, regular-expression-mounted Express middleware may not match requests when the plugin is registered under a parameterized prefix. If that middleware provides authentication or authorization, Fastify may still run the route handler without those checks, exposing protected routes to unauthenticated clients.
Affected context
The issue occurs when an application uses @fastify/express with a plugin registered under a parameterized prefix and mounts Express middleware using a regular expression. The risk is present when access control depends on that middleware and the corresponding Fastify route can still proceed when the middleware does not match.
Exploit preconditions
- Attack surface: HTTP requests to routes served by the affected Fastify application
- Required access: No prior authentication may be needed if the route relies solely on the skipped middleware for access control
- Trigger point: A request reaches a route within a plugin registered under a parameterized prefix
- Why exploitation is possible: The regular-expression middleware matcher does not account for the parameterized prefix, so Express skips the middleware while Fastify continues route processing
Why this happens
The plugin does not adjust regular-expression mount paths to reflect a parameterized plugin prefix. This creates inconsistent path interpretation between Express middleware matching and Fastify routing: a middleware intended to guard a route may not match the actual request path, even though the route handler still runs. This relates primarily to CWE-287: Improper Authentication when authentication checks are bypassed, and to CWE-436: Interpretation Conflict because the components interpret the request path differently.
Potential impact
- Unauthenticated clients may access routes that rely on the skipped middleware for authentication
- Clients may perform actions that should require authorization
- Sensitive data or operations exposed through affected routes could be accessed or misused
General mitigation guidance
Defensive patterns focus on ensuring access control is enforced consistently and does not depend on fragile path matching.
- Prefer authentication and authorization checks at a layer that reliably covers the route, such as explicit Fastify route-level hooks or centralized guards.
- Avoid relying solely on regular-expression-mounted middleware for protecting routes under parameterized prefixes.
- Treat all incoming requests as untrusted and verify identity and permissions before performing protected operations.
- Apply least privilege to application identities and limit the data and operations available to each route.
- Test middleware and route matching together across parameterized prefixes, including cases where middleware does not match.
How teams detect issues like this
- Review plugin registrations for parameterized prefixes combined with regular-expression middleware mounts.
- Use static analysis or code review checks to flag access-control logic that depends exclusively on middleware path matching.
- Add integration tests that verify unauthenticated requests are rejected for every protected route, including routes under parameterized prefixes.
- Enforce policy checks in CI or security reviews requiring protected routes to have explicit, testable authorization controls.

