Severity:

CRITICAL RISK

(9.1)

AuthZ Bypass via Route Prefix (CWE-285) in Fastify

CVE-2026-6556

Analyzed

Vulnerability type

Category:

Authorization Bypass

CWE:

CWE-285

Impact:

Bypass of authentication and authorization middleware on scoped routes

Severity:

CRITICAL RISK

(9.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A middleware prefix handling flaw in @fastify/express allows routes inside prefixed plugin scopes to be matched without their intended path-scoped middleware when non-string mount paths are used.

When applications rely on scoped middleware for authentication, authorization, rate limiting, or auditing, attackers can send requests to prefixed routes that bypass these controls and gain unintended access.

Affected context

This vulnerability arises in Node.js applications using Fastify with the @fastify/express plugin, specifically when:

  • Plugins are registered with a prefix (e.g., /api/v1), and
  • Middleware is mounted using non-string path arguments (arrays of paths or regular expressions), and
  • Those middleware functions are expected to enforce security or auditing at specific route paths.

In this context, prefixed routes still match and execute route handlers, but the associated middleware is not invoked because their mount paths are not correctly rewritten with the plugin prefix.

Exploit preconditions

  • Attack surface: HTTP endpoints exposed by Fastify applications using @fastify/express with prefixed plugins.
  • Required access: Ability to send HTTP requests to prefixed routes (typically remote, unauthenticated network access).
  • Trigger point: Requests directed at routes inside a plugin scope that rely on path-scoped middleware registered with array or RegExp mount paths.
  • Why exploitation is possible: The plugin prefix is only applied to string mount paths; arrays and regular expressions remain unprefixed, so middleware path matching fails while the route itself still matches and executes, leaving protected functionality reachable without the intended checks.

Why this happens

The core issue is inconsistent handling of route prefixes when applying middleware mount paths within the @fastify/express integration.

Only string-based path arguments receive the plugin prefix, while non-string paths—such as arrays and regular expressions—are left unchanged. This breaks the assumed invariant that all paths inside a prefixed scope share the same prefix.

Under CWE-285 (Improper Authorization), this manifests as security-critical middleware (auth, rate limiting, auditing) being logically detached from the routes they are intended to protect, allowing unauthorized requests to reach those routes without undergoing the configured checks.

Potential impact

  • Unauthorized access to routes that were intended to require authentication.
  • Bypass of authorization checks and role or permission enforcement.
  • Circumvention of rate limiting and abuse-prevention controls.
  • Missing audit logging or compliance trails for sensitive operations.
  • Increased exposure of internal APIs or administrative functionality.

General mitigation guidance

Effective mitigation focuses on aligning middleware scoping logic with route prefix behavior and reducing implicit assumptions about path matching.

Common defensive patterns include:

  • Using consistent, string-based mount paths in prefixed plugin scopes so that prefix rewriting is predictable and uniform.
  • Avoiding reliance on complex path arrays or regular expressions for critical security middleware unless their interaction with prefixes is explicitly validated.
  • Centralizing authentication and authorization logic at a higher, non-prefixed level (e.g., global hooks or root-level middleware) so that security does not depend on per-scope rewriting.
  • Designing middleware registration to default to protecting all routes within a trust boundary, rather than relying on fine-grained path filters that can desynchronize from routing behavior.
  • Applying least-privilege principles in route design, so sensitive operations are isolated and guarded by multiple layers of checks rather than a single path-based middleware.

How teams detect issues like this

Teams can detect this class of issue by combining static inspection, configuration review, and runtime verification:

  • Static analysis or code search for middleware registration using arrays or regular expressions in @fastify/express plugins that also use prefixes, especially where those middleware functions perform authentication, authorization, or rate limiting.
  • Code review checklists that explicitly ask whether middleware mount paths are correctly aligned with route prefixes, and whether any non-string paths might be skipped.
  • Automated policy checks in CI that flag prefixed plugin registrations where security-sensitive middleware is not applied globally or where path filters are inconsistent with declared route paths.
  • Integration tests that exercise protected routes via their full, prefixed paths and assert that the expected middleware behavior (auth challenge, denial, logging, throttling) occurs.

Sources

SourceLink
cna.openjsf.orgcna.openjsf.org/security-advisories.html
github.comgithub.com/fastify/fastify-express/security/advisories/GHSA-3wf5-7852-vcfq

Frequently asked

questions

It can expose protected routes without their intended security checks, which may include sensitive administrative or data-modifying endpoints. The extent of compromise depends on what those routes do, but in many cases this can be a high-impact authorization failure.

Typically, only network access to the Fastify application is required. If prefixed routes are exposed over HTTP and rely on scoped middleware registered with non-string paths, an attacker can invoke them directly without special privileges.

Ensure that security-critical middleware (authentication, authorization, rate limiting, auditing) is applied in a way that does not depend on fragile prefix rewriting. Prefer global or clearly scoped middleware using simple, string-based paths, and verify that all protected routes are covered by those checks.

Treat authorization and authentication as cross-cutting concerns applied at stable boundaries, not as per-route afterthoughts. Avoid complex path-based conditions for critical middleware, document how prefixes interact with middleware registration, and enforce these rules through code review, automated checks, and tests that validate that protected routes cannot be reached without passing the intended controls.

Find out what's already
exploitable in your codebase.