Skip to content

Commit 96a3651

Browse files
authored
fix: Expand sanitizeURL secrets redactions (#4126)
1 parent dd0b651 commit 96a3651

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

github/github.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,15 +1382,23 @@ func (r *RedirectionError) Is(target error) bool {
13821382
r.Location != nil && v.Location != nil && r.Location.String() == v.Location.String()) // or they are both not nil and marshaled identically
13831383
}
13841384

1385-
// sanitizeURL redacts the client_secret parameter from the URL which may be
1385+
var sensitiveParams = []string{"client_secret", "access_token", "token"}
1386+
1387+
// sanitizeURL redacts sensitive parameters from the URL which may be
13861388
// exposed to the user.
13871389
func sanitizeURL(uri *url.URL) *url.URL {
13881390
if uri == nil {
13891391
return nil
13901392
}
13911393
params := uri.Query()
1392-
if len(params.Get("client_secret")) > 0 {
1393-
params.Set("client_secret", "REDACTED")
1394+
var redacted bool
1395+
for _, p := range sensitiveParams {
1396+
if len(params.Get(p)) > 0 {
1397+
params.Set(p, "REDACTED")
1398+
redacted = true
1399+
}
1400+
}
1401+
if redacted {
13941402
uri.RawQuery = params.Encode()
13951403
}
13961404
return uri

github/github_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,9 @@ func TestSanitizeURL(t *testing.T) {
21742174
{"/?a=b", "/?a=b"},
21752175
{"/?a=b&client_secret=secret", "/?a=b&client_secret=REDACTED"},
21762176
{"/?a=b&client_id=id&client_secret=secret", "/?a=b&client_id=id&client_secret=REDACTED"},
2177+
{"/?a=b&access_token=secret", "/?a=b&access_token=REDACTED"},
2178+
{"/?a=b&token=secret", "/?a=b&token=REDACTED"},
2179+
{"/?client_secret=s&access_token=t&token=u", "/?access_token=REDACTED&client_secret=REDACTED&token=REDACTED"},
21772180
}
21782181

21792182
for _, tt := range tests {

0 commit comments

Comments
 (0)