Skip to content

Commit 8edd421

Browse files
fix: address PR review suggestions for redact and tokenbroker
- redact: add "key" and "credential" to sensitive suffix list for defense-in-depth (api_key, private_key, signing_key, etc.) - redact: descend into container-valued sensitive keys instead of skipping them — a field like {"token": {"access_token": "..."}} now has its nested secrets redacted - redact: add best-effort doc noting inline secrets should use *_file paths; this layer is defense-in-depth - tokenbroker: TrimSpace the extracted bearer token so whitespace-only tokens ("Bearer ") are treated as missing rather than forwarded to the broker Signed-off-by: Varsha Prasad Narsing <vnarsing@redhat.com> Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
1 parent d9e632b commit 8edd421

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

authbridge/authlib/plugins/tokenbroker/plugin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ func (p *TokenBroker) OnRequest(ctx context.Context, pctx *pipeline.Context) pip
244244
"server_url", serverURL,
245245
"broker_url", brokerURL)
246246

247-
// Extract bearer token
248-
subjectToken := auth.ExtractBearer(authHeader)
247+
subjectToken := strings.TrimSpace(auth.ExtractBearer(authHeader))
249248
if subjectToken == "" {
250249
return pctx.DenyAndRecord("missing_subject_token", "auth.missing-token",
251250
"broker route requires authorization token")

authbridge/authlib/redact/redact.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// Package redact strips sensitive values from JSON config payloads.
1+
// Package redact provides best-effort stripping of sensitive values from
2+
// JSON config payloads served by unauthenticated diagnostic endpoints.
3+
// The canonical defense is to keep inline secrets out of config entirely
4+
// (use *_file paths instead); this layer is defense-in-depth.
25
package redact
36

47
import (
@@ -7,7 +10,7 @@ import (
710
)
811

912
var sensitiveKeys = []string{
10-
"secret", "password", "token", "bearer",
13+
"secret", "password", "token", "bearer", "key", "credential",
1114
}
1215

1316
// JSON redacts values whose keys match sensitive patterns in a
@@ -36,8 +39,8 @@ func redactMap(m map[string]any) {
3639
if isSensitiveKey(k) {
3740
if _, ok := v.(string); ok {
3841
m[k] = "[REDACTED]"
42+
continue
3943
}
40-
continue
4144
}
4245
switch val := v.(type) {
4346
case map[string]any:

authbridge/authlib/redact/redact_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,37 @@ func TestJSON_NonStringSecretPreserved(t *testing.T) {
100100
}
101101
}
102102

103+
func TestJSON_ContainerValuedSensitiveKey(t *testing.T) {
104+
in := json.RawMessage(`{"token":{"access_token":"secret","url":"https://idp"}}`)
105+
out := JSON(in)
106+
var m map[string]any
107+
if err := json.Unmarshal(out, &m); err != nil {
108+
t.Fatal(err)
109+
}
110+
inner := m["token"].(map[string]any)
111+
if inner["access_token"] != "[REDACTED]" {
112+
t.Errorf("access_token inside container-valued sensitive key = %v, want [REDACTED]", inner["access_token"])
113+
}
114+
if inner["url"] != "https://idp" {
115+
t.Errorf("url inside container-valued sensitive key = %v, want https://idp", inner["url"])
116+
}
117+
}
118+
119+
func TestJSON_RedactsApiKey(t *testing.T) {
120+
in := json.RawMessage(`{"api_key":"k3y","endpoint":"https://api"}`)
121+
out := JSON(in)
122+
var m map[string]any
123+
if err := json.Unmarshal(out, &m); err != nil {
124+
t.Fatal(err)
125+
}
126+
if m["api_key"] != "[REDACTED]" {
127+
t.Errorf("api_key = %v, want [REDACTED]", m["api_key"])
128+
}
129+
if m["endpoint"] != "https://api" {
130+
t.Errorf("endpoint = %v, want https://api", m["endpoint"])
131+
}
132+
}
133+
103134
func TestJSON_NestedArrayRedaction(t *testing.T) {
104135
in := json.RawMessage(`{"data":[[{"client_secret":"xyz","url":"https://a"}]]}`)
105136
out := JSON(in)

0 commit comments

Comments
 (0)