← Back to Pull requests

fix(agent-os): redact keyword secrets whose key is quoted #4581

Open
unknown opened this pull request with 386 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 16, 2026 20:34 UTC
Author

Related Issue


None; see #3479 (closed for account reasons).

Problem & Solution


Problem. "Generic API secret" runs the keyword straight into \s*[:=], so quoted keys ({"api_key": "..."}, {'client_secret': '...'}) never match. intercept_tool_response json.dumps structured results first, so such a tool response is "Response clean".

Solution. A quoted-key branch (plain or escaped quote) captures only the value in a secret group, and find_matches reports that span. Output stays valid JSON: {"api_key": "[REDACTED]"}. Unquoted values stop at , } ]. Only a value exactly [REDACTED] is skipped (SANITIZE re-check); no other value-shape exemptions. The scanner keeps one finding per identical span. Other output is unchanged.

Impact on Your Work


Secrets in structured MCP tool output reach the model unredacted.

Timeline


None.

Alternatives Considered


Redacting key and value together breaks JSON; #3479 reviewers asked for value-only spans.

Type of Change


  • Bug fix

  • Security fix
  • Package(s) Affected


  • agent-os
  • Testing


    Unit Testing


    43 new tests (JSON/dict spellings, round-trips, matched_text, negatives, AWS pins, scanner and gateway). Against main source: 21 fail. Fixed: 261 pass. Full suite: same 12 pre-existing failures both sides.

    Manual Testing


    From agent-governance-python/agent-os:
    python -c "import sys; sys.path.insert(0,'src'); from agent_os.credential_redactor import CredentialRedactor as R; print(R.redact('{\"api_key\": \"Zx81kQ0pLm77Qa\"}'))"
    main prints the secret; this branch prints {"api_key": "[REDACTED]"}.

    <details><summary>Limits and follow-ups</summary>

    A redacted number is not valid JSON. Not changed: Rust redactor.rs:90, quoted password/AccountKey.
    </details>

    Checklist


  • Completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"

  • Code follows ruff check

  • Added tests that prove the fix

  • All new and existing tests pass (pytest): 261 pass in the touched files; 12 suite failures pre-exist on main

  • Updated documentation as needed

  • I have signed the Microsoft CLA
  • Attribution & Prior Art


  • No code copied or derived without attribution

  • Inspiring projects credited

  • Similar open-source work listed below
  • Prior art: #3479 (LHMQ878) addressed this gap. This fix was written independently, following that review thread.

    AI Assistance


  • I can explain every meaningful change

  • I have run appropriate tests and verification

  • Nothing here was autonomously submitted without my review

  • I have not used AI to generate review comments
  • Prepared with AI assistance: an AI coding assistant (Claude) reproduced the gap, wrote the fix and tests, and drafted this description. I reviewed every change before submitting.

    IP, Patents, and Licensing


  • Not patent-encumbered

  • No NDA or licence needed

  • AI tools' terms are MIT-compatible
  • John B Joseph, Co-founder & CPTO, Purplecop Security

    Diff: 386 lines (+289 / -97) across 4 files Reviewer: MohammadHaroonAbuomar Review duration: 8647m
    All Vouch review confidence checks passed
    Residual risk 0.35 = Change Risk (0.66) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.66 · 386 lines diff across 4 files
    0.66
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.356
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.066
    Real PR Conversation Timeline
    1 comments
    "Review active on #4581"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 46.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 66.2% (HIGH) · Higher = larger blast radius
    66.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 35.3% · Moderate risk
    35.3%