Skip to content

fix(auth): omit token-provider response bodies from errors - #5263

Open
singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/redact-token-provider-errors
Open

singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/redact-token-provider-errors

Conversation

@singh4jitendra

Copy link
Copy Markdown
Contributor

Description

A token provider's error body can contain credentials. Returning that body in oauth2.RetrieveError also copies it into the error message, which callers may log.

This leaves the HTTP status and standard error type available for diagnostics and retries, but omits the body. Successful token responses are unchanged. Tests cover JSON and plain-text responses using dummy values.

This is separate from the provider timeout/lifetime work in #5230.

Link to the issue in case of a bug fix.

Fixes #5257

Testing details

Go 1.27.4, Linux under WSL.

  1. Manual -
    • The initial native build passed vet and lint, then the local filesystem became read-only during compilation.
    • Repeated the full build from writable task storage with CGO_ENABLED=0 and a longer local lint budget:
      printf 'lint: vet\n\tgolangci-lint run -E=unused --timeout 10m0s --new-from-rev=master\n' | make -f Makefile -f - build - passed with 0 lint issues. No build checks were skipped.
  2. Unit tests -
    • go test -mod=readonly -p 1 -count=1 -timeout=90s -run '^TestProxyTokenSourceErrorDoesNotExposeResponseBody$' ./internal/auth - failed as expected before the fix, showing the dummy response values in the error.
    • go test -mod=readonly -p 1 -count=1 -race -timeout=3m ./internal/auth ./internal/storage/storageutil - passed on native Linux storage, including expiry, Unix sockets and status-based retry behavior.
  3. Integration tests - Not run. Tests use local servers and dummy tokens, not cloud credentials.

Any backward incompatible change? If so, please explain.

Provider response bodies are intentionally no longer included in errors. The HTTP status, retry classification, success behavior and response-size cap remain unchanged. Provider-specific details should be checked in the provider's own logs.

Keep the standard OAuth retrieval error and HTTP status for retry decisions without echoing potentially sensitive provider payloads. Cover dummy JSON and plaintext error responses and document the diagnostic change.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request prevents credential-provider response bodies, which may contain sensitive tokens or secrets, from being exposed in error logs when a token request fails. Specifically, the Body field is omitted from oauth2.RetrieveError in internal/auth/token_source.go. Corresponding documentation has been added to docs/client_and_retries.md, and a new unit test has been introduced to verify that response bodies are not leaked. I have no additional feedback to provide as the changes are well-implemented and there are no review comments.

@singh4jitendra
singh4jitendra marked this pull request as ready for review November 17, 2026 05:30
@singh4jitendra
singh4jitendra requested a review from a team as a code owner November 17, 2026 05:30
@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, could you help approve CI and review the token-provider error-body change when you have a moment? Happy to address any feedback. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, could you help get CI running and review the token-provider error-body fix when you have time? Please let me know if anything needs adjusting. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @geertj, could you review the token-provider error-body fix when you have a moment? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant