Skip to content
Putting technology to work.
Insights to guide decisions and action.

Search articles

Hono 4.13.23: {a|b} constraints throw off except() matching

Table of contents · 7 items

When building an API with Hono, you might express a requirement like "only login and health checks should skip authentication" with except(). For example, app.use('/api/*', except('/api/:name{login|health}', bearerAuth({ token }))). With this pattern, Hono up to 4.13.22 did not apply authentication to /api/loginX or /api/xhealth either.

The cause was that when building the regular expression constraint for a path parameter (the {...} part), Hono did not wrap | in parentheses. The result was the regular expression ^login|health$, which matched anything that "starts with login" or "ends with health." This was fixed in Hono 4.13.23 (published to npm at 6:23 a.m. on November 27, Japan time). At the same time, advisory GHSA-586x-c76g-h528 (moderate severity, CVSS 5.3) was published in the Hono repository. It covers 4.5.0 through 4.13.22, as well as 5.0.0-rc.0 and rc.1.

In this article, we read the advisory, the fix commit and its tests, and ran 4.13.22 and 4.13.23 in a test environment to confirm which patterns and which routers cause the mismatch. We also tried rewrites for cases where you cannot upgrade right away.

The three fixes in 4.13.23

In the Hono repository, three merges from private forks ("Merge commit from fork") landed just before the 4.13.23 release. At 21:24 on November 26 (UTC; 6:24 a.m. on the 27th, Japan time), the same time as the release, three advisories and the release notes were published in the repository. All three are moderate severity.

  • | in path constraints (GHSA-586x-c76g-h528, CVSS 5.3, 0c91d4e): getPattern() in src/utils/url.ts now wraps the constraint's regular expression in parentheses, as in ^(?:...)$. This is the issue covered in this article. It affects 4.5.0 through 4.13.22
  • Requests using __proto__ or similar as the method name (GHSA-656w-x92q-369m, CVSS 5.9, d6e4804): TrieRouter now builds its per-method handler table as an object without a prototype. According to the advisory, a single request with __proto__ as the method name adds a property to Object.prototype, and subsequent responses in the same process return errors until a restart. Most runtimes reject such method names, but they get through with Node.js HTTP/2 or hono/method-override. Cloudflare Workers and Bun are said to be unaffected unless hono/method-override is used. It affects 4.8.0 through 4.13.22 (3.11.7 through 4.1.1 are also affected; those were fixed in 4.1.2)
  • URLs without a scheme and host (GHSA-mhwf-w6q6-q58w, CVSS 5.3, 19069e7): getPath() now correctly determines the start of the path when it receives a URL that begins with /, such as /public/admin/secret. According to the advisory, for requests without a usable Host header (HTTP/1.0 requests without Host, or an empty Host), Bun passes a path-only URL, and Hono dropped the first segment of the path. If you run Bun behind a reverse proxy that restricts by path, requests reach routes the proxy should have blocked. Node.js (@hono/node-server), Deno and Cloudflare Workers are said to be unaffected. It affects all versions up to 4.13.22

We did not test the second and third issues in a test environment.

