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

Redact CPK headers in log output. #2127

Merged
merged 1 commit into from
Mar 28, 2023
Merged
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
14 changes: 13 additions & 1 deletion ste/xferLogPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func prepareRequestForServiceLogging(request pipeline.Request) *http.Request {
// contains header x-ms-copy-source which could contains secrets for authentication.
// Prepare the headers for logging, with redact secrets in x-ms-copy-source header.
if exist, key := doesHeaderExistCaseInsensitive(req.Header, xMsCopySourceHeader); exist {
req = request.Copy()
req = req.Copy()
url, err := url.Parse(req.Header.Get(key))
if err == nil {
rawQuery := url.RawQuery
Expand All @@ -267,10 +267,22 @@ func prepareRequestForServiceLogging(request pipeline.Request) *http.Request {
}
}
}
// Redact headers that have to do with CPK keys.
if exist, key := doesHeaderExistCaseInsensitive(req.Header, xMsEncryptionKey); exist {
req = req.Copy()
req.Header.Set(key, "REDACTED")
}
if exist, key := doesHeaderExistCaseInsensitive(req.Header, xMsEncryptionKeySha256); exist {
req = req.Copy()
req.Header.Set(key, "REDACTED")
}

return req.Request
}

const xMsCopySourceHeader = "x-ms-copy-source"
const xMsEncryptionKey = "x-ms-encryption-key"
const xMsEncryptionKeySha256 = "x-ms-encryption-key-sha256"

func doesHeaderExistCaseInsensitive(header http.Header, key string) (bool, string) {
for keyInHeader := range header {
Expand Down