From f9fef691612572cfaaba52a6f5ac2ac861eb6052 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 03:38:03 +0000 Subject: [PATCH 1/3] Bound intake package path components to what a checkout can hold safe_path() bounded no component length and no component grammar beyond '..', dotfiles and canonical form. A package file whose name component is 300 bytes passes GitHub's web merge (no checkout) and then fails every fresh clone and full-checkout workflow on main with 'File name too long' on ext4/APFS/NTFS. Windows reserved device names and components ending in space or dot are the Windows-only variant; components beginning with space or '-' are hygiene. safe_path() now requires: total length <= MAX_PACKAGE_PATH (1024, the same bound as MAX_SOURCE_PATH); every component <= NAME_MAX (255 bytes; the grammar is ASCII-only so len() counts bytes), not beginning with space or '-', not ending in space or dot, and not a Windows reserved device name in any case. Package file paths and manifest artifact records only: source rows are exact tree keys and keep source_path() unchanged. Messages never echo the submitted value. Controls, each shown to fail when its rule is weakened on a scratch copy: refusal through the full check as a package file and as a manifest record, refusal at the CLI boundary before any source fetch and without echoing the name, acceptance of a 255-byte component and of ordinary names (inner spaces, 'CONTENTS.md', 'COM10.md', 'nul-report.md'), the 1024/1025 path length boundary, source rows unaffected, and a path-only census over the 10 landed packets (182 artifact rows) in the checkout. Finding PT-1 of the adversarial panel on main #86 comment 5851057735 (MINOR, 3/3 unrefuted). Scientific effect NONE. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Fij9F1cYrAUDW7PhWQze1G --- tests/test_public_intake.py | 93 ++++++++++++++++++++++++++++++++++++ tools/public_intake_check.py | 11 +++++ 2 files changed, 104 insertions(+) diff --git a/tests/test_public_intake.py b/tests/test_public_intake.py index 6794a2bf7..391f5841e 100644 --- a/tests/test_public_intake.py +++ b/tests/test_public_intake.py @@ -722,6 +722,99 @@ def test_public_catalog_census_splits_source_and_package_grammar(self): self.assertIn(COLON_PATH, refused) self.assertTrue(all(not path.isascii() or ':' in path for path in refused)) + # --- PT-1 of main #86 comment 5851057735 (adversarial panel; MINOR, 3/3 unrefuted): + # safe_path bounded no component length and no component grammar beyond '..', + # dotfiles and canonical form, so a tree GitHub stores but no fresh clone can + # check out passed the checker. The probes below reproduce the finding; the + # controls invert it. Source rows are exact tree keys and are not governed. + + INCOMING = Path(__file__).resolve().parents[1] / 'incoming' + + def accept_name(self, name): + self.raw[name] = b'payload' + self.save() + self.assertEqual(self.run_check()['artifact_files'], len(self.raw)) + self.raw.pop(name) + + def test_unportable_package_components_refused(self): + """A 300-byte component (git: 'File name too long' on ext4/APFS/NTFS), components + beginning with space or '-' or ending in space or dot, and Windows reserved device + names in any case, as a package file and as a manifest artifact record.""" + names = ['a' * 300 + '.md', 'sub /x.md', 'sub/ /x.md', 'sub/ x.md', 'x /y.md', 'dir./x.md', 'sub/-rf.md', 'sub/-x.md', + 'CON.md', 'con.md', 'con', 'nul.txt', 'Nul.json', 'com1.csv', 'COM9.csv', 'Aux.json', 'lpt1.md', 'lpt9.md', 'PRN.md', + 'CON.tar.md', 'nested/' + 'b' * 256] + for name in names: + with self.subTest(package_file=name[:40]): + old = self.raw.copy() + self.raw[name] = b'payload' + self.save() + self.reject('unportable path component') + self.raw = old + with self.subTest(artifact_record=name[:40]): + self.save() + self.manifest['artifacts'][0]['path'] = name + self.files['IDENTITY.json'] = json.dumps(self.manifest).encode() + self.install() + self.reject('unportable path component') + with self.assertRaisesRegex(ValueError, 'unportable path component'): + intake.safe_path('incoming/example/' + name) + + def test_unportable_component_refused_at_cli_boundary_without_echo(self): + name = 'a' * 300 + '.md' + self.raw[name] = b'payload' + self.save() + self.api.calls.clear() + code, result = self.cli() + self.assertEqual((code, result['result'], result['reason']), (1, 'REJECTED', 'unportable path component')) + self.assertNotIn('aaaa', json.dumps(result)) + self.assertFalse(any(MATH in route for route in self.api.calls)) # refused before any source fetch + + def test_portable_package_components_accepted(self): + for name in ['a' * 252 + '.md', 'notes-2026.md', 'regeneration/run 1.txt', 'a.b.c.md', 'a b.md', 'CONTENTS.md', 'console.md', + 'nul-report.md', 'COM10.md', 'x-y/z.md', 'v3/lpw_constant_v3.py.txt', 'sub/x-.md', 'sub/x.-y.md']: + with self.subTest(name=name[:40]): + self.accept_name(name) + self.assertEqual(len('a' * 252 + '.md'), intake.NAME_MAX) + + def test_package_path_length_bounded_like_source_paths(self): + prefix = 'incoming/example/' + name = '/'.join(['a' * 200] * 4 + ['b' * 200 + '.md']) + self.assertEqual(len(prefix + name), 1024) + self.assertEqual(intake.MAX_PACKAGE_PATH, intake.MAX_SOURCE_PATH) + self.accept_name(name) + self.raw[name + 'b'] = b'payload' + self.save() + self.reject('path too long') + self.raw.pop(name + 'b') + with self.assertRaisesRegex(ValueError, 'path too long'): + intake.safe_path(prefix + name + 'b') + + def test_source_rows_keep_the_tree_key_grammar(self): + # The component grammar governs package and manifest paths only. A pinned + # source is an exact key into the tree the git trees API returns. + path = 'drive/mirrors/' + 'a' * 300 + '/ CON./-x.md' + self.assertEqual(intake.source_path(path), path.split('/')) + self.manifest['sources'][0]['path'] = path + self.save() + self.assertEqual(self.run_check()['verified_sources'], 1) + + def test_landed_packets_keep_passing_the_component_grammar(self): + """Census over the landed packets in this checkout: every artifact row of every + incoming/*/IDENTITY.json still passes safe_path, as a manifest path and as the + package file path. Path-only; no network.""" + manifests = sorted(self.INCOMING.glob('*/IDENTITY.json')) + self.assertTrue(manifests) + checked = 0 + for manifest in manifests: + package = manifest.parent.name + for row in intake.strict_json(manifest.read_bytes())['artifacts']: + with self.subTest(package=package, path=row['path']): + self.assertEqual(intake.safe_path(row['path']), row['path'].split('/')) + self.assertEqual(intake.safe_path(f'incoming/{package}/' + row['path'])[:2], ['incoming', package]) + checked += 1 + self.assertGreater(checked, 0) + + if __name__ == '__main__': unittest.main() diff --git a/tools/public_intake_check.py b/tools/public_intake_check.py index 3d045053c..d273fe2de 100644 --- a/tools/public_intake_check.py +++ b/tools/public_intake_check.py @@ -32,6 +32,9 @@ HEX64 = re.compile(r'[0-9a-f]{64}\Z') REPOSITORY = re.compile(r'[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+\Z') SAFE_PATH = re.compile(r'[A-Za-z0-9_][A-Za-z0-9_. /-]*\Z') +NAME_MAX = 255 # ext4/APFS/NTFS component limit; SAFE_PATH is ASCII-only, so len() counts bytes +MAX_PACKAGE_PATH = 1024 # the same bound as MAX_SOURCE_PATH; a checkout prefix still fits under PATH_MAX +WINDOWS_RESERVED = {'CON', 'PRN', 'AUX', 'NUL'} | {p + d for p in ('COM', 'LPT') for d in '123456789'} BRANCH = re.compile(r'[A-Za-z0-9_][A-Za-z0-9_./-]*\Z') # a name this route can carry; '..' refused below MAX_BRANCH_PAGES = 3 MAX_SOURCE_PATH = 1024 @@ -75,8 +78,16 @@ def finite_float(token): def safe_path(path): require(isinstance(path, str) and SAFE_PATH.fullmatch(path), 'unsafe path') + require(len(path) <= MAX_PACKAGE_PATH, 'path too long') parts = path.split('/') require(all(p not in ('', '.', '..') and not p.startswith('.') for p in parts), 'unsafe path') + # A merged tree must be one every fresh clone can check out. git refuses a + # component over 255 bytes on ext4/APFS/NTFS, Windows refuses its reserved + # device names and names ending in space or dot, and a component beginning + # with space or '-' reads as an option. Package and manifest paths only; + # source rows are exact tree keys and keep source_path() below. + require(all(len(p) <= NAME_MAX and p[0] not in ' -' and p[-1] not in ' .' + and p.split('.')[0].upper() not in WINDOWS_RESERVED for p in parts), 'unportable path component') require(str(PurePosixPath(path)) == path, 'noncanonical path') return parts From 50c4697d701dd6d0d9fbe40e171159c05adb3057 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 03:40:13 +0000 Subject: [PATCH 2/3] Cover common credential formats in the intake scan The CREDENTIALS scan refused unencrypted PEM private keys, GitHub, AWS, Slack bot, OpenAI and Anthropic tokens, and passed eight other common formats inside output.json or RESULT.md: encrypted and PGP private-key armor, Google AIza keys, npm and Hugging Face tokens, Stripe live keys, three-part JWTs and Slack incoming-webhook URLs. The PEM pattern now matches any '-----BEGIN PRIVATE KEY[ BLOCK]-----' armor, and six byte patterns are added for the other formats, each with the format's fixed length or a floor so that shared prefixes in prose (npm_package, hf_model, sk_live_test, a short AIza run, a one-dot eyJ pair, hooks.slack.com without /services/) are not refused. The refusal message is unchanged and never echoes the value. The scan is still not a guarantee; the module docstring and CONTRIBUTING say so and are not edited. Controls, each shown to fail when its pattern is removed on a scratch copy (the PEM control fails when the pattern is reverted to the old regex): each new format and each previously covered format planted inside output.json and inside RESULT.md is refused at the CLI boundary without echo; a prose file of look-alikes, public PEM armor, SHA digests, base64 and URLs is accepted; a byte-for-byte census over the 10 landed packets (192 files) still passes the scan. Finding CR-F6 of the adversarial panel on main #86 comment 5851057735 (MINOR, 2/3 unrefuted). Scientific effect NONE. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Fij9F1cYrAUDW7PhWQze1G --- tests/test_public_intake.py | 78 ++++++++++++++++++++++++++++++++++++ tools/public_intake_check.py | 9 ++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/tests/test_public_intake.py b/tests/test_public_intake.py index 391f5841e..628fdcbc6 100644 --- a/tests/test_public_intake.py +++ b/tests/test_public_intake.py @@ -814,6 +814,84 @@ def test_landed_packets_keep_passing_the_component_grammar(self): checked += 1 self.assertGreater(checked, 0) + # --- CR-F6 of main #86 comment 5851057735 (adversarial panel; MINOR, 2/3 unrefuted): + # the CREDENTIALS scan missed encrypted and PGP private-key armor, Google AIza + # keys, npm and Hugging Face tokens, Stripe live keys, three-part JWTs and + # Slack webhook URLs, while sk-ant-/sk-proj- and plain PEM were refused. The + # scan is still not a guarantee (module docstring; CONTRIBUTING), so no stated + # promise was broken; the dissenting refuter graded it INFO on that ground. + + NEW_CREDENTIAL_FORMATS = { + 'encrypted PEM': '-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQI', + 'PGP private key block': '-----BEGIN PGP PRIVATE KEY BLOCK-----\n\nlQOYBGQAAAABCADK', + 'Google API key': 'AIza' + 'SyA1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q', # 4 + 35 characters + 'npm token': 'npm_' + 'A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8', + 'Hugging Face token': 'hf_' + 'A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7', + 'Stripe live key': 'sk_live_' + '4eC39HqLyjWDarjtT1zdp7dc', + 'JWT': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', + # Assembled at run time: the literal URL shape trips GitHub push protection on the test file itself. + 'Slack webhook': 'https://hooks.slack.com/' + '/'.join(['services', 'T0123ABCD', 'B0123ABCD', 'a1B2c3D4e5F6g7H8i9J0k1L2']), + } + OLD_CREDENTIAL_FORMATS = { + 'plain PEM': '-----BEGIN PRIVATE KEY-----', 'RSA PEM': '-----BEGIN RSA PRIVATE KEY-----', 'OpenSSH PEM': '-----BEGIN OPENSSH PRIVATE KEY-----', + 'GitHub classic': 'ghp_' + 'X' * 36, 'GitHub fine-grained': 'github_pat_' + 'X' * 60, 'AWS': 'AKIA' + 'A' * 16, + 'Slack bot': 'xoxb-' + '1' * 12, 'OpenAI project': 'sk-proj-' + 'A' * 48, 'Anthropic': 'sk-ant-api03-' + 'A' * 95, + } + + def plant(self, value, where): + # Both text files start clean so each planting is judged on its own. + self.raw['RESULT.md'] = b'# Result\nIllustration only; scientific effect NONE.\n' + self.raw['output.json'] = b'{"illustration":true}\n' + if where == 'output.json': + self.raw['output.json'] = json.dumps({'token': value}).encode() + else: + self.raw['RESULT.md'] = self.raw['RESULT.md'] + ('\n' + value + '\n').encode() + self.save() + + def test_common_credential_formats_refused_without_echo(self): + for label, value in {**self.NEW_CREDENTIAL_FORMATS, **self.OLD_CREDENTIAL_FORMATS}.items(): + for where in ('output.json', 'RESULT.md'): + with self.subTest(format=label, where=where): + self.plant(value, where) + code, result = self.cli() + self.assertEqual((code, result['result'], result['reason']), + (1, 'REJECTED', 'possible credential detected; values are not logged')) + self.assertNotIn(value.split('\n')[0][-16:], json.dumps(result)) + for label, value in self.NEW_CREDENTIAL_FORMATS.items(): + with self.subTest(pattern=label): + self.assertTrue(any(pattern.search(value.encode()) for pattern in intake.CREDENTIALS)) + + def test_credential_lookalikes_in_prose_accepted(self): + """False-positive guards: identifiers that share a prefix, a one-dot pair, + hooks.slack.com in prose, public PEM armor, SHA digests, base64, URLs.""" + prose = ' '.join([ + 'npm_package.json', 'hf_model-card', 'sk_live_test', 'AIza' + 'A' * 10, 'AIza' + 'A' * 36, + 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0', 'see https://hooks.slack.com/ for the format', + '-----BEGIN PUBLIC KEY-----', '-----BEGIN CERTIFICATE-----', '-----BEGIN PGP PUBLIC KEY BLOCK-----', '-----BEGIN PGP SIGNATURE-----', + 'a' * 64, '0123456789abcdef' * 4, 'd' * 40, 'QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=' * 3, + 'https://github.com/d6g8k5htny-coder/main/blob/main/docs/x.md', '[a.b.c](https://example.org/a.b.c?x=1)', + 'version 1.2.3', 'eyJ.eyJ.eyJ', 'hf_', 'npm_', 'sk_live_']) + for where in ('output.json', 'RESULT.md'): + with self.subTest(where=where): + self.plant(prose, where) + self.assertEqual(self.run_check()['verified_sources'], 1) + self.assertFalse(any(pattern.search(prose.encode()) for pattern in intake.CREDENTIALS)) + + def test_landed_packets_keep_passing_the_credential_scan(self): + """Census over the landed packets in this checkout: every artifact file and + IDENTITY.json still passes the CREDENTIALS scan byte-for-byte. No network.""" + manifests = sorted(self.INCOMING.glob('*/IDENTITY.json')) + self.assertTrue(manifests) + checked = 0 + for manifest in manifests: + rows = intake.strict_json(manifest.read_bytes())['artifacts'] + for name in ['IDENTITY.json'] + [row['path'] for row in rows]: + with self.subTest(package=manifest.parent.name, path=name): + raw = (manifest.parent / name).read_bytes() + self.assertFalse(any(pattern.search(raw) for pattern in intake.CREDENTIALS)) + checked += 1 + self.assertGreater(checked, 0) + if __name__ == '__main__': diff --git a/tools/public_intake_check.py b/tools/public_intake_check.py index d273fe2de..5de36dbe7 100644 --- a/tools/public_intake_check.py +++ b/tools/public_intake_check.py @@ -39,12 +39,19 @@ MAX_BRANCH_PAGES = 3 MAX_SOURCE_PATH = 1024 CREDENTIALS = [ - re.compile(rb'-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----'), + # Any PEM private-key armor: unencrypted, ENCRYPTED, RSA/EC/OPENSSH/DSA, and PGP's '... PRIVATE KEY BLOCK'. + re.compile(rb'-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----'), re.compile(rb'\bgh[pousr]_[A-Za-z0-9]{36,}\b'), re.compile(rb'\bgithub_pat_[A-Za-z0-9_]{60,}\b'), re.compile(rb'\b(?:AKIA|ASIA)[A-Z0-9]{16}\b'), re.compile(rb'\bxox[baprs]-[A-Za-z0-9-]{10,}\b'), re.compile(rb'\bsk-(?:proj-)?[A-Za-z0-9_-]{32,}\b'), + re.compile(rb'\bAIza[0-9A-Za-z_-]{35}\b'), # Google API key: fixed 39 characters + re.compile(rb'\bnpm_[A-Za-z0-9]{36}\b'), # npm access token + re.compile(rb'\bhf_[A-Za-z0-9]{30,}\b'), # Hugging Face token + re.compile(rb'\bsk_live_[0-9A-Za-z]{20,}\b'), # Stripe live secret key + re.compile(rb'\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b'), # three-part JWT ('{"' in base64url) + re.compile(rb'hooks\.slack\.com/services/T[A-Z0-9]+/B[A-Z0-9]+/[A-Za-z0-9]+'), # Slack incoming webhook ] From ff90a74f827a24782a0afb916c7ca132ebfd4778 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 05:45:32 +0000 Subject: [PATCH 3/3] Match device names with end-of-stem spaces, and bound AIza in its own alphabet Two findings from the nonauthor engineering review of PR #240 at 50c4697 (comment 5966056876), both in the guards this branch adds. F1: the reserved-name check compared the raw stem, but Windows drops spaces at the end of a stem before matching device names, so 'CON .md', 'nul .txt' and 'COM1 .dir/result.md' passed the full CLI (176 aliases over the 22 stems in the reviewer's enumeration). The stem is now compared with end-of-stem spaces removed. 'CON report.md', 'COM10 .md' and inner spaces stay accepted. The comment above the check no longer claims every fresh clone can check the tree out; it says what the guard does and that it is not a guarantee. F2: the Google-key pattern admitted '-' in its 35-character body but closed with a word boundary, so a 39-character value ending in '-' passed inside RESULT.md, output.json and as a filename, while a 40-character look-alike was refused by its prefix. Both boundaries are now lookarounds over the token's own alphabet [0-9A-Za-z_-]; the JWT pattern, which shares that alphabet, gets the same boundaries. Fixed-length look-alikes (40 characters, or preceded by '_' or '-') are accepted again. All values are synthetic. Controls, each shown to fail with the fix reverted on a scratch copy: the space aliases as package file, manifest record and at the CLI boundary; the hyphen-tail key in both text files and in a filename, refused without echo; five look-alikes accepted. 71 tests pass normal and -O; both censuses pass. Scientific effect NONE. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Fij9F1cYrAUDW7PhWQze1G --- tests/test_public_intake.py | 46 ++++++++++++++++++++++++++++++++++-- tools/public_intake_check.py | 16 +++++++------ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/tests/test_public_intake.py b/tests/test_public_intake.py index 628fdcbc6..d22cdd10b 100644 --- a/tests/test_public_intake.py +++ b/tests/test_public_intake.py @@ -742,7 +742,9 @@ def test_unportable_package_components_refused(self): names in any case, as a package file and as a manifest artifact record.""" names = ['a' * 300 + '.md', 'sub /x.md', 'sub/ /x.md', 'sub/ x.md', 'x /y.md', 'dir./x.md', 'sub/-rf.md', 'sub/-x.md', 'CON.md', 'con.md', 'con', 'nul.txt', 'Nul.json', 'com1.csv', 'COM9.csv', 'Aux.json', 'lpt1.md', 'lpt9.md', 'PRN.md', - 'CON.tar.md', 'nested/' + 'b' * 256] + 'CON.tar.md', 'nested/' + 'b' * 256, + # PR #240 review 5966056876 F1: Windows drops end-of-stem spaces, so these are device names too. + 'CON .md', 'nul .txt', 'COM1 .dir/result.md', 'con .md', 'Aux .json', 'lpt9 .md', 'PRN '] for name in names: with self.subTest(package_file=name[:40]): old = self.raw.copy() @@ -769,9 +771,21 @@ def test_unportable_component_refused_at_cli_boundary_without_echo(self): self.assertNotIn('aaaa', json.dumps(result)) self.assertFalse(any(MATH in route for route in self.api.calls)) # refused before any source fetch + def test_device_name_with_end_of_stem_space_refused_at_cli_boundary(self): + # PR #240 review 5966056876 F1. 'CON .md' passed the full CLI at 50c4697 with exit 0. + for name in ['CON .md', 'nul .txt', 'COM1 .dir/result.md']: + with self.subTest(name=name): + old = self.raw.copy() + self.raw[name] = b'payload' + self.save() + code, result = self.cli() + self.assertEqual((code, result['result'], result['reason']), (1, 'REJECTED', 'unportable path component')) + self.raw = old + def test_portable_package_components_accepted(self): for name in ['a' * 252 + '.md', 'notes-2026.md', 'regeneration/run 1.txt', 'a.b.c.md', 'a b.md', 'CONTENTS.md', 'console.md', - 'nul-report.md', 'COM10.md', 'x-y/z.md', 'v3/lpw_constant_v3.py.txt', 'sub/x-.md', 'sub/x.-y.md']: + 'nul-report.md', 'COM10.md', 'x-y/z.md', 'v3/lpw_constant_v3.py.txt', 'sub/x-.md', 'sub/x.-y.md', + 'CON report.md', 'COM10 .md', 'sub/run 1.md', 'CONTENTS .md']: with self.subTest(name=name[:40]): self.accept_name(name) self.assertEqual(len('a' * 252 + '.md'), intake.NAME_MAX) @@ -861,6 +875,34 @@ def test_common_credential_formats_refused_without_echo(self): with self.subTest(pattern=label): self.assertTrue(any(pattern.search(value.encode()) for pattern in intake.CREDENTIALS)) + def test_google_key_boundaries_follow_its_alphabet(self): + """PR #240 review 5966056876 F2: the pattern admitted '-' in its body but closed + with a word boundary, so a 39-character value ending in '-' passed inside text + and as a filename, while a 40-character look-alike was refused by its prefix. + Boundaries are now the token's own alphabet; all values are synthetic.""" + hyphen_tail = 'AIza' + 'A' * 34 + '-' + for where in ('output.json', 'RESULT.md'): + with self.subTest(where=where): + self.plant(hyphen_tail, where) + code, result = self.cli() + self.assertEqual((code, result['result'], result['reason']), + (1, 'REJECTED', 'possible credential detected; values are not logged')) + for text in [hyphen_tail, '"' + hyphen_tail + '"', hyphen_tail + '\n', '(' + hyphen_tail + ').', 'x ' + hyphen_tail + ' y']: + with self.subTest(text=text[-6:]): + self.assertTrue(any(pattern.search(text.encode()) for pattern in intake.CREDENTIALS)) + self.plant('', 'RESULT.md') + self.raw[hyphen_tail + '.md'] = b'payload' + self.save() + code, result = self.cli() + self.assertEqual((code, result['result'], result['reason']), (1, 'REJECTED', 'possible credential in path; values are not logged')) + self.assertNotIn('AIza', json.dumps(result)) + self.raw.pop(hyphen_tail + '.md') + for lookalike in ['AIza' + 'A' * 35 + '-', 'AIza' + 'A' * 36, '_AIza' + 'A' * 35, '-AIza' + 'A' * 35, 'xAIza' + 'A' * 35]: + with self.subTest(lookalike=lookalike[:6] + '...' + lookalike[-2:]): + self.assertFalse(any(pattern.search(lookalike.encode()) for pattern in intake.CREDENTIALS)) + self.plant(lookalike, 'RESULT.md') + self.assertEqual(self.run_check()['verified_sources'], 1) + def test_credential_lookalikes_in_prose_accepted(self): """False-positive guards: identifiers that share a prefix, a one-dot pair, hooks.slack.com in prose, public PEM armor, SHA digests, base64, URLs.""" diff --git a/tools/public_intake_check.py b/tools/public_intake_check.py index 5de36dbe7..edc64d9a7 100644 --- a/tools/public_intake_check.py +++ b/tools/public_intake_check.py @@ -46,11 +46,11 @@ re.compile(rb'\b(?:AKIA|ASIA)[A-Z0-9]{16}\b'), re.compile(rb'\bxox[baprs]-[A-Za-z0-9-]{10,}\b'), re.compile(rb'\bsk-(?:proj-)?[A-Za-z0-9_-]{32,}\b'), - re.compile(rb'\bAIza[0-9A-Za-z_-]{35}\b'), # Google API key: fixed 39 characters + re.compile(rb'(?