Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion repodx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
("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.
("Sentry auth token", r"\bsntry[su]_[A-Za-z0-9+/=_\-]{40,}"),
Expand Down Expand Up @@ -431,7 +432,7 @@ def check_readme(repo_path):
CANDIDATE_LITERALS = [
"sk-", "AKIA", "ASIA", "ghp_", "gho_", "ghu_", "ghs_", "ghr_", "github_pat_", "glpat-", "_live_",
"glsa_", "sb_secret_", "xox", "hf_", "npm_", "gsk_", "pplx-", "r8_", "SG.", ":AA", "AIza", "eyJ", "://",
"shpat_", "shpca_", "shppa_", "shpss_", "dop_v1_", "doo_v1_", "pypi-", "sntry",
"shpat_", "shpca_", "shppa_", "shpss_", "dop_v1_", "doo_v1_", "pypi-", "sntry", "lin_api_",
]


Expand Down
19 changes: 19 additions & 0 deletions tests/test_repodx.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ def test_detects_provider_keys(self):
"sntrys", "_", "Q7zT4mWx9Rb2Kd5Nf8Lp3Hs6Vc1Yj0GuE4tA9BnC7Xq2Zw5Mu6Ry3Kd8Nf2"
),
"Replicate API token": fake("r8", "_", "A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S"),
"Linear API key": fake("lin", "_api_", "Q7zT4mWx9Rb2Kd5Nf8Lp3Hs6Vc1Yj0GuE4tA9BnC"),
"Discord webhook URL": fake(
"https://discord.com/api/webhooks/",
"908172635490817263/",
Expand All @@ -615,6 +616,24 @@ def test_detects_provider_keys(self):

self.assertEqual([(hit[0], hit[1], hit[2]) for hit in hits], [("secret", "critical", name)])

def test_detects_linear_api_key_in_a_file(self):
key = fake("lin", "_api_", "Q7zT4mWx9Rb2Kd5Nf8Lp3Hs6Vc1Yj0GuE4tA9BnC")

with tempfile.TemporaryDirectory() as temp_dir:
repo_path = make_repo(temp_dir, {"src/config.js": f"// setup\nconst LINEAR_KEY = '{key}';\n"})

result = findings_for(repo_path, "secret")

self.assertEqual(
[(finding["severity"], finding["title"], finding["path"], finding["line"]) for finding in result],
[("critical", "Linear API key", "src/config.js", 2)],
)

def test_linear_api_key_needs_forty_characters(self):
key = fake("lin", "_api_", "Q7zT4mWx9Rb2Kd5Nf8Lp3Hs6Vc1Yj0GuE4tA9Bn")

self.assertEqual(repodx.scan_line_for_secrets(f'const key = "{key}";'), [])

def test_shared_stripe_clerk_prefix_has_one_neutral_finding(self):
for length in (20, 32, 48, 96):
with self.subTest(length=length):
Expand Down
Loading