Skip to content

Commit 7a55336

Browse files
Miyamura80claude
andcommitted
🐛 fix email regex bug and reorder patterns for specificity
- Remove errant `|` from email TLD character class - Move Anthropic pattern before OpenAI for correct matching - Add rk_ prefix to Stripe key tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cd71987 commit 7a55336

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/utils/logging_config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
_logging_lock = threading.Lock()
1515

1616
# PII Patterns for redaction (pre-compiled for performance)
17+
# Note: More specific patterns must come before general ones (e.g., sk-ant- before sk-)
1718
_COMPILED_PII_PATTERNS = [
1819
# Email addresses
1920
(
20-
re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b"),
21+
re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b"),
2122
"[REDACTED_EMAIL]",
2223
),
24+
# Anthropic API keys (sk-ant-...) - must be before OpenAI pattern
25+
(re.compile(r"sk-ant-[a-zA-Z0-9-]{20,}"), "[REDACTED_API_KEY]"),
2326
# OpenAI API keys (sk-...)
2427
(re.compile(r"sk-[a-zA-Z0-9]{20,}"), "[REDACTED_API_KEY]"),
25-
# Anthropic API keys (sk-ant-...)
26-
(re.compile(r"sk-ant-[a-zA-Z0-9-]{20,}"), "[REDACTED_API_KEY]"),
2728
# Stripe API keys (sk_live_*, sk_test_*, pk_live_*, pk_test_*, rk_live_*, rk_test_*)
2829
(re.compile(r"[spr]k_(live|test)_[a-zA-Z0-9]{20,}"), "[REDACTED_API_KEY]"),
2930
# Authorization Bearer tokens

tests/test_logging_security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_stripe_api_key_redaction(self):
8787
"""Test that Stripe API keys are redacted."""
8888
# Construct keys dynamically to avoid GitHub secret scanning
8989
suffix = "0" * 24
90-
prefixes = ["sk" + "_live_", "sk" + "_test_", "pk" + "_live_"]
90+
prefixes = ["sk" + "_live_", "sk" + "_test_", "pk" + "_live_", "rk" + "_live_"]
9191

9292
for prefix in prefixes:
9393
key = prefix + suffix

0 commit comments

Comments
 (0)