Skip to main content
kRouter
All posts
Fix an error

33 of 34 requests left the machine while interception was "on"

Claude Desktop gzips its request bodies. The model matcher read raw bytes, saw a binary header, gave up, and passed everything through to Anthropic on the user's own quota — with every setting correct.

Kodelyth · The team behind kRouter
7 min read

The worst kind of bug in a gateway is not one that fails. It is one that succeeds at everything except the thing it exists to do, while every indicator says it is working.

Here is what a live install looked like, from the interceptor's own dumps:

/v1/messages raw dumps        34
of those, passthrough         33
content-encoding              gzip   (5 of 5 sampled)
body as the MITM read it      \x1f\x8b...  (binary)
model as the MITM read it     (not found)
user-agent                    claude-cli/2.1.321 (external, claude-desktop, ...)

Thirty-three of thirty-four requests were received by kRouter and forwarded straight back out to Anthropic. The user's own Anthropic quota paid for all of them, while the dashboard said interception was on.

Everything you would check was correct

This survived two releases because every diagnostic step passes:

  • the claude DNS toggle: on
  • /etc/hosts pointing api.anthropic.com at 127.0.0.1: correct
  • the TLS handshake: served by 9Router MITM Root CA, so the certificate is trusted and working
  • the interceptor listening on :443: yes
  • requests arriving: yes, all 34 of them

Every layer anyone would suspect was fine. The requests reached kRouter. kRouter then chose, deliberately and by its own logic, to forward them unchanged.

\x1f\x8b

Those two bytes are the gzip magic number, and they are the whole bug.

Claude Desktop and Claude Code send /v1/messages gzip-compressed. The routing logic did this:

  1. extractModel() read the raw request bytes.
  2. isBinaryData() sampled them, counted more than 30% non-printable bytes — which a gzip header is, entirely — and concluded this was binary data, not JSON.
  3. So extractModel() returned null.
  4. getMappedModel() had no model to look up, and returned nothing.
  5. if (!mappedModel) return passthrough(...).

Every one of those steps is individually correct. isBinaryData() really is looking at binary data. Returning null for a model you cannot find really is the honest answer. And passing through a request whose model you do not recognise is exactly right — that is what keeps sign-in, telemetry and unmapped models working.

The chain is wrong because the first step read the wrong bytes. Nothing after it had any way to know.

The handler one line further on would have failed on the same body for the same reason, so there was no backstop.

Why it looked like a Claude certificate problem

Kiro was unaffected throughout. Kiro sends plain JSON with no content-encoding, so its model was extracted, mapped, and intercepted correctly on every turn.

One tool working and one tool failing, where the failing one is the one with the fiddly api.anthropic.com redirect, reads as a Claude-specific certificate or toggle problem. That is where the investigation goes. It is a body-reading problem affecting every client that compresses, and Claude happened to be the only one that did.

This is the same misdirection as the Antigravity trust bug, where three Node apps worked and one Go app failed, and the asymmetry made the failing tool look special rather than subject to something general.

The fix, and why it decodes once

The body is now decoded before the routing decision, and the decoded buffer is what both the model extractor and the handler see.

It handles gzip, x-gzip, deflate including raw deflate, br, zstd — and stacked encodings, undone right-to-left in the order Content-Encoding lists them.

One subtlety is worth naming, because getting it wrong produces a new silent failure in the opposite direction. Passthrough must forward the original bytes, not the decoded ones. Passthrough forwards the client's own headers, and those headers still say content-encoding: gzip. Send a decoded body with a header claiming it is compressed and the upstream will fail to parse it — so a bug that leaked requests to the vendor would have become a bug that corrupted them.

So the decision function returns both: the decoded body for anything that needs to understand the request, and the untouched original for anything that merely forwards it.

What this class of bug has in common

Three of the interception bugs worth shipping a release for have had the same structure: the retirement notice, usage attribution, and this one. In each case the system produced a plausible result through a chain of individually defensible steps, and recorded it as normal operation.

Here the specific lesson is narrow and reusable: if you are going to make a decision based on the contents of an HTTP body, decode it first. Content-Encoding is not an edge case, it is the default for any client that cares about bandwidth, and a matcher that reads raw bytes will silently stop matching the moment a vendor turns compression on — with no error, no log line, and every setting still green.

Kodelyth · The team behind kRouter

Published by Kodelyth, the team that builds kRouter. Posts are drafted with AI assistance and reviewed by a person before they go out. kRouter is free and MIT licensed.

Install kRouter