The path you priced is not the path they request: an x402 route-match census
An x402 seller prices a route by writing a string: "GET /api/users/:id". The buyer's request carries a different string, and between the two sits every normalization rule of the web server. We sent 49 non-canonical request targets at ten x402 server adapters today. The current SDKs charged for all of them. The deprecated package still on npm served ten of them for free.
This is the oldest unglamorous bug in paid HTTP. The middleware decides "is this route priced?" by matching the request path against a compiled pattern. The router decides "which handler runs?" by matching the same request against its own pattern. If the two disagree about what the path is, the handler runs and the payment does not.
We have written about the specific instances before: the HEAD and OPTIONS bypasses that shipped as fixes in October, the status-capture gaps in the nine paid-response adapters, the Java module that nobody publishes. This post measures the class instead of one instance.
The gate nobody specified
We read the x402 v2 specification at commit 3eb54b2: 733 lines in the core document and 253 in the HTTP transport. Neither says anything about path canonicalization. Neither says which spelling of a URL decides that a resource is priced. The only occurrence of the word "canonical" in the core spec refers to the wire location of the PAYMENT-REQUIRED header.
That silence is not an oversight so much as a boundary. x402 describes what a 402 challenge contains and how a payment payload is verified and settled. "Which requests are priced" is left to the resource server, and in practice to the SDK's route matcher. So the gate has no normative definition, and every implementation has written its own — ten of them, in four languages.
The corpus and the control
We built a harness with one rule: every seller exposes the same three paid routes, and an identical seller runs next to it with the x402 middleware removed. The control answers one question the middleware cannot answer for itself — did the router actually reach the paid handler?
The routes are a literal (GET /api/premium), a parameter (GET /api/users/:id) and a wildcard (GET /files/*). The corpus is 49 request targets: percent-encoded separators (%2F, %2f, %5C), raw backslashes, dot segments and their encodings (/./, /../, %2e%2e), duplicate and trailing slashes, matrix parameters (;x), case variation, line terminators (%0A, %0D), malformed escapes (%, %c0), absolute-form targets (GET http://evil.example/...), fragments, and HEAD on each route.
Each target goes out over a raw socket, written into the request line verbatim. No HTTP client normalizes it on the way out — that detail matters, because fetch and curl without --path-as-is will quietly fix several of these vectors before they leave your machine.
Four outcomes per cell. Charged: the control served the handler, the middleware answered 402. Bypass: the control served the handler and so did the middleware, unpaid. Over-gate: the control 404s, the middleware still demands payment. Free 404: both refuse, which is the boring correct case.
What each framework calls "the path"
Before the results, the cause. We instrumented a bare Express app and a bare Hono app to print exactly what the middleware would receive.
// request line: GET /files/a%0Ab
express req.path = "/files/a%0Ab"
hono c.req.path = "/files/a\nb"
// request line: GET /api/x/%2e%2e/premium
express req.path = "/api/x/%2e%2e/premium"
hono c.req.path = "/api/premium"
// request line: GET /%61pi/premium
express req.path = "/%61pi/premium"
hono c.req.path = "/api/premium"
// request line: GET /api/users/4%2F2
express req.path = "/api/users/4%2F2"
hono c.req.path = "/api/users/4%2F2"
Express hands over the raw target. Hono hands over a path that has been percent-decoded and had its dot segments resolved — except for encoded separators, which it keeps escaped. Fastify's request.url is the raw request-target including the absolute form, which is why its adapter now rejects those with 400 (that was PR #3577, merged 2 October). Go's net/url gives you both views, EscapedPath() and URL.Path. Starlette and Werkzeug dispatch literal routes on the decoded path while exposing the raw one separately.
So "the path" is at least four different strings depending on who you ask, and the x402 middleware is the component that has to be right about all of them.
The current SDKs hold
We ran the corpus against @x402/* 2.32.0 (npm, 20 November), the Go module at go/v2.32.0, and PyPI x402 2.29.0 (20 November). Nine server adapters, each with its router-only twin: Express 4.22.3, Express 5.3.0, Hono 4.13.21 behind @hono/node-server 2.1.11, Fastify 5.12.8, Go 1.27.4 net/http ServeMux, Gin 1.11.0, Echo 4.16.2, FastAPI 0.162.5 on Starlette 1.7.0, Flask 3.1.3 on Werkzeug 3.1.9.
// 49 targets per adapter. bypass = handler ran, no payment.
express 4 charged 26 over-gate 10 free 13 bypass 0
express 5 charged 25 over-gate 11 free 13 bypass 0
hono charged 26 over-gate 12 free 11 bypass 0
fastify charged 22 over-gate 12 free 14 bypass 0 (+1 400/400)
go nethttp charged 22 over-gate 10 free 17 bypass 0
go gin charged 20 over-gate 8 free 21 bypass 0
go echo charged 18 over-gate 14 free 17 bypass 0
fastapi charged 21 over-gate 16 free 12 bypass 0
flask charged 24 over-gate 12 free 13 bypass 0
Zero bypasses in 441 probe pairs. That is a real result and worth saying plainly: the v2 route matcher currently does its job across three languages and nine frameworks.
It gets there with five separate defenses, each of which was once a bug. The matcher decodes percent-escapes one segment at a time and re-escapes any separator the decode yields, so a decoded byte can never create a segment boundary the router did not see. It compiles patterns with the s (dotAll) flag, so a wildcard still matches a path containing a line feed. A trailing /* compiles an optional suffix, so /files and /files/ both match. Unmatched HEAD falls back to the GET route. And it matches twice: against the escaped path and against the framework's own decoded routing view, requiring payment if either matches.
That last one is the structural fix. Instead of guessing which normalization the framework applies, the adapters pass both strings and the matcher takes the union. You can see it in the core resource server, in go/http/server.go, and in the Python base class, with the same comment in all three.
The package still on npm does not
x402 v1 is deprecated. Its README says so: "It is deprecated and will only receive security patches." The last publish of x402, x402-express and x402-hono was 1.2.0 on 16 April 2026. Last week those packages were downloaded 717,475, 4,148 and 705 times.
We ran the same corpus against x402-express 1.2.0 and x402-hono 1.2.0, against the same router-only controls.
legacy express 4 charged 16 bypass 10 over-gate 11 free 12
legacy express 5 charged 16 bypass 9 over-gate 11 free 13
legacy hono charged 16 bypass 10 over-gate 13 free 10
Eleven distinct vectors, six classes. Every one returned 200 with the paid handler's body and no facilitator contact:
// X = handler served unpaid ex4 ex5 hono
HEAD /api/premium X X X
HEAD /api/users/42 X X X
HEAD /files/a X X X
GET /api/users/4%2F2 X X X
GET /api/users/4%2f2 X X X
GET /api/users/4%5C2 X X X
GET /api/users/4\2 X X -
GET /files/a%0Ab X X X
GET /files/a%0Db X X X
GET /files/ X - X
GET /files - - X
The mechanism is a single line in the published bundle. findMatchingRoute calls decodeURIComponent on the whole path, then folds backslashes into forward slashes:
// [email protected], dist/cjs/shared/index.js
const normalizedPath = decodedOrRawPath
.replace(/\\/g, "/")
.replace(/\/+/g, "/")
.replace(/(.+?)\/+$/, "$1");
A request for /api/users/4%2F2 becomes /api/users/4/2 — three segments. The compiled pattern for GET /api/users/[id] is ^/api/users/[^/]+$, which now misses. No match means no payment required, and the middleware calls next(). Express, meanwhile, never decoded anything: it routes the request to the :id handler with id = "4/2" and serves the paid content. Same for the backslash, whose fold into / has the same effect. Same for %0A and %0D, where the decoded line feed defeats a .*? compiled without the dotAll flag. Same for HEAD, which the 1.2.0 matcher compares literally against GET while Express dispatches it to the GET handler.
None of this is new information to the repository. Every one of these six classes has a merged fix in v2. They were simply never published for v1.
npm audit in that install reports 30 advisories, every one of them transitive (zod, viem, WalletConnect, cdp-sdk); the x402 entry itself is flagged only through wagmi and zod. The only advisory ever published against the x402 package is GHSA-3j63-5h8p-gf7c, from August 2025, fixed in 0.5.2. Nothing in the tooling tells a v1 seller that their paywall has ten holes.
The open fix, and the one it duplicates
The parameter case was reported on 19 October by qwqoro in issue #3850, with the curl -k http://localhost:3000/api/4%2f2/premium-content repro and a screenshot of the paid content. It is still open, 36 days later.
A fix exists. PR #3857 (ahmad-codex, 20 October) adds a second match against the raw path, the same union strategy v2 uses:
// PR #3857, legacy/x402/src/shared/middleware.ts
const rawPath = pathWithoutQuery
.replace(/\/+/g, "/")
.replace(/(.+?)\/+$/, "$1");
// ...and in the filter predicate:
(pattern.test(normalizedPath) || pattern.test(rawPath)) &&
(verb === "*" || candidateMethod === verb)
It has been through three review rounds from an outside reviewer and is currently blocked on a lint-python CI failure the author attributes to a GitHub 504 — on a pull request that touches only TypeScript. On 24 November a second contributor opened PR #4401 with the same root-cause analysis and a narrower fix; a reviewer flagged it as a duplicate of #3857 within hours. Two open pull requests, one bug, 36 days.
We measured what the fix actually buys. We patched the published 1.2.0 bundle with the current repository version of the legacy matcher plus #3857's raw-path union, and re-ran the corpus:
legacy + #3857, express 4 bypass 1 (/files/)
legacy + #3857, express 5 bypass 0
legacy + #3857, hono bypass 4 (/files, /files/, %0A, %0D)
Nine of ten closed on Express. On Hono, four remain — and the reason is the instrumentation above. Hono hands the middleware an already-decoded path, so the "raw path" the fix adds is the same decoded string, and the union has nothing new to match. The wildcard pattern compiled without the dotAll flag still misses a path containing a line feed, and still misses the bare and trailing-slash forms of the prefix. The v2 package fixed those with the pattern compiler, not the matcher. A fix ported through one function does not port the other four.
Java: eight free paths, one month, no publish
The monorepo's java/ module has its own filter and its own normalizer. The same reporter filed issue #3849 on 19 October, noting their team had first gone through a HackerOne report to Coinbase and was told to raise it publicly.
We built the module from main at 3eb54b2 against Tomcat 11.0.29 embedded on JDK 17.0.21.1, with a /api/premium servlet, the PaymentFilter mapped to /*, and a filter-free control on another port. We ran the literal-route subset of the corpus plus ten traversal variants: 36 targets.
java (main @3eb54b2) charged 12 bypass 8 free 16
The eight: /api/x/%2e%2e/premium, /public/%2e%2e/api/premium, /public/%2E%2E/api/premium, /public/.%2e/api/premium, /x/y/%2e%2e/%2e%2e/api/premium, /api/%2e/premium, /api/premium/. and /api/premium/%2e. Each returned {"PAID":"/api/premium","servletPath":"/api/premium"} with no payment. The servlet path in the response is the proof: Tomcat resolved the request to the priced servlet, and the filter in front of it did not.
The cause is an ordering bug in a helper whose comment is correct about the threat:
// java/src/main/java/org/x402/server/PaymentFilter.java (main)
String normalized = new URI("http://x" + stripped).normalize().getPath();
URI.normalize() resolves dot segments on the still-encoded path, and getPath() decodes afterwards. %2e%2e is not .. to the normalizer, so /public/%2e%2e/api/premium stays four segments, decodes to /public/../api/premium, and misses the /api/premium price entry. Tomcat then decodes first and resolves second, which is the opposite order, and serves /api/premium.
A fix for this one also exists and is also open. PR #3864 (Echolonius, 21 October) decodes first, then drops empty and . segments and applies .. with a deque, clamping at the root so an over-reaching path can only be priced, never freed. We compiled the module with that version and re-ran the same 36 targets:
java + #3864 charged 20 bypass 0 free 16
All eight closed, eight more targets now charged, nothing newly broken. The pull request has sat for 34 days behind the repository's unverified-commit gate.
Nineteen merged fixes for one bug
We counted the merged pull requests in this repository that fix route matching or path normalization: nineteen, between August 2025 and October 2026. #318 and #320 in the first month of the project. #967, a Hono paywall bypass via malformed percent-encoding where the catch block failed open, in January. #2372, preserving encoded separators, in May. Then August's cluster — #3036 and #3055 and #3100 on line terminators in wildcards, #3044 and #3073 on matching the escaped path, #3116 on backslashes. Then #3213, #3440 and #3441, decoding a route template to a fixed point because single decoding let double encoding through. Then #3502, #3542 and #3543, adding the decoded-view match in Python, TypeScript and Go. Then #3577 on Fastify's absolute-form target, #3796 on HEAD, #3738 on OPTIONS.
Nineteen fixes, four languages, and every single one is the same defect: the gate and the router read the request differently. The v2 matcher is good today because it accumulated nineteen patches, not because anyone specified the invariant. Which means the next adapter someone writes — a new framework, a new language, a new transport — starts at zero and reinvents the whole sequence. The Java module is the proof: it is the newest server-side implementation in the monorepo and it is the one with live bypasses.
The over-gate column is not free either
Across the nine current adapters, 8 to 16 targets per adapter produced a 402 for a path the router does not serve. That direction fails closed, which is the right default, but it is not harmless. A paying agent that retries a mistyped or proxy-rewritten path gets a priced challenge for a resource that will 404 after payment. The settle gate we measured yesterday means the seller does not actually capture on a 404 response — but the agent has signed an authorization, consumed a nonce, and burned a round trip.
There is a second detail worth noting for buyer-side checks. The resource.url in the 402 challenge echoes the request target as the adapter saw it. On Express, a probe at /api/users/4%2F2 yields "url": "http://host/api/users/4%2F2", and //api/premium yields a URL with the doubled slash intact. On Hono, the same probes yield the normalized spelling. Any client-side expected-resource comparison — the kind proposed for the price-expectation checks — is therefore comparing a string whose canonical form depends on the seller's framework.
What it means for LLM4Agents
We are a seller with exactly one paid route, and that is the narrow end of this problem. A literal path with no parameter and no wildcard removes the two patterns that produce most of the vectors above: there is no [^/]+ capture group for an encoded separator to widen, and no .*? for a line feed to defeat. The three vectors that break literal routes elsewhere — the decoded separator in Starlette and Werkzeug, dot segments in Tomcat, the absolute-form target in Fastify — are all framework-specific, and our measurement shows the one we run keeps %2F escaped and resolves dot segments before the middleware ever sees the path.
That is a reason to be calm, not a reason to skip the check. Two things follow directly from today's numbers.
First, pinning matters more than patching. Every bypass we reproduced lives in a published artifact, not in main. The v1 holes are closed in the repository and open on npm. The Java holes are open in the repository because nobody publishes that module at all. For a paid gateway the version you run is the only version that exists, so "fixed upstream" is not a status — "pinned and probed" is.
Second, the probe is cheap and belongs in CI. The entire harness is a mock facilitator, a seller, an identical seller without the middleware, and a loop over 49 strings written to a socket. It takes seconds and it produces a number that cannot be argued with: the count of targets where the handler ran and the facilitator was never contacted. Any seller can run it against their own route table, which is the part that actually determines their exposure. A literal route is not the same risk as GET /v1/agents/:id/*.
Staying on the frontier
In order, from cheapest to most structural.
Keep the gate's own control. The router-only twin is the whole method. A middleware test that asserts 402 proves the middleware answered; it cannot prove the router would have served the handler, which is the only thing that makes a miss a bypass. Every paid-route test should run against a second instance with the gate removed, and compare.
Probe the artifact, not the branch. Point the harness at the installed package — node_modules, the wheel, the module cache — and run it on every dependency bump. The nineteen merged fixes are a reminder that this class returns; the HEAD bypass was merged on 13 October and only reached a pinnable version on 28 October.
Treat the route table as attack surface when it grows. Our exposure today is one literal path. The moment a priced route carries a parameter or a wildcard — per-agent endpoints, file ranges, tool namespaces — the corpus above becomes relevant to us, and the right move is to run it before the route ships, not after.
Push for the invariant, not the nineteenth patch. The useful upstream contribution here is not another matcher fix. It is a paragraph in the HTTP transport spec stating that a resource server MUST decide pricing on a path view no narrower than the one its router dispatches on, plus a shared conformance corpus every adapter runs. The v2 SDKs already implement that rule; it simply has no name. Give it a name and the next adapter inherits nineteen fixes instead of rediscovering them.
Watch the three open pull requests. #3857 and #4401 for v1, #3864 for Java. All three are correct in the parts we measured, and all three are stalled on process rather than substance: a CI job that failed on a network error, a duplicate, and a commit-signing gate. If v1 is going to keep receiving security patches, ten reproducible bypasses in the shipped bundle is the test of whether that promise is real.
One key. All tools. The agent pays.
An OpenAI-compatible gateway where the client is an autonomous agent paying per call in stablecoins — one literal paid route, pinned middleware, and a probe that proves it.
Register an agent