5.0.0-rc.0 and rc.1 (npm's next) are also affected by all three, and as of November 30 there is no fixed release. As of November 30, getPattern() on the repository's v5 branch is also still in its pre-fix form.

As of November 30, the three advisories are not listed in the GitHub Advisory Database (the database that npm audit references). As a result, npm audit does not show a warning.

4.13.21 on November 23 and 4.13.22 on November 25 also included fixes through regular PRs, such as limiting JWT signatures to a single representation (#5673) and fixing parseBody() ignoring keys that contain constructor.prototype (#5681). The five advisories in 4.13.16 on November 1 and the four advisories in 4.13.18 on November 11 are covered in our article on Hono's five advisories.

Results on the old and new versions

Using the same paths as the official tests, we ran the following two apps in four configurations. This check used Node.js v22.23.5 and only sent requests into the app with app.request().

  1. Route constraint: register app.get('/api/:name{login|health}', ...) and app.get('/api/:name', ...), and see which handler the request reaches
  2. except(): with app.use('/api/*', except('/api/:name{login|health}', mw)), see whether mw is called

The configurations were the default hono, hono/quick (LinearRouter), hono/tiny (PatternRouter), and one specifying router: new TrieRouter().

hono 4.13.22
  [hono (SmartRouter)] route: /api/login=constrained /api/health=constrained /api/loginX=constrained /api/xhealth=constrained /api/admin=fallback
  [hono (SmartRouter)] except: /api/login=skipped /api/health=skipped /api/loginX=skipped /api/xhealth=skipped /api/admin=called
  [hono/quick (LinearRouter)] route: ... /api/loginX=fallback /api/xhealth=fallback ...
  [hono/quick (LinearRouter)] except: ... /api/loginX=skipped /api/xhealth=skipped /api/admin=called
hono 4.13.23
  [hono (SmartRouter)] route: ... /api/loginX=fallback /api/xhealth=fallback /api/admin=fallback
  [hono (SmartRouter)] except: ... /api/loginX=called /api/xhealth=called /api/admin=called

Diagram comparing whether the middleware in except('/api/:name{login|health}', mw) was called in Hono 4.13.22 and 4.13.23. In 4.13.22, the middleware was not called for /api/loginX and /api/xhealth in any of the default hono, hono/quick, hono/tiny and TrieRouter configurations. In 4.13.23, it was called in every configuration. When the constraint was wrapped in parentheses as {(?:login|health)}, it was called even in 4.13.22

The results show two things.

except() is affected regardless of the app's router. In 4.13.22, the middleware for /api/loginX and /api/xhealth was not called in any of the four configurations (skipped). Looking at the except() implementation, conditions passed as strings are evaluated by an internally created TrieRouter. Even if the app uses hono/quick or hono/tiny, except() matching is done with the pre-fix regular expression.

For route constraints, the result depends on the combination of routes. The default hono is SmartRouter, which picks RegExpRouter or TrieRouter based on the registered routes. In the example above, which registers both a constrained route and /api/:name, SmartRouter picked TrieRouter (app.router.name was SmartRouter + TrieRouter), and /api/loginX reached the constrained route. When only the constrained route was registered, RegExpRouter was picked, and /api/loginX returned 404 even in 4.13.22. With the hono/quick and hono/tiny routers, route constraints did not mismatch.

In 4.13.23, /api/loginX and /api/xhealth reached /api/:name in every configuration, and the except() middleware was also called.

Affected code pattern

Based on our test results, the fix diff and the advisory, the following patterns are affected (editorial summary).

  • Passing a constrained path containing | as a string in the except() condition (example: '/api/:name{login|health}')
  • Writing | in a route constraint when another route exists at the same position (when the default hono picks TrieRouter, or when TrieRouter is specified)

The former has the bigger impact. When the scope of except() widens, middleware such as authentication, rate limiting and CSRF checks stops applying to requests you never meant to exclude. In the latter, values the constraint was never meant to accept reach the constrained handler. If the handler assumes c.req.param('name') is either login or health, it runs with unexpected values.

Constraints that do not contain |, such as {[0-9]+}, mean the same thing with or without parentheses, so they were outside the scope of this check.

Rewrites until you can upgrade

When we ran the same check on 4.13.22 with the constraint wrapped in parentheses as {(?:login|health)}, /api/loginX and /api/xhealth reached /api/:name in all four configurations, and the except() middleware was also called. This approach writes the same parentheses yourself that the 4.13.23 fix adds.

// 4.13.22 以前でも、loginX・xhealth を対象外にしない書き方
app.use('/api/*', except('/api/:name{(?:login|health)}', bearerAuth({ token })))

However, this only addresses this one issue. The other two issues from the same day are not fixed without upgrading. Treat the rewrite as a stopgap until the update, and upgrade with npm i hono@^4.13.23.

Steps to check (editorial suggestion)

  1. Check the version. Look at npm ls hono, or the hono version in package-lock.json or pnpm-lock.yaml. If it is earlier than 4.13.23 or a 5.0.0-rc, it is affected. As of November 30, npm audit shows no warning, so judge by the version
  2. Find constraints containing |. Search route definitions and calls such as except()
grep -rnE ":[A-Za-z_]+\{[^}]*\|[^}]*\}" src/ --include=*.ts --include=*.tsx
grep -rn "except(" src/ --include=*.ts --include=*.tsx
  1. Update, then check the excluded paths. After upgrading, add tests that send requests to the paths excluded with except() and to similar paths that are not excluded (such as /api/loginX). This is the same form as the tests for this fix
  2. Review the handlers too. Check that they do not use constrained parameters on the assumption that the values have passed the constraint

A setup that runs Hono on Cloudflare Workers is introduced in our article on edge APIs with Hono and Cloudflare Workers.

Scope of verification

On November 27, 2026, we reviewed the diffs and tests of the fixes in the honojs/hono repository (commits from 4.13.20 to 4.13.23), the implementation and JSDoc of src/middleware/combine/index.ts, the publication timestamps on the npm registry, and github/advisory-database (additions since November 24) (document research). On November 30, we rechecked the three advisories in the honojs/hono repository and the v4.13.23 release notes, whether they are listed in the GitHub Advisory Database, getPattern() on the v5 branch, and the latest version on npm. For the path constraint issue, we installed hono 4.13.22 and 4.13.23 on Node.js v22.23.5 and tested four configurations with in-app requests (app.request()) (hands-on testing). We have not checked on an actual server or reproduced the other two issues from the same day.

For maintenance of business APIs built with Hono or reviews of authentication, contact us through Development, AI and automation consultation.

References

Share this articleXFacebook
Kakeru Suzuki

Fascinated by the possibilities of technology, has had a deep interest in programming and digital art since student days

Turn this article's theme into your company's next step

Concrete steps forward for your organization.

We organize your desired architecture, legacy systems, and operational requirements to formulate your next steps toward execution.

  • Desired architecture
  • Integration with existing environments
  • Operational requirements
Consult on development & operations initiatives

You can consult with us from the initial conceptual stage. Details from this article will be carried over to the inquiry form.

Receive the latest articles by email