Repository navigation
fix: Prevent sanitizeURL from mutating request URL - #4654
Open
AdamMagued wants to merge 2 commits into
Open
AdamMagued wants to merge 2 commits into
AdamMagued wants to merge 2 commits into
Conversation
sanitizeURL from mutating request URL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4654 +/- ##
==========================================
+ Coverage 98.61% 98.63% +0.01%
==========================================
Files 199 201 +2
Lines 18693 18868 +175
==========================================
+ Hits 18435 18610 +175
Misses 258 258 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gmlewis
requested changes
Oct 21, 2026
gmlewis
left a comment
Collaborator
There was a problem hiding this comment.
Thank you, @AdamMagued, but this PR as written doesn't solve #4651, as Error() continues to mutate state.
Additionally,
- The library never puts these params in URLs. Auth is applied as an Authorization header (github/github.go:661), and since #4564 even UnauthenticatedRateLimitedTransport uses Basic auth via setCredentialsAsHeaders (github/github.go:2217-2231). A grep of non-test code finds zero constructions of ?access_token=, ?client_secret=, or ?token=. Notably, the existing TestDo_sanitizeURL (github_test.go:2602) is now effectively vacuous — the secret is sent as a header, so it could never appear in the URL.
- The internal retry is unaffected. The only retry in bareDo (github/github.go:1528) clones the request and never calls Error(). So "subsequent retries fail with redacted credentials" only happens if caller code manually put a legacy query-token in a URL, then logged the error, then reused that request. Possible, but caller-induced and not something the repo does.
- The data race is narrow. It requires a sensitive param to be present and the same error formatted concurrently. Error() is otherwise a pure read, so ordinary header-auth users never trigger it.
If you wish to try again, that is fine, otherwise this PR will be closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4651
Summary
sanitizeURL(uri *url.URL) *url.URLpreviously mutateduri.RawQuerydirectly on the input pointer. When formatting error messages (ErrorResponse.Error(),RateLimitError.Error(),AbuseRateLimitError.Error(), orRedirectionError.Error()), the liver.Response.Request.URLpointer was passed tosanitizeURL. This caused the caller's active request URL to be overwritten in place, redacting sensitive tokens toREDACTED. Consequently, subsequent request retries failed due to redacted credentials, and concurrent error formatting on the same request introduced a data race.Changes
sanitizeURLingithub/github.goto clone the incoming*url.URLstruct prior to mutatingRawQuery, returning a pointer to the clone while keeping the original pointer unchanged.github/github_test.go:TestSanitizeURL_DoesNotMutateInputverifies that callingsanitizeURLleaves the input pointer'sRawQueryandString()intact.TestErrorResponse_Error_DoesNotMutateRequestURLverifies that formatting anErrorResponseredacts credentials in the formatted string while preserving original credentials inr.Response.Request.URL.RateLimitError,AbuseRateLimitError, andRedirectionError.