Skip to content

fix(backoff): cool down forwarded client credentials separately - #458

Open
ravi-pplx wants to merge 2 commits into
block:mainfrom
perplexityai:fix/backoff-forwarded-credentials
Open

ravi-pplx wants to merge 2 commits into
block:mainfrom
perplexityai:fix/backoff-forwarded-credentials

Conversation

@ravi-pplx

@ravi-pplx ravi-pplx commented Nov 22, 2026 •

Copy link
Copy Markdown

The handler forwards the client's Authorization header upstream when the transform doesn't set one, as with proxy and artifactory. When the upstream answers such a request with 429, BackoffTransport starts a cooldown for the whole hostname. Other callers, anonymous requests, and the same caller retrying with a different token then get a local 429 until it ends, even though the upstream limits each credential on its own. #445 scoped the GitHub credentials cachew attaches itself; this PR covers the ones it forwards.

Change

  • httputil.WithForwardedCredentialCooldown(ctx, authorization) records the caller's credential on the request. While the request still sends that exact value, the transport scopes the cooldown to an HMAC-SHA256 of it, keyed with a random per-process secret. The cooldown log names the scope forwarded-credential:<16 hex>, so it never contains the credential and can't be used to test guesses of it.
  • The handler records the value only when it copies the client's header itself, that is, when the transform left Authorization unset. A credential the transform attaches, such as one from host headers, keeps the scope the transform chose, which is the hostname unless it uses WithCooldownScope, even if the client sent the same value. WithCooldownScope takes precedence over the recorded credential.
  • A transport that replaces the header falls back to the hostname's cooldown. OCI strips client credentials and attaches cachew's own registry token, so OCI requests keep sharing the registry's cooldown whether or not the client sent credentials.
  • artifactory and Hermit's GitHub redirect (with an external github-base-url) no longer copy Authorization in their transforms. They rely on the handler's forwarding, which already sends the header whenever the transform doesn't set it. Artifactory still copies X-JFrog-Art-Api and Cookie, and Hermit still copies the other client headers. A credential sent on Hermit's redirect and direct routes now shares one cooldown, where before each route bypassed the other's.
  • The git strategy's pass-through proxy, used for pushes, LFS API calls and other requests it doesn't serve from a mirror, records the client's Authorization the same way. When it attaches a GitHub App token for github.com, that token replaces the header and the installation's scope applies.
  • Unchanged: a redirect to another host drops the credential and so shares that host's cooldown, and requests without Authorization share the hostname's cooldown.

#445 scopes attached credentials where they are attached, rather than by hashing Authorization, because a hash splits one rate limit into many cooldowns when tokens rotate. For a forwarded credential cachew has no better identity than the header, and falling back to the hostname lets one caller's 429 block every other caller. The cost is that a caller rotating tokens against one limit isn't held back locally; it still gets the upstream's own 429s.

Behaviour changes

  • A forwarded credential's 429 no longer pauses the host for everyone else, and a host-wide cooldown no longer pauses requests that forward their own credential.
  • Only Authorization is considered. Other credential headers, such as Artifactory's X-JFrog-Art-Api, still share the hostname's cooldown.

Testing

  • TestBackoffForwardedCredentialCooldown covers the transport. The limited credential cools down alone, and other credentials and anonymous requests pass. Unmarked requests share the host's cooldown, as does a replaced credential. WithCooldownScope wins, and the log names the scope without the credential.
  • TestBackoffScopesForwardedCredentials drives the handler against a real upstream. A forwarded credential's 429 doesn't pause another credential or anonymous requests, and a credential the transform attaches cools down the whole host even when the client sent the same value.
  • TestProxyScopesForwardedCredentials checks that one credential's 429 through the git proxy doesn't pause another credential or anonymous requests.
  • TestOCIBackoff now triggers the registry's 429 with client credentials and still expects the cooldown to cover requests without them.
  • TestHermitBackoff now also runs with a client credential and expects a 429 on the redirect route to cool down the direct route for that credential.
  • TestArtifactoryAuthHeaders still checks that Authorization reaches Artifactory.

Created with Perplexity

@ravi-pplx
ravi-pplx requested a review from a team as a code owner November 22, 2026 02:43
@ravi-pplx
ravi-pplx requested review from stuartwdouglas and removed request for a team November 22, 2026 02:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T18:30:00.878269Z f425227 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7397f42804

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/httputil/backoff.go Resolved
Comment thread internal/strategy/handler/handler.go Resolved
@ravi-pplx
ravi-pplx force-pushed the fix/backoff-forwarded-credentials branch from 7397f42 to c62d6a9 Compare November 22, 2026 02:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c62d6a95ee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/strategy/handler/handler.go Resolved
The handler forwards the client's Authorization header upstream when the
transform doesn't set one. A 429 for such a request started a cooldown
for the whole hostname, so other callers, anonymous requests and the
same caller retrying with another token were rejected locally, even
though the upstream limits each credential on its own.

WithForwardedCredentialCooldown now records the forwarded value. While
a request still sends that value, the transport scopes its cooldown to
an HMAC of it, keyed with a per-process secret, so the scope name it
logs never reveals the credential. A transport that replaces the
header, as OCI's registry authentication does, falls back to the
host's cooldown. The handler records the value only when it copied the
client's header itself, so a credential the transform attaches keeps
the scope the transform chose even if the client sent the same value.
Artifactory and Hermit's GitHub redirect no longer copy Authorization
in their transforms and rely on the handler's forwarding instead, so a
credential sent on Hermit's redirect and direct routes shares one
cooldown. The git strategy's pass-through proxy records the client's
credential the same way. WithCooldownScope takes precedence.

Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx
ravi-pplx force-pushed the fix/backoff-forwarded-credentials branch from c62d6a9 to 3388f80 Compare November 22, 2026 03:06
Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx

Copy link
Copy Markdown
Author

@codex review

Created with Perplexity

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: f425227a24

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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