Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

273 implement mask for base64 basic auth #279

Merged
merged 3 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions http/transport/dump_round_tripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ func TestNewDumpRoundTripperRedacted(t *testing.T) {
assert.Contains(t, out.String(), `"message":"HTTP Transport Dump"`)
}

func TestNewDumpRoundTripperRedactedBasicAuth(t *testing.T) {
out := &bytes.Buffer{}
ctx := log.Output(out).WithContext(context.Background())

rt := NewDumpRoundTripper(
DumpRoundTripperOptionRequest,
DumpRoundTripperOptionResponse,
DumpRoundTripperOptionBody,
)

req := httptest.NewRequest("GET", "/foo", bytes.NewBufferString("Authorization: Basic ZGVtbzpwQDU1dzByZA=="))
ctx = redact.Default.WithContext(ctx)
req = req.WithContext(ctx)
rt.SetTransport(&transportWithResponse{})

_, err := rt.RoundTrip(req)
assert.NoError(t, err)

assert.Contains(t, out.String(), `"level":"debug"`)
assert.Contains(t, out.String(), `"request":"GET /foo HTTP/1.1\r\nHost: example.com\r\n\r\n*************************************ZA=="`)
assert.Contains(t, out.String(), `"response":"HTTP/0.0 000 status code 0\r\nContent-Length: 0\r\n\r\n"`)
assert.Contains(t, out.String(), `"message":"HTTP Transport Dump"`)
}

func TestNewDumpRoundTripperSimple(t *testing.T) {
out := &bytes.Buffer{}
ctx := log.Output(out).WithContext(context.Background())
Expand Down
4 changes: 4 additions & 0 deletions pkg/redact/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var AllPatterns = []*regexp.Regexp{
PatternCCDinersClub,
PatternCCDiscover,
PatternCCJCB,
PatternBasicAuthBase64,
}

var (
Expand Down Expand Up @@ -49,4 +50,7 @@ var (

// PatternJWT JsonWebToken
PatternJWT = regexp.MustCompile(`(?:ey[a-zA-Z0-9=_-]+\.){2}[a-zA-Z0-9=_-]+`)

//PatternBasicAuthBase match any: Basic YW55IGNhcm5hbCBwbGVhcw== does not validate base64 string
PatternBasicAuthBase64 = regexp.MustCompile(`Authorization: Basic ([a-zA-Z0-9=]*)`)
)