Keep only redacted text in typed errors, not the credential
ProviderError and RateLimitedError now build their redacted Error text when constructed and do not store the secret, so formatting the value with %#v or %+v cannot print it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -184,3 +184,15 @@ func TestRateLimitedErrorWithFixedWordSecretNeverLeaksSecret(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypedErrorsDoNotKeepSecret(t *testing.T) {
|
||||
const secret = "sk-live-0123456789abcdef"
|
||||
for _, err := range []error{
|
||||
NewProviderError(500, []byte("down "+secret), secret),
|
||||
NewRateLimitedError(30*time.Second, secret),
|
||||
} {
|
||||
if got := fmt.Sprintf("%#v %+v", err, err); strings.Contains(got, secret) {
|
||||
t.Fatalf("formatting %T leaks the secret: %q", err, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user