From ceb82227b0069b0d34c5f251a48d738c4945c3f9 Mon Sep 17 00:00:00 2001 From: jwalith4418-Mj Date: Wed, 25 Nov 2026 08:26:49 +0530 Subject: [PATCH] fix(secrets): detect Mapbox secret tokens AI-assisted implementation and validation with OpenAI Codex. --- repodx.py | 1 + tests/test_repodx.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/repodx.py b/repodx.py index 646e10e..1a5acd7 100644 --- a/repodx.py +++ b/repodx.py @@ -381,6 +381,7 @@ def check_readme(repo_path): ("Groq API key", r"\bgsk_[A-Za-z0-9]{48,}\b"), ("Perplexity API key", r"\bpplx-[A-Za-z0-9]{40,}\b"), ("Replicate API token", r"\br8_[A-Za-z0-9]{37}\b"), + ("Mapbox secret token", r"\bsk\.eyJ[A-Za-z0-9_\-]{20,}\.[A-Za-z0-9_\-]{20,}"), ("Linear API key", r"\blin_api_[A-Za-z0-9]{40}\b"), ("SendGrid API key", r"\bSG\.[A-Za-z0-9_\-]{22}\.[A-Za-z0-9_\-]{43}\b"), # Sentry DSNs are public by design; only the auth tokens carry the sntry prefix. diff --git a/tests/test_repodx.py b/tests/test_repodx.py index f5d7c1b..aab0ca9 100644 --- a/tests/test_repodx.py +++ b/tests/test_repodx.py @@ -571,6 +571,28 @@ def findings_for(repo_path, check_id): class SecretScanTests(unittest.TestCase): + def test_mapbox_secret_token_is_reported_once_but_public_token_is_not(self): + payload = base64.urlsafe_b64encode( + json.dumps({"u": "scanner-test", "a": "q7ZT4mWx9Rb2Kd5Nf8Lp"}).encode() + ).decode().rstrip("=") + signature = fake("Q7zT4mWx9Rb2", "Kd5Nf8Lp3Hs6Vc1Yj0GuE4tA_-") + secret = fake("sk", ".", payload, ".", signature) + public = fake("pk", ".", payload, ".", signature) + self.assertTrue(repodx.has_candidate(secret)) + self.assertEqual( + repodx.scan_line_for_secrets(f'const key = "{secret}";'), + [("secret", "critical", "Mapbox secret token", secret)], + ) + self.assertEqual(repodx.scan_line_for_secrets(f'const key = "{public}";'), []) + + def test_mapbox_detection_reaches_file_scanner(self): + secret = fake("sk", ".eyJ", "q7ZT4mWx9Rb2Kd5Nf8Lp3Hs6", ".", "Q7zT4mWx9Rb2Kd5Nf8Lp3Hs6") + with tempfile.TemporaryDirectory() as temp_dir: + repo = make_repo(temp_dir, {"map.js": f'const key = "{secret}";\n'}) + hits = findings_for(repo, "secret") + self.assertEqual(len(hits), 1) + self.assertEqual(hits[0]["title"], "Mapbox secret token") + def test_detects_provider_keys(self): keys = { "OpenAI API key": fake("sk-", "proj-", "A1b2C3d4E5f6G7h8I9j0K1l2"),