GHSA-h7mg-cq63-vhpq: Hono: RegExpRouter skips wildcard middleware for some route sets and for paths with an encoded line terminator
Summary
RegExpRouter, which the default SmartRouter selects for most applications, skipped wildcard middleware in three cases, so a route handler ran without the middleware registered for it:
1. Middleware whose parameter is written with the explicit default pattern, such as /api/:tenant{[^/]+}/admin/, was not applied to a route written as /api/:tenant/admin/:id. (since 4.13.0) 2. Middleware on /admin/ was not applied to a route registered on /admin for paths under /admin/. (since 4.1.4) 3. For a path with an encoded line terminator (%0A, %0D, %E2%80%A8, %E2%80%A9), no wildcard pattern matched, so the request reached the not-found handler without any wildcard middleware. (since 4.4.0)
TrieRouter, LinearRouter and PatternRouter apply the middleware in all three cases.
Details
RegExpRouter decides at registration time which wildcard middleware covers which route. In cases 1 and 2 it treated patterns that match the same requests as different ones. In case 3 the compiled wildcard did not match line terminators.
The fix derives the coverage from the structure of the registered paths and lets wildcards match line terminators. It also corrects other differences from the other routers (a wildcard in the middle of a path with parameters, duplicate middleware, middleware on static routes), and rejects custom patterns that can match the empty string, such as {[0-9]}, with UnsupportedPathError. PreparedRegExpRouter data must be regenerated.
Impact
An unauthenticated client can reach a route handler, or the not-found handler, without the authentication or authorization middleware registered on a wildcard path.
This affects applications that use RegExpRouter, directly or through the default SmartRouter, and rely on wildcard middleware for authentication or authorization.
Workarounds
Use new Hono({ router: new TrieRouter() }).
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/honoto a version that resolves this vulnerability.Fixed in 4.13.16 - Configuration
Use `new Hono({ router: new TrieRouter() })` instead of RegExpRouter or the default SmartRouter.
Hono router = TrieRouter - Operational
Regenerate `PreparedRegExpRouter` data.
Event History
Frequently Asked Questions
Which applications are most likely to be affected?
Applications using Hono's default SmartRouter are most likely to be affected, because SmartRouter selects RegExpRouter for most applications. Applications explicitly using TrieRouter, LinearRouter, or PatternRouter apply the middleware in all three described cases.
What route definitions create a middleware-bypass risk?
The risk exists when wildcard middleware uses an explicit default parameter pattern such as /api/:tenant{[^/]+}/admin/* while a covered route is registered as /api/:tenant/admin/:id. It also exists when middleware is registered on /admin/* and a route is registered on /admin* for requests below /admin/.
Can a specially encoded request bypass wildcard middleware?
Yes. Paths containing an encoded line terminator—%0A, %0D, %E2%80%A8, or %E2%80%A9—did not match wildcard patterns in RegExpRouter. Such requests reached the not-found handler without wildcard middleware being applied.
What can be done if updating is not immediately possible?
Use TrieRouter, LinearRouter, or PatternRouter instead of RegExpRouter, as those routers apply wildcard middleware in all three cases. Review routes and middleware for the route-pattern combinations described above.