Your API key may be sitting in someone else's access log


When people audit for leaked credentials, the checklist is usually: hardcoded strings, .env permissions, git history, CI logs echoing an environment variable. Almost nobody checks item five — the request line.

If an API sits behind a reverse proxy, a gateway, or a third-party relay, item five is the one that bites. nginx’s default combined log format records the full request line, query string included:

GET /v1beta/models/gemini-3.7-flash:generateContent?key=AIza... HTTP/1.1

That line goes to disk, to a log shipper, to object storage, to somebody’s support ticket screenshot. Nobody “stole” the key. It was recorded, exactly as designed.

Two Hermes fixes landed in this category last week: the same key, placed two different ways in different requests. One goes in a header. The other goes in the URL. The second one is the one that ends up in logs.

One key, three paths through the code

Start with the normal case. A Google AI Studio key travels in the x-goog-api-key header for:

  • model requests (GeminiNativeClient);
  • the model listing in hermes doctor;
  • text-to-speech.

All headers. A proxy does not record them. The problem was in two less prominent requests that put the key in the query string:

  1. The free-tier probe that hermes model runs on a Gemini key (probe_gemini_tier): one generateContent call to decide whether the key is free-tier or paid.
  2. The dashboard backend’s key check (POST /api/providers/validate, the GEMINI_API_KEY row): a models list call.

Both now send the header only, with no query parameter. The key has exactly one place in every request Hermes makes to that API, and it never appears in a URL.

Why this is worse than it looks

The keyword is “probe”.

The tier probe is not something you click once and forget — it rides along with model selection. And its destination is not hardcoded: if you set GEMINI_BASE_URL (to use a relay, a regional endpoint, your own egress proxy), the request carrying ?key= goes to that address.

So the chain is: your key is in the URL → the request goes to whatever endpoint you configured → that endpoint writes a default access log line → the line now contains a working API key.

This is not a logging bug in Hermes. It is the shape of the request putting a secret where secrets should never go. HTTP headers exist for exactly this: proxies do not log them by default, error pages do not echo them, browser history does not store them, Referer does not leak them. Query strings are the opposite on every count.

The second bug: an OAuth credential sent as an API key

The Anthropic fix is a different failure — not the wrong place, but the wrong identity.

To work out a model’s context window, Hermes asks /v1/models with the x-api-key header, which is what a Console key uses.

But Anthropic credentials are not all Console keys. There are setup tokens (sk-ant-oat01...), JWTs (eyJ...), cc- tokens, and other sk-ant- prefixes. The Messages client sends all of those as a bearer token (Authorization: Bearer ...), because that is what they are.

The context-length lookup skipped only sk-ant-oat. So anyone using a JWT, a cc- token, or another sk-ant- shape had the same credential sent a second time — this time inside x-api-key, a header Anthropic does not accept an OAuth credential in.

Two consequences:

  • Security: one secret appeared in two places in a single lookup, and one of those places was wrong. If base_url points at a third-party relay, that header goes to the relay.
  • Function: the request was guaranteed to fail, so the context window had to come from later lookups — a computable value delayed by a request that could never have answered.

The fix is unglamorous and correct: stop hand-rolling the sk-ant-oat prefix test and call _is_oauth_token(), the helper the Messages client, the model list, the usage lookup and hermes doctor already decide by. OAuth-shaped credentials are not probed. Console keys are probed as before.

Credential How Messages sends it Probe before Probe now
Console key sk-ant-api03… x-api-key x-api-key x-api-key
Admin key x-api-key x-api-key x-api-key
Setup token sk-ant-oat01… bearer no request no request
JWT eyJ… bearer x-api-key no request
cc-… token bearer x-api-key no request
Another sk-ant- prefix bearer x-api-key no request

The most important column is not “what changed” but “still sends nothing”: OAuth-shaped credentials are never probed. One less request, in exchange for a credential that only appears where it belongs.

For context: the same class of bug existed in a third place — the model picker’s list request sends the key as a bearer token — fixed separately in #141295. Three separate patches for one mistake is a good sign the mistake is easy to repeat.

Header versus query string is a security question, not a style one

Lined up together, the pattern is obvious:

  • URLs persist in the most places: proxy access logs (the default format includes the full request line), CDN logs, WAF logs, APM samples, the url field in error reports, browser history, Referer.
  • Headers persist in the fewest: not logged unless you deliberately dump them.
  • URLs get shared: someone pastes a log line into a ticket, a curl command into a chat, a URL into a browser to debug. Headers usually do not travel.

So “where does this key go” is not a matter of taste. Any credential that can live in a header should never appear in a query string — especially when the request’s destination may be a third-party relay.

A ten-minute self-check

  1. Search your proxy logs for key= and api_key=:

    grep -c "key=AIza" /var/log/nginx/access.log

    A non-zero count means requests were putting a Gemini key in the URL. Grep token= while you are there.

  2. Check whether you set GEMINI_BASE_URL or ANTHROPIC_BASE_URL. If either points at a relay, and you ran hermes model or the dashboard key check before the fix merged on 2026-11-23, the safe assumption is “this key may have been recorded”, not “probably fine”.

  3. Rotate if it was exposed. A key in a log is a key in a place someone else can read — even when “someone else” is your own log archive three months from now.

  4. Redact at the proxy. nginx can mask sensitive query parameters with a map, or use a custom log_format without $request. Not Hermes’s job, but if you run the relay, it is yours.

  5. Verify after upgrading. The fixed shape is header-only, no query parameter. Confirm on the relay side:

    tail -n 5 /var/log/nginx/access.log

    You should see POST /v1beta/models/...:generateContent HTTP/1.1 with nothing after the path.

The general lesson

Neither bug was a typo. Both were the same fact decided in two places:

  • For Gemini, headers were the norm, but two secondary requests took the convenient shortcut.
  • For Anthropic, credential-shape classification was scattered, and one site knew only one prefix.

The fix is always the same shape: collapse the decision into one function and make every caller ask it. _is_oauth_token() existed for exactly that reason; it just was not called here. Likewise, if “where does this provider’s key go” is written down twice, the second copy will eventually drift.

For users the lesson is shorter: a key in a URL is a key in a log. And logs usually outlive your rotation schedule.

To harden credential handling further upstream, read the keychain encryption guide and profile export credential leaks — the first covers how credentials are stored, the second how they get “legitimately” carried away.