Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

security: redact unrecognized auth HTTP headers from logs #46112

Merged
merged 3 commits into from
Jan 5, 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
22 changes: 20 additions & 2 deletions cmd/frontend/internal/httpapi/auth.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package httpapi

import (
"crypto/md5"
"encoding/json"
"fmt"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -43,9 +45,25 @@ func AccessTokenAuthMiddleware(db database.DB, logger log.Logger, next http.Hand
if err != nil {
if authz.IsUnrecognizedScheme(err) {
// Ignore Authorization headers that we don't handle.
// 🚨 SECURITY: md5sum the authorization header value so we redact it
// while still retaining the ability to link it back to a token, assuming
// the logs reader has the value in clear.
var redactedValue string
h := md5.New()
if _, err := io.WriteString(h, headerValue); err != nil {
redactedValue = "[REDACTED]"
} else {
redactedValue = fmt.Sprintf("md5sum:%x", h.Sum(nil))
}
// TODO: It is possible for the unrecognized header to be legitimate, in the case
// of a customer setting up a HTTP header based authentication and decide to still
// use the "Authorization" key.
//
// We should parse the configuration to see if that's the case and only log if it's
// not defined over there.
logger.Warn(
"ignoring unrecognized Authorization header",
log.String("value", headerValue),
"ignoring unrecognized Authorization header, passing it down to the next layer",
log.String("redacted_value", redactedValue),
log.Error(err),
)
next.ServeHTTP(w, r)
Expand Down