Skip to content
Open
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
2 changes: 1 addition & 1 deletion scripts/audit-public-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ROOT = Path(__file__).resolve().parents[1]
MAX_BLOB = 32 * 1024 * 1024
CREDENTIALS = [
re.compile(rb'(?:gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-[A-Za-z0-9_-]{20,}|AKIA[A-Z0-9]{16}|AIza[A-Za-z0-9_-]{30,}|xox[baprs]-[A-Za-z0-9-]{15,})'),
re.compile(rb'(?:gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}|AKIA[A-Z0-9]{16}|AIza[A-Za-z0-9_-]{30,}|xox[baprs]-[A-Za-z0-9-]{15,})'),
re.compile(rb'-----BEGIN (?:RSA |EC |OPENSSH |ENCRYPTED )?PRIVATE KEY-----'),
re.compile(rb'(?i)\bauthorization\s*[:=]\s*[\x22\x27]?\s*(?:bearer|basic)\s+[A-Za-z0-9_+=./-]{12,}'),
re.compile(rb'''(?i)\b(?:api[_-]?key|client[_-]?secret|password|access[_-]?token|session[_-]?token|cookie)\b[\x22\x27]?\s*[:=]\s*[\x22\x27][^\x22\x27\r\n]{12,}[\x22\x27]'''),
Expand Down
10 changes: 10 additions & 0 deletions scripts/tests/test_publication_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def test_secrets_in_history_and_a_tag_remain_detected_after_head_cleanup(self):
findings = self.scan('history')['findings']
self.assertTrue(any(f['rule'] == 'credential' and f['location'] == 'history-only' for f in findings))

def test_sk_key_inside_a_longer_word_is_not_a_credential(self):
# A merge message for branch fix/cask-browser-download-url once matched sk-[...]{20,}.
self.write('notes.txt', 'see fix/cask-browser-download-url and task-runner-configuration-file')
self.git('commit', '-qm', 'Merge pull request #1 from example/fix/cask-browser-download-url')
self.assertNotIn('credential', {f['rule'] for f in self.scan('history')['findings']})
for prefix in ['', 'OPENAI_API_KEY=', 'key: "', ' ']:
with self.subTest(prefix=prefix):
self.write('key.txt', prefix + 'sk-' + 'e' * 40)
self.assertIn('credential', {f['rule'] for f in self.scan('staged')['findings']})

def test_same_blob_under_different_historical_names_gets_filename_checks(self):
self.write('notes.txt', 'harmless bytes')
self.git('commit', '-qm', 'first')
Expand Down
Loading