Skip to content

fix(agent-os): detect context-cued bare SSNs in redactor and adapter PII patterns - #3801

Open
dylanyunlon wants to merge 1 commit into
microsoft:mainfrom
dylanyunlon:fix/context-cued-bare-ssn-evasion
Open

fix(agent-os): detect context-cued bare SSNs in redactor and adapter PII patterns#3801
dylanyunlon wants to merge 1 commit into
microsoft:mainfrom
dylanyunlon:fix/context-cued-bare-ssn-evasion

Conversation

@dylanyunlon

Copy link
Copy Markdown

Closes #3592

Problem

CredentialRedactor.PII_PATTERNS and integrations.base.PII_PATTERNS both require a separator between digit groups so that bare nine-digit numbers (tracking numbers, ZIP+4, ABA routing numbers) do not hard-block at the MCP gateway. That requirement also lets a genuine SSN through when it is written without separators next to an explicit cue:

  • SSN: 745102386
  • ssn=745102386
  • social security number 745102386

None of these match at either detector today (verified against both patterns), so tool output carrying a cued bare SSN is neither redacted at the gateway nor blocked by the adapters.

Fix

Add a "US SSN (context-cued)" pattern to both detection sites. The pattern fires only when a case-insensitive cue keyword (ssn, social security, social security number/num/no/#, soc sec) appears immediately before the nine-digit run, keeping uncued bare digits as non-matches so the false-positive suppression from #3531 is preserved. Both detectors carry the identical regex to stay in lockstep (#3591 tracks their alignment).

Call chain (2 entry points, 2 source files, 2 test files)

Entry point Guard
CredentialRedactor.find_pii_matches() PII_PATTERNS["US SSN (context-cued)"].pattern
adapter PII scan (autogen/bedrock) integrations.base.PII_PATTERNS[1]

Files changed (5)

File Change
agent-governance-python/agent-os/src/agent_os/credential_redactor.py New US SSN (context-cued) CredentialPattern with cue-anchored regex
agent-governance-python/agent-os/src/agent_os/integrations/base.py Mirrored context-cued regex in PII_PATTERNS tuple (index 1)
agent-governance-python/agent-os/tests/test_credential_redactor.py 18 new tests (11 positive cued matches, 6 negative uncued stability, 1 matched_text assertion)
agent-governance-python/agent-os/tests/test_pii_patterns.py 9 new tests (5 positive cued matches, 4 negative uncued stability)
CHANGELOG.md ### Fixed entry under [Unreleased]

Tests

18 new tests over the two detection call chains:

  • test_context_cued_bare_ssn_is_detected (11 tests): every cue variant from the issue (SSN:, ssn=, social security number, Social Security, soc sec, socsec, etc.) with a bare nine-digit run.
  • test_context_cued_ssn_does_not_match_uncued_bare_digits (6 tests): uncued bare digits (tracking numbers, invoices, routing numbers, phone-like) are NOT matched — preserves fix(agent-os): detect separated SSN forms without matching bare nine digits #3531 FP suppression.
  • test_context_cued_ssn_match_captures_digits_only (1 test): the matched_text includes the digit run for redaction.
  • test_shared_context_cued_ssn_matches_cued_bare_digits (5 tests): adapter-side PII_PATTERNS[1] matches cued forms.
  • test_shared_context_cued_ssn_rejects_uncued_bare_digits (4 tests): adapter-side pattern rejects uncued forms.

All 125 existing + new tests pass.

Signed-off-by: dylanyunlon dogechat@163.com

…PII patterns

CredentialRedactor.PII_PATTERNS and integrations.base.PII_PATTERNS both
require a separator between digit groups so that bare nine-digit numbers
(tracking numbers, ZIP+4, ABA routing numbers) do not hard-block at the
MCP gateway.  That requirement also lets a genuine SSN through when it
is written without separators next to an explicit cue:

    SSN: 745102386
    ssn=745102386
    social security number 745102386

Add a "US SSN (context-cued)" pattern to both detection sites.  The
pattern fires only when a case-insensitive cue keyword (ssn, social
security, social security number/num/no/#, soc sec) appears immediately
before the nine-digit run, keeping uncued bare digits as non-matches so
the false-positive suppression from microsoft#3531 is preserved.  Both detectors
carry the identical regex to stay in lockstep (microsoft#3591 tracks their
alignment).

Call chain (2 entry points, 2 source files, 2 test files):

  CredentialRedactor.find_pii_matches()
    -> PII_PATTERNS["US SSN (context-cued)"].pattern
  adapter PII scan (autogen/bedrock)
    -> integrations.base.PII_PATTERNS[1]

18 new tests across test_credential_redactor.py (11 positive, 6
negative, 1 matched_text assertion) and test_pii_patterns.py (5
positive, 4 negative).

Closes microsoft#3592

Signed-off-by: dylanyunlon <dogechat@163.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests size/M Medium PR (< 200 lines) labels Aug 21, 2026
@github-actions

Copy link
Copy Markdown

🟡 Contributor Check: MEDIUM

Check Result
Profile MEDIUM
Credential LOW
Overall MEDIUM

Automated check by AGT Contributor Check.

@github-actions github-actions Bot added the needs-review:MEDIUM Contributor check flagged MEDIUM risk label Aug 21, 2026
@github-actions

Copy link
Copy Markdown

PR Review Summary

Check Status Details
🔍 Code Review ⚠️ Missing No current-run comment
🛡️ Security Scan ⚠️ Missing No current-run comment
🔄 Breaking Changes ⚠️ Missing No current-run comment
📝 Docs Sync ⚠️ Missing No current-run comment
🧪 Test Coverage ⚠️ Missing No current-run comment

Verdict: ⚠️ AI review incomplete; ready for human review

AI review comments are untrusted advisory output. The summary reports workflow-generated completion status only, not model-authored pass/fail claims.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation needs-review:MEDIUM Contributor check flagged MEDIUM risk size/M Medium PR (< 200 lines) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context-cued bare SSNs evade both the redactor and adapter SSN detectors

1 participant