Skip to content

Document how to attribute a private-api 401#59

Merged
feruzm merged 2 commits into
mainfrom
docs/private-api-401-attribution
Jul 21, 2026
Merged

Document how to attribute a private-api 401#59
feruzm merged 2 commits into
mainfrom
docs/private-api-401-attribution

Conversation

@feruzm

@feruzm feruzm commented Jul 21, 2026

Copy link
Copy Markdown
Member

A 401 on a private-API route is easy to misattribute to this service, because the handlers pipe upstream responses through unchanged: a 401 from the backend arrives looking identical to one produced here.

Records the tell and two cheap checks:

  • Body length. This service answers SendText(401, "Unauthorized"), 12 bytes. A longer body means it was piped from upstream.
  • Compare a sibling route sharing ValidateCode. If one endpoint 401s while another succeeds for the same session, the code validated fine and the cause is downstream.
  • Look at the rate. A token problem hits a subset of users; a misconfigured backend gate fails for everyone. 100% 401 on one route with siblings at 100% success is not an authentication bug in the usual sense.

Also notes that RequireAuthedUsername and a direct ValidateCode call validate identically, so the choice between them never explains one route failing while another passes.

Written without infrastructure specifics, per this repo being public. Documentation only.

These handlers pipe upstream responses through unchanged, so a 401 from a
backend is indistinguishable from one this service produced unless you look at
the body length. Records that tell, plus two checks that separate a token
problem from a misconfigured gate downstream.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds private-api 401 troubleshooting notes to CLAUDE.md. The main changes are:

  • Guidance for distinguishing local 401s from upstream 401s.
  • Suggested sibling-route and failure-rate checks.
  • A note that RequireAuthedUsername and direct ValidateCode use the same validation.

Confidence Score: 5/5

The documentation change looks mergeable after tightening two troubleshooting examples.

  • Runtime behavior is unchanged.
  • The body-length rule can misclassify an upstream Unauthorized response.
  • The notifications example can mislead because that route can succeed without a successful code validation.

CLAUDE.md

Important Files Changed

Filename Overview
CLAUDE.md Adds operational guidance for attributing /private-api/* 401 responses.

Fix All in Claude Code

Reviews (1): Last reviewed commit: "docs: how to attribute a private-api 401" | Re-trigger Greptile

Comment thread CLAUDE.md Outdated
Comment on lines +99 to +101
answers `SendText(401, "Unauthorized")`, a 12-byte body. A longer body almost
always means the 401 was piped from further upstream.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Twelve Bytes Can Be Upstream

When the backend returns a 401 body of Unauthorized, the proxy path forwards that body unchanged and it is also 12 bytes. The body-length check only proves upstream when the body is longer, so the current wording can make an upstream 401 look like a local auth failure.

Fix in Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 496fc52. You are right that the inference only runs one way: an upstream that also answers Unauthorized is piped through at exactly 12 bytes, so a short body is inconclusive. Reworded to state that a longer body means upstream while a 12-byte body proves nothing.

Comment thread CLAUDE.md Outdated
Comment on lines +105 to +108
notifications succeed while one endpoint 401s for the same session, the code
validated fine and the failure is downstream of this service. Route-specific
auth on the backend, not the caller's token, is then the thing to look at.
- **Check the failure rate.** A token or session problem affects a subset of

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Notifications Can Bypass Validation

notifications is a risky sibling example because that handler can continue with a body-supplied user after ValidateCode fails. A request with a bad signed code can therefore succeed there and fail on another private-api route, making the docs incorrectly rule out a token or session problem.

Fix in Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed in the source and fixed in 496fc52. Notifications falls back to body.Field("user") when ValidateCode returns nothing, and the following if (JsJson.IsTruthy(user)) overrides even a validated username with that field. So it can answer for a request whose code was rejected, which makes it actively misleading as a validation canary. Swapped the example to notifications/unread and notifications/mark, which 401 unconditionally, and documented the notifications behaviour as a trap rather than dropping it.

The body length only proves upstream in one direction: an upstream answering
Unauthorized forwards through at the same 12 bytes, so a short body is
inconclusive rather than evidence the 401 was raised here.

notifications was the wrong sibling to suggest comparing against. It falls back
to a body-supplied user when validation fails and overrides even a validated
username with that field, so it can answer for a request whose code was
rejected. Points at notifications/unread and notifications/mark instead, which
401 unconditionally, and records the notifications behaviour as a trap.
@feruzm
feruzm merged commit 38b2ee1 into main Jul 21, 2026
3 checks passed
@feruzm
feruzm deleted the docs/private-api-401-attribution branch July 21, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant