Skip to content

fix(git): Keep the provider token out of error reports - #167

Open
vaind wants to merge 1 commit into
mainfrom
ivan/git-relay-token-secret
Open

vaind wants to merge 1 commit into
mainfrom
ivan/git-relay-token-secret

Conversation

@vaind

@vaind vaind commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

When Sentry's git endpoint (getsentry/sentry#128444) refuses a request after it has fetched a provider token, for example because the provider is unreachable or rejects the token, the error report carries the token. Sentry's SDK sends the local variables of every frame in the traceback, Sentry's SDK configuration turns off the scrubber that would otherwise replace a variable named token, and GitServer.handle and GitRelay.forward both hold the token as a plain string. #162 fixed this for grant secrets and the grant, but left the token a str.

Approach

  • GetToken returns scm.Secret | None, and GitServer.handle passes the Secret on to GitRelay.forward, so both frames show [Filtered]. The relay calls reveal() only inline, for the ASCII check and HTTPBasicAuth.
  • GitServer.handle refuses a token that isn't a Secret with a TypeError, deleting the local first so that error's report doesn't carry it either. A plain string from untyped code would otherwise fail every request in the relay with an AttributeError whose frames hold it.
  • bin/git-server wraps its tokens.

get_token now has to wrap the token in Secret. Nothing calls it yet: Sentry's endpoint is still unmerged and will wrap it when it bumps to the release with this change.

Not covered: an error the relay's adapter raises itself, such as Sentry's BlacklistAdapter refusing an internal address, passes through urllib3's frames, which hold the Authorization header. The relay can't mask those, so GitRelay's docstring now says to report such an error without its frames' local variables; Sentry's endpoint handles that separately.

GitServer.handle and GitRelay.forward held the provider token as a
plain string. Sentry's SDK sends every frame's local variables with an
error report, and Sentry's SDK configuration turns off the scrubber
that would replace a local named `token`. So in Sentry's git endpoint
(getsentry/sentry#128444), every refusal after
the token is fetched, such as an unreachable provider or a rejected
token, would report it.

get_token now returns an scm.Secret, which shows as [Filtered]. The
relay reveals it only inline, for the ASCII check and HTTPBasicAuth.
GitServer refuses a plain string with a TypeError, after dropping it
from its frame: one that got past the type checker would otherwise
fail every request in the relay and report the token.

Breaking: get_token must wrap the token it returns, e.g.
Secret(access_token.token).
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