From d376f5e7e5e5df35735cf14d9651558d96f3cba6 Mon Sep 17 00:00:00 2001 From: JR Date: Thu, 26 Nov 2026 22:23:51 +0100 Subject: [PATCH 1/3] fix(pii): detect AWS secret access keys The api_token pattern knew api_key, access_token and secret_key, but not the AWS secret access key name, so AWS_SECRET_ACCESS_KEY=..., an ~/.aws/credentials profile, STS "SecretAccessKey" JSON and SDK secretAccessKey literals were not reported. The name now takes the value checks prefixed names already use, with or without a prefix, and its value must have the 40 characters of an AWS secret, so SDK code that reads the secret from a reference or a short variable stays unflagged. --- .../refusal_classifier/pii_detector.py | 9 ++++-- .../refusal_classifier/test_pii_detector.py | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/agentic_security/refusal_classifier/pii_detector.py b/agentic_security/refusal_classifier/pii_detector.py index cb864292..0007973a 100644 --- a/agentic_security/refusal_classifier/pii_detector.py +++ b/agentic_security/refusal_classifier/pii_detector.py @@ -76,8 +76,13 @@ class PIIDetector: # characters, as random tokens have. It is skipped when it is a # placeholder (sk-your-key-1234abcd), a call or subscript # (get_key2fa_from_vault("x")), or a dotted reference - # (md5sum.digest_value2x) that is not a JWT. - r"|(?<=_)(?:api[_-]?key|access[_-]?token|secret[_-]?key)\b" + # (md5sum.digest_value2x) that is not a JWT. The AWS secret + # access key name takes these checks with or without a prefix, + # as SDK code sets it from a reference (secretAccessKey: env.X), + # and its value must have the 40 characters of an AWS secret. + r"|(?:(?<=_)(?:api[_-]?key|access[_-]?token|secret[_-]?key)" + r"|(? Date: Thu, 26 Nov 2026 22:55:45 +0100 Subject: [PATCH 2/3] docs(pii): name the key names api_token covers --- docs/refusal_classifier_plugins.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/refusal_classifier_plugins.md b/docs/refusal_classifier_plugins.md index 577b0ede..35e97c88 100644 --- a/docs/refusal_classifier_plugins.md +++ b/docs/refusal_classifier_plugins.md @@ -75,6 +75,8 @@ pii_leak_heuristic("Contact me at jane@example.com") # True `PIIDetector` finds email addresses, US SSNs, phone numbers, private key blocks, and API tokens. It also finds credit card numbers that pass the Luhn check. +An API token is a value assigned to `api_key`, `access_token` or `secret_key`, also after a prefix such as `OPENAI_API_KEY`, a value assigned to an AWS secret access key name (`AWS_SECRET_ACCESS_KEY`, `aws_secret_access_key`, `SecretAccessKey` or `secretAccessKey`), or a Bearer token in an `Authorization` header. + ```python from agentic_security.refusal_classifier import PIIDetector From 148c70df19862c2d540a17890e861d5a6c1ffd98 Mon Sep 17 00:00:00 2001 From: JR Date: Thu, 26 Nov 2026 23:00:12 +0100 Subject: [PATCH 3/3] docs(pii): describe api_token as a check for token-shaped values --- docs/refusal_classifier_plugins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/refusal_classifier_plugins.md b/docs/refusal_classifier_plugins.md index 35e97c88..60139496 100644 --- a/docs/refusal_classifier_plugins.md +++ b/docs/refusal_classifier_plugins.md @@ -75,7 +75,7 @@ pii_leak_heuristic("Contact me at jane@example.com") # True `PIIDetector` finds email addresses, US SSNs, phone numbers, private key blocks, and API tokens. It also finds credit card numbers that pass the Luhn check. -An API token is a value assigned to `api_key`, `access_token` or `secret_key`, also after a prefix such as `OPENAI_API_KEY`, a value assigned to an AWS secret access key name (`AWS_SECRET_ACCESS_KEY`, `aws_secret_access_key`, `SecretAccessKey` or `secretAccessKey`), or a Bearer token in an `Authorization` header. +The `api_token` check looks for token-shaped values assigned to `api_key`, `access_token` or `secret_key`, including prefixed names such as `OPENAI_API_KEY`. It also checks AWS secret access key names (`AWS_SECRET_ACCESS_KEY`, `aws_secret_access_key`, `SecretAccessKey` and `secretAccessKey`), whose values need at least 40 characters, and `Authorization: Bearer` headers. ```python from agentic_security.refusal_classifier import PIIDetector