Severity:

HIGH RISK

(7.3)

Access Control Bypass in @koa/router When Using

CVE-2026-9495

Awaiting Analysis

Vulnerability type

Category:

Access Control Bypass

CWE:

CWE-284

Impact:

Authentication and Authorization Bypass

Severity:

HIGH RISK

(7.3)

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 logic flaw in @koa/router causes middleware to be silently dropped from the execution chain when a router prefix includes path parameters.

When critical middleware such as authentication, authorization, rate limiting, or input sanitization is skipped, attackers may access protected routes or send unsafe input without the intended safeguards being applied.

Affected context

This vulnerability appears in Node.js applications using @koa/router versions 14.0.0 up to (but not including) 15.0.0 where:

  • Routers are configured with a prefix that contains one or more path parameters (for example, /:tenant/api or /v:version/users)
  • Security-sensitive middleware (authentication, authorization, rate limiting, validation, sanitization, logging, etc.) is attached to the router or routes under that prefix
  • Application developers assume that all requests matching those routes will pass through the configured middleware chain

Under these conditions, some middleware functions may be silently skipped, creating an inconsistent and unintuitive protection boundary.

Exploit preconditions

  • Attack surface: HTTP(S) endpoints served via Koa that use @koa/router with parameterized prefixes
  • Required access: Ability to send HTTP requests to affected routes; no prior authentication is necessary if the skipped middleware was intended to enforce it
  • Trigger point: Requests to routes under a router that uses a prefix with path parameters, where middleware is expected to run but is silently dropped
  • Why exploitation is possible: The router's internal handling of prefix path parameters causes certain middleware to be omitted from the execution chain without error, so routes that appear protected in code can be reached without the corresponding checks being executed

Why this happens

The root cause is a routing and middleware composition bug in @koa/router where prefixes containing path parameters interact incorrectly with the middleware chain assembly.

Instead of reliably composing all registered middleware in the order defined, the router logic can silently omit middleware when a prefixed route includes parameters in the prefix. This leads to inconsistent enforcement of access control and request processing rules.

Conceptually, this maps to CWE-284: Improper Access Control, because the application code indicates that certain resources should be protected by middleware-based checks, yet the underlying routing framework fails to apply those controls as intended, resulting in a practical bypass of authentication, authorization, and other security-related middleware.

Potential impact

  • Attackers could access endpoints that developers intended to protect with authentication middleware
  • Attackers may bypass fine-grained authorization checks tied to roles, tenants, or scopes
  • Rate-limiting middleware may not execute, allowing abuse such as brute-force attempts or resource exhaustion
  • Input validation or sanitization middleware may be skipped, increasing the risk of injection or data integrity issues
  • Security logging or auditing middleware may not run, reducing visibility into malicious or unexpected activity

General mitigation guidance

Effective mitigation focuses on ensuring that middleware execution does not depend on fragile or ambiguous router prefix configurations:

  • Avoid relying on prefixes that contain dynamic path parameters for security-critical middleware; instead, attach such middleware directly to specific routes or sub-routers without parameterized prefixes
  • Structure routers so that authentication and authorization middleware are defined at clearly separated layers (for example, a top-level security router) where route paths are explicit and stable
  • Introduce defensive checks inside downstream handlers (e.g., verifying that authentication context is present and valid) rather than assuming middleware always ran
  • Apply least-privilege principles: treat unauthenticated or unauthorised requests as the default and require explicit confirmation before performing sensitive actions
  • Use centralized, reusable middleware configurations for critical protections, and avoid complex or heavily parameterized routing structures for those paths

How teams detect issues like this

Detection generally involves both code-centric and runtime-centric approaches:

  • Static/code review: Look for @koa/router usage where router.prefix() or equivalent mechanisms include path parameters (such as /:id, /:tenant, /v:version) and where security-relevant middleware is attached at the router level
  • Pattern-based checks: Define internal guidelines or linters that flag parameterized prefixes on routers that are expected to enforce authentication, authorization, or rate limiting
  • Automated testing: Add integration tests that assert critical middleware effects (such as requiring authentication, enforcing tenant boundaries, or applying rate limits) for routes under parameterized prefixes
  • Runtime monitoring: Inspect access logs and authorization metrics for anomalies, such as protected routes being accessed without corresponding authentication events, which can indicate skipped middleware

Sources

SourceLink
github.comgithub.com/koajs/router/commit/d53e17f284557b1f417946f9807ee52290c3c759
github.comgithub.com/koajs/router/issues/202
github.comgithub.com/koajs/router/pull/206
security.snyk.iosecurity.snyk.io/vuln/SNYK-JS-KOAROUTER-12215044

Frequently asked

questions

Exploitability depends on how heavily your application relies on router-level middleware combined with parameterized prefixes. If critical checks (like authentication or authorization) are attached at affected router levels, attackers who can reach those endpoints may access them without the intended protections.

Not necessarily. If the skipped middleware was responsible for enforcing authentication, an unauthenticated attacker could directly call impacted routes. If the skipped logic handled authorization or tenant isolation, even authenticated users could escalate privileges or cross tenant boundaries.

The safest pattern is to ensure that security-critical middleware does not rely on parameterized router prefixes. Attach authentication and authorization middleware either globally or to specific route definitions with explicit paths, and validate that every sensitive route performs required checks within its handler or a clearly associated middleware chain.

Adopt routing and middleware design patterns where security concerns are centralized and testable, avoid complex or dynamic prefixes for critical paths, enforce internal code review guidelines around access control configuration, and maintain automated tests that verify authentication and authorization behavior for all high-value routes.

Find out what's already
exploitable in your codebase.