Skip to content

security(tracker): sanitize provider probe error bodies before surfacing in DoctorReport#122

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/sanitize-provider-error-bodies
Closed

security(tracker): sanitize provider probe error bodies before surfacing in DoctorReport#122
Copilot wants to merge 2 commits intomainfrom
copilot/sanitize-provider-error-bodies

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

DoctorReport provider probe failures were exposing raw provider error text (trimmed but unsanitized) in CheckDetail.Message. Some provider errors can echo sensitive request context (tokens, key fragments, request identifiers), creating downstream leak risk for logs/webhooks.

  • What changed

    • Added sanitizeProviderError(msg string) in tracker_doctor.go.
    • Applied sanitization in probeProvider for non-auth failures before trimErrMsg(..., 80) is used to build the public message.
    • Kept existing auth-failure behavior unchanged ("invalid or expired API key").
  • Sanitization coverage

    • Redacts bearer tokens (`******
    • Redacts API-key-like shapes (sk-ant-*, sk-*, AIza*).
    • Redacts common request ID patterns (request-id=..., req_...).
  • Targeted test additions

    • Added unit test for direct sanitization redaction coverage.
    • Added probe-path test ensuring non-auth provider errors are sanitized before being returned.
if err != nil {
    msg := err.Error()
    if isAuthError(msg) {
        return false, "invalid or expired API key"
    }
    return false, trimErrMsg(sanitizeProviderError(msg), 80)
}

Copilot AI changed the title [WIP] Sanitize provider error bodies in CheckDetail.Message security(tracker): sanitize provider probe error bodies before surfacing in DoctorReport Apr 20, 2026
Copilot AI requested a review from clintecker April 20, 2026 15:50
@clintecker clintecker requested a review from Copilot April 20, 2026 16:25
@clintecker clintecker marked this pull request as ready for review April 20, 2026 16:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces the risk of leaking sensitive credential material by sanitizing LLM provider probe error strings before they’re surfaced in DoctorReport check details/messages.

Changes:

  • Sanitize non-auth provider probe error messages via sanitizeProviderError(...) before trimming and returning them.
  • Add regex-based redaction rules for Bearer tokens, API-key-like strings, and request-id patterns.
  • Add unit tests covering direct sanitization and the probe-path behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tracker_doctor.go Applies sanitization to provider probe errors and introduces regex-based redaction rules.
tracker_doctor_test.go Adds tests validating redaction and that probeProvider returns sanitized messages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tracker_doctor.go
re *regexp.Regexp
repl string
}{
{regexp.MustCompile(`(?i)\bBearer\s+[A-Za-z0-9._~+/=-]+\b`), "Bearer [REDACTED]"},
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bearer-token sanitizer regex ends with a word-boundary (\b). If the token ends with '=' (common for base64/JWT padding), '\b' will not match and the token will remain unredacted. Consider replacing the trailing '\b' with a lookahead like (?=\s|$) (or otherwise anchoring on whitespace/end) so tokens ending in non-word characters are still sanitized, and add a unit test covering a Bearer token that ends with '='.

Suggested change
{regexp.MustCompile(`(?i)\bBearer\s+[A-Za-z0-9._~+/=-]+\b`), "Bearer [REDACTED]"},
{regexp.MustCompile(`(?i)\bBearer\s+[A-Za-z0-9._~+/=-]+(?=\s|$)`), "Bearer [REDACTED]"},

Copilot uses AI. Check for mistakes.
Comment thread tracker_doctor_test.go
}, "test-key")

if ok {
t.Fatal("expected auth probe to fail")
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test failure message says "expected auth probe to fail", but the test is specifically asserting the non-auth error path is sanitized. Updating the message to reflect the actual expectation will make failures easier to interpret.

Suggested change
t.Fatal("expected auth probe to fail")
t.Fatal("expected non-auth probe to fail")

Copilot uses AI. Check for mistakes.
Comment thread tracker_doctor.go
Comment on lines +349 to +350
{regexp.MustCompile(`(?i)\bBearer\s+[A-Za-z0-9._~+/=-]+\b`), "Bearer [REDACTED]"},
{regexp.MustCompile(`\bsk-ant-[A-Za-z0-9_-]+\b`), "[REDACTED_API_KEY]"},
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says Bearer tokens are redacted to "******", but the implementation replaces them with "Bearer [REDACTED]". Either align the description with the actual redaction format or adjust the replacement string so downstream users know what to expect.

Copilot uses AI. Check for mistakes.
@clintecker
Copy link
Copy Markdown
Collaborator

Superseded by merged #113, which added sanitizeProviderError in tracker_doctor.go (redacts sk-ant-, sk-, AIza*, bearer tokens) and applies it in probeProvider before any error text lands in CheckDetail.Message. Round-4 review also fixed sanitize-before-trim ordering to prevent partial-key leaks. Closes issue #106 via #113.

@clintecker clintecker closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(tracker): sanitize provider error bodies in CheckDetail.Message

3 participants