diff --git a/docs/verified-update-automation.md b/docs/verified-update-automation.md index 887b1f9..f6c4f74 100644 --- a/docs/verified-update-automation.md +++ b/docs/verified-update-automation.md @@ -174,6 +174,39 @@ now encoded in `schemas/special-review.v1.schema.json` and bound to the exact `fromRef`→`toRef` pair and `reviewedPaths` in `special-review.v1.json`. This remains a read-only review boundary, not a security certification or runtime acceptance. +### Diagnostic scope boundaries (false-positive fixes, no new exemptions) + +`scripts/catalog/update_diagnostics.py` keeps every fail-closed gate, but no longer +blocks on facts that cannot affect the installed payload: + +1. **Single-path installs list only what they read.** When an entry has a + `source.path` and no `children`, diagnostics list the selected subtree, root-level + files, declared license/notice evidence paths and `.claude-plugin`/`.codex-plugin` + manifests instead of the whole repository. A monorepo with more than 20,000 + unrelated files (for example `openclaw/openclaw`) therefore reaches its real gates + instead of stopping at `independent-static-diagnostics: not_checked`. Whole-tree + and collection installs still list the complete tree. +2. **Historic malformed fixtures outside every member scope are informational.** + `frontmatter-parse` stays `blocked` for a newly added or in-member unparseable + `SKILL.md`. Only a file that was already unparseable at the old pin and lies + outside every declared/discovered member scope (such as an upstream test fixture + that is malformed on purpose) is reported as `info`, with `insideMemberScope: false`. +3. **`acceptedBehavioralSecurityReview` is honored by diagnostics.** A valid review + bound to the exact `fromRef`→`toRef` whose `reviewedPaths` cover every changed + authorization/credential/configuration/network path turns + `authorization-config-network-review` into `info`. Missing paths are listed in + `unreviewedPaths` and keep the row `manual_review`; an invalid or other-pin review + is reported in `behavioralReviewError`. +4. **Images named after a license are not license evidence.** `protected_audit_path` + ignores image extensions (`.png`, `.jpg`, `.jpeg`, `.webp`, `.svg`, `.gif`, `.ico`, + `.bmp`, `.avif`), so an icon such as `license.svg` can sit inside an `excludePaths` + directory. `LICENSE*`/`NOTICE*`/`COPYING*` text files and dependency manifests stay + protected. + +Root `NOTICE` delivery is unchanged: the verified client implementations attach only the +catalog license evidence file, so a client-attach review cannot clear +`installed-notice-delivery` for a separate root `NOTICE`. + ### Audited carry-forward rules (reducing repetitive Drafts without skipping checks) To prevent routine updates from repeatedly falling back to Draft when the underlying diff --git a/scripts/catalog/audit_skill_update.py b/scripts/catalog/audit_skill_update.py index d752e6c..ebc28e0 100644 --- a/scripts/catalog/audit_skill_update.py +++ b/scripts/catalog/audit_skill_update.py @@ -161,8 +161,15 @@ def path_matches(name: str, patterns: list[str] | tuple[str, ...] | None) -> boo return False +IMAGE_EXTENSIONS = STATIC_IMAGE_EXTENSIONS | {'.svg', '.gif', '.ico', '.bmp', '.avif'} + + def protected_audit_path(path: str) -> bool: - name = PurePosixPath(path).name.upper() + pure = PurePosixPath(path) + # Icon or image assets named after a license (license.svg) are not license text. + if pure.suffix.lower() in IMAGE_EXTENSIONS: + return False + name = pure.name.upper() return name.startswith(('LICENSE', 'NOTICE', 'COPYING')) or dependency_file(path) diff --git a/scripts/catalog/test_audit_skill_update.py b/scripts/catalog/test_audit_skill_update.py index 99092a3..719a47d 100644 --- a/scripts/catalog/test_audit_skill_update.py +++ b/scripts/catalog/test_audit_skill_update.py @@ -206,6 +206,22 @@ class AuditTests(unittest.TestCase): with self.assertRaisesRegex(AuditBlocked, '排除列表'): audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new}, '2026-10-31T01:02:03Z', special_review=review) + def test_license_named_image_is_not_protected_evidence(self): + from audit_skill_update import protected_audit_path + self.assertFalse(protected_audit_path('skills/sample/icons/license.svg')) + self.assertFalse(protected_audit_path('skills/sample/icons/License-Off.PNG')) + self.assertTrue(protected_audit_path('skills/sample/LICENSE')) + self.assertTrue(protected_audit_path('skills/sample/LICENSE.md')) + self.assertTrue(protected_audit_path('NOTICE.txt')) + self.assertTrue(protected_audit_path('skills/sample/package.json')) + self.write('skills/sample/icons/license.svg', '') + self.write('skills/sample/icons/star.svg', '') + self._rebind_old(self.commit()) + self.write('skills/sample/scripts/tool.py', 'print("new fixture")\n') + new = self.commit() + review = {'schemaVersion': 1, 'excludePaths': ['skills/sample/icons']} + audit_snapshots(self.repo, self.entry, self.metadata, {'ref': self.old, 'head': new}, '2026-10-31T01:02:03Z', special_review=review) + def test_budget_exempt_allows_known_oversize_file(self): big = 'skills/sample/data/index.json' self.write(big, 'x' * (1024 * 1024 + 50)) diff --git a/scripts/catalog/test_update_diagnostics.py b/scripts/catalog/test_update_diagnostics.py index 7edc257..7be6e28 100644 --- a/scripts/catalog/test_update_diagnostics.py +++ b/scripts/catalog/test_update_diagnostics.py @@ -520,3 +520,96 @@ def test_stale_short_desc_description_locale_review_does_not_pass(case): with pytest.raises(AuditBlocked): audit_snapshots(case.repo, case.entry, case.metadata, {'ref': case.old, 'head': new}, '2026-10-31T01:02:03Z', special_review=review) + + +def test_single_path_install_ignores_unrelated_monorepo_files(case): + # Many files outside the selected path must not exhaust the diagnostic budget. + unrelated = case.repo/'packages/huge' + unrelated.mkdir(parents=True) + for index in range(20001): + (unrelated/f'f{index}.txt').write_text('') + baseline(case) + case.write('skills/sample/scripts/tool.py','new') + rows=findings(case) + assert not any(r['gate']=='independent-static-diagnostics' for r in rows) + delta=next(r for r in rows if r['gate']=='installed-content-delta') + assert delta['evidence']['changedPaths']==['skills/sample/scripts/tool.py'] + + +def test_single_path_install_still_reads_root_and_plugin_evidence(case): + case.write('NOTICE','Possibly applicable root notice') + baseline(case) + case.write('skills/sample/scripts/tool.py','new') + row=next(r for r in findings(case) if r['gate']=='installed-notice-delivery') + assert row['state']=='manual_review' + + +def _malformed_fixture(case, marker): + case.entry['children']=[{'id':'sample','path':'skills/sample'}] + case.write(marker,'---\nname: broken\ndescription: Invalid: YAML\n---\nBody\n') + + +def test_preexisting_malformed_fixture_outside_members_is_info(case): + marker='tools/format-check/tests/bad-skill/SKILL.md' + _malformed_fixture(case, marker) + baseline(case) + case.write('skills/sample/scripts/tool.py','new') + row=next(r for r in findings(case) if r['gate']=='frontmatter-parse') + assert row['state']=='info' and row['origin']=='pre_existing' + assert row['evidence']['insideMemberScope'] is False + + +def test_new_malformed_skill_outside_members_still_blocks(case): + case.entry['children']=[{'id':'sample','path':'skills/sample'}] + case.write('tools/format-check/tests/bad-skill/SKILL.md','---\nname: broken\ndescription: Invalid: YAML\n---\nBody\n') + row=next(r for r in findings(case) if r['gate']=='frontmatter-parse') + assert row['state']=='blocked' and row['origin']=='introduced' + + +def test_preexisting_malformed_skill_inside_member_still_blocks(case): + marker='skills/sample/nested/SKILL.md' + _malformed_fixture(case, marker) + baseline(case) + case.write('skills/sample/scripts/tool.py','new') + row=next(r for r in findings(case) if r['gate']=='frontmatter-parse') + assert row['state']=='blocked' + assert row['evidence']['insideMemberScope'] is True + + +def _behavior_review(old, new, paths): + return {'schemaVersion': 1, 'reviewedBy': 'mashagua', 'reviewedAt': '2026-12-05', + 'notes': 'Read-only behavioral review of the exact delta.', + 'acceptedBehavioralSecurityReview': { + 'fromRef': old, 'toRef': new, + 'reviewDoc': 'docs/reviews/sample-behavior.md', 'reviewedPaths': paths}} + + +def test_bound_behavior_review_covering_all_sensitive_paths_is_info(case): + case.write('skills/sample/scripts/cookie_extract.py','implementation') + new=case.commit() + review=_behavior_review(case.old, new, ['skills/sample/scripts/cookie_extract.py']) + rows=inspect_snapshots(case.repo,case.entry,case.metadata,{'ref':case.old,'head':new},review) + row=next(r for r in rows if r['gate']=='authorization-config-network-review') + assert row['state']=='info' + assert row['evidence']['reviewDoc']=='docs/reviews/sample-behavior.md' + + +def test_behavior_review_missing_a_sensitive_path_stays_manual(case): + case.write('skills/sample/scripts/cookie_extract.py','implementation') + case.write('skills/sample/scripts/auth_safety.py','implementation') + new=case.commit() + review=_behavior_review(case.old, new, ['skills/sample/scripts/cookie_extract.py']) + rows=inspect_snapshots(case.repo,case.entry,case.metadata,{'ref':case.old,'head':new},review) + row=next(r for r in rows if r['gate']=='authorization-config-network-review') + assert row['state']=='manual_review' + assert row['evidence']['unreviewedPaths']==['skills/sample/scripts/auth_safety.py'] + + +def test_behavior_review_for_another_pin_stays_manual(case): + case.write('skills/sample/scripts/cookie_extract.py','implementation') + new=case.commit() + review=_behavior_review(case.old, case.old, ['skills/sample/scripts/cookie_extract.py']) + rows=inspect_snapshots(case.repo,case.entry,case.metadata,{'ref':case.old,'head':new},review) + row=next(r for r in rows if r['gate']=='authorization-config-network-review') + assert row['state']=='manual_review' + assert '不可跨版本继承' in row['evidence']['behavioralReviewError'] diff --git a/scripts/catalog/update_diagnostics.py b/scripts/catalog/update_diagnostics.py index 347aa04..4bf423b 100644 --- a/scripts/catalog/update_diagnostics.py +++ b/scripts/catalog/update_diagnostics.py @@ -35,7 +35,8 @@ def inspect_snapshots(repo, entry, metadata, result, special_review=None): from audit_skill_update import ( git, blob, safe_path, GENERATOR, MAX_FILE_BYTES, MAX_FILES, accept_client_attached_notices, accept_data_only_license_exception, - accept_description_and_locales, _has_locale_copy, AuditBlocked, + accept_description_and_locales, accept_behavioral_security_review, + _has_locale_copy, AuditBlocked, ) old, new = result['ref'], result['head'] review = special_review or {} @@ -45,13 +46,31 @@ def inspect_snapshots(repo, entry, metadata, result, special_review=None): gate=gate, state=state, origin=origin, reason=reason, repair=repair, evidence=evidence or {}, sourceUrl=entry['source']['repoUrl'].removesuffix('.git') + '/compare/' + old + '...' + new)) + # A single-path install only reads its own subtree, root-level files and a + # few named evidence paths; listing an unrelated monorepo would exhaust the + # budget without adding evidence. Whole-tree and collection installs still + # list the complete tree because their scopes or discovery span it. + walk_scope = '' if entry.get('children') else safe_path(entry['source'].get('path', '')) + walk_gov = metadata.get('governance', {}) + walk_extras = sorted({safe_path(p) for p in ( + (walk_gov.get('license') or {}).get('evidencePath'), + walk_gov.get('compliance', {}).get('licenseEvidencePath'), + walk_gov.get('compliance', {}).get('noticePath'), + '.claude-plugin/plugin.json', '.codex-plugin/plugin.json') if p}) def files(ref): found = {} - for record in git(repo, 'ls-tree', '-rz', ref).split(b'\0'): - if record: - meta, path = record.split(b'\t', 1) - mode, kind, oid = meta.decode().split() - found[path.decode()] = (mode, kind, oid) + def collect(*args, skip_trees=False): + for record in git(repo, 'ls-tree', '-z', *args).split(b'\0'): + if record: + meta, path = record.split(b'\t', 1) + mode, kind, oid = meta.decode().split() + if not (skip_trees and kind == 'tree'): + found[path.decode()] = (mode, kind, oid) + if walk_scope: + collect(ref, skip_trees=True) + collect('-r', ref, '--', walk_scope, *walk_extras) + else: + collect('-r', ref) if len(found) > 20000: raise ValueError('独立诊断仓库文件数超预算 / diagnostic tree exceeds budget') return found @@ -225,11 +244,19 @@ def inspect_snapshots(repo, entry, metadata, result, special_review=None): add(path, 'collection-members', 'info' if accepted_members else 'blocked', 'pre_existing' if marker in markers[old] else 'introduced', '登记与解析集合不一致;文件原已存在。 / Declared/discovered mismatch; file already existed.' if marker in markers[old] else '登记与解析集合不一致;本次新增物理文件。 / Declared/discovered mismatch; physical file is newly added.', '逐项审核后同步 children 及两种语言,不把缺项自动准入。 / Review each item and synchronize children and both locales; never auto-admit missing members.') + member_scopes = discovered | declared for path in sorted(markers[new]): if fm_at(new, path) is None: - add(path, 'frontmatter-parse', 'blocked', 'pre_existing' if fm_at(old, path) is None and path in markers[old] else 'introduced', + pre_existing = fm_at(old, path) is None and path in markers[old] + # A historically unparseable SKILL.md outside every member scope + # (for example a deliberately malformed test fixture) is never + # installed and cannot hide a member; a new or in-scope one can. + outside = not any(not scope or path.startswith(scope + '/') for scope in member_scopes) + add(path, 'frontmatter-parse', 'info' if pre_existing and outside else 'blocked', + 'pre_existing' if pre_existing else 'introduced', 'SKILL frontmatter 无法可靠解析。 / SKILL frontmatter cannot be parsed reliably.', - '修正 YAML 后重新发现;这不证明技能是新增加的。 / Fix YAML and rediscover; this does not prove a new skill was added.') + '修正 YAML 后重新发现;这不证明技能是新增加的。 / Fix YAML and rediscover; this does not prove a new skill was added.', + {'insideMemberScope': not outside}) # Descriptions are semantic, not automatic translations. Unchanged historical # English fallbacks are visible but not newly invented failures. for scope in scopes: @@ -318,11 +345,27 @@ def inspect_snapshots(repo, entry, metadata, result, special_review=None): 'physicalRemoved':sorted(old_installed.keys()-new_installed.keys()), 'modeChanges':[p for p in changed_paths if p in old_installed and p in new_installed and old_installed[p][0]!=new_installed[p][0]], 'comparisonComplete':True}) - if sensitive: + behavior_reviewed = set() + behavior_error = None + if sensitive and review.get('acceptedBehavioralSecurityReview'): + try: + if accept_behavioral_security_review(review, old, new): + behavior_reviewed = set(review['acceptedBehavioralSecurityReview']['reviewedPaths']) + except AuditBlocked as error: + behavior_error = str(error) + if sensitive and set(sensitive) <= behavior_reviewed: + add('.', 'authorization-config-network-review', 'info', 'changed', + '授权/凭据/配置/网络相关命名的实现文件发生变化;已由绑定当前旧/新 pin 的只读行为专项复核逐项覆盖。不是安全认证。 / Authorization, credential, configuration or networking paths changed and are each covered by a read-only behavioral review bound to these exact pins. Not a security certification.', + '该复核不跨 pin 继承;后续 pin 的同类变化需重新复核。 / The review does not carry to later pins.', + {'changedPaths': sensitive, + 'reviewDoc': review['acceptedBehavioralSecurityReview'].get('reviewDoc')}) + elif sensitive: add('.', 'authorization-config-network-review', 'manual_review', 'changed', '授权/凭据/配置/网络相关命名的实现文件发生变化;依赖哈希或普通元数据校验不能确认行为边界。这是保守人工复核提示,不是已证实漏洞。 / Implementation paths related by name to authorization, credentials, configuration or networking changed. Dependency hashes or metadata checks cannot establish behavioral bounds. This is a conservative review requirement, not a confirmed vulnerability.', '逐项检查凭据来源/保存、用户同意、网络端点与授权降级;另行记录真实最终 SHA 行为审核,不以依赖专项说明代替。 / Review credential access/storage, user consent, endpoints and authorization fallback; record genuine final-SHA behavioral review, not a dependency-only exception.', - {'changedPaths':sensitive}) + {'changedPaths':sensitive, + 'unreviewedPaths':sorted(set(sensitive) - behavior_reviewed), + **({'behavioralReviewError': behavior_error} if behavior_error else {})}) # Root tooling is reported separately from installed runtime dependencies. old_package, new_package = read(old, 'package.json'), read(new, 'package.json') if old_package != new_package and new_package: