From 60e69a87fac05b1ea3a9e8d54d6ceb97ed5c166a Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:44:57 -0500 Subject: [PATCH] Reject NUL paths in source references and manifests Isolated two-file source-contract repair under META-CONTRACT-NUL-20261014. Preserve the separately owned architecture JSON loader and registry checks. Actual author: OpenAI / GPT-6 Astra Pro, meta-framework validation conversation. Scientific effect: NONE. --- tests/test_source_contracts.py | 37 ++++++++++++++++++++++++++++++++++ tools/contract_validation.py | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/test_source_contracts.py b/tests/test_source_contracts.py index b528f70..3e13767 100644 --- a/tests/test_source_contracts.py +++ b/tests/test_source_contracts.py @@ -22,6 +22,43 @@ def test_public_git_source_ref_rejects_sandbox_and_noncanonical_repo(self): with self.assertRaises(ContractError): validate_source_ref(git_ref(repository=repo)) def test_source_ref_rejects_case_variant_sandbox_path(self): with self.assertRaisesRegex(ContractError,'sandbox'): validate_source_ref(git_ref(path='Sandbox/private.txt')) + def test_git_source_ref_rejects_nul_at_each_position(self): + for path in ('\x00docs/proof.md', 'docs/\x00proof.md', 'docs/proof.md\x00'): + with self.subTest(path=path): + row = git_ref(path=path) + before = json.loads(json.dumps(row)) + with self.assertRaisesRegex(ContractError, '^unsafe path$'): + validate_source_ref(row) + self.assertEqual(row, before) + + def test_source_manifest_rejects_nul_at_each_position(self): + for path in ('\x00docs/proof.md', 'docs/\x00proof.md', 'docs/proof.md\x00'): + with self.subTest(path=path): + row = {'schema_version':'1.0', 'distribution':'synthetic', 'version':'0.1.0', + 'repository':'d6g8k5htny-coder/Math-', 'commit':'1'*40, + 'scientific_status_authority':False, + 'files':[{'path':path, 'sha256':'2'*64, 'bytes':0}]} + before = json.loads(json.dumps(row)) + with self.assertRaisesRegex(ContractError, '^unsafe path$'): + validate_source_manifest(row) + self.assertEqual(row, before) + + def test_source_paths_preserve_ordinary_names_and_inputs(self): + for path in ('docs/proof.md', 'docs/proof notes.md', 'docs/\u03b1.md'): + reference = git_ref(path=path) + manifest = {'schema_version':'1.0', 'distribution':'synthetic', 'version':'0.1.0', + 'repository':'d6g8k5htny-coder/Math-', 'commit':'1'*40, + 'scientific_status_authority':False, + 'files':[{'path':path, 'sha256':'2'*64, 'bytes':0}]} + for validator, row in ((validate_source_ref, reference), + (validate_source_manifest, manifest)): + with self.subTest(path=path, validator=validator.__name__): + before = json.loads(json.dumps(row)) + result = validator(row) + self.assertEqual(result, before) + self.assertIsNot(result, row) + self.assertEqual(row, before) + def test_external_frozen_source_ref(self): row={'schema_version':'1.0','kind':'external','provider':'google-drive','source_id':'abc','sha256':'4'*64,'size_bytes':12,'monitorability':'external-frozen','role':'historical-source','visibility':'public'} self.assertEqual(validate_source_ref(row)['provider'],'google-drive') diff --git a/tools/contract_validation.py b/tools/contract_validation.py index a6226db..74cc75a 100644 --- a/tools/contract_validation.py +++ b/tools/contract_validation.py @@ -31,7 +31,7 @@ def _copy(data: Any) -> dict: return dict(data) def _safe_path(text: Any) -> str: - if not isinstance(text,str) or not text or '\\' in text or ':' in text: raise ContractError('unsafe path') + if not isinstance(text,str) or not text or '\\' in text or ':' in text or '\x00' in text: raise ContractError('unsafe path') p=PurePosixPath(text) if p.is_absolute() or '..' in p.parts or str(p)!=text: raise ContractError('unsafe path') if any(part.casefold()=='sandbox' for part in p.parts): raise ContractError('private sandbox path refused')