diff --git a/CHANGELOG.d/1099-claude-plugin-supply-chain.md b/CHANGELOG.d/1099-claude-plugin-supply-chain.md index 5575be71..81917a83 100644 --- a/CHANGELOG.d/1099-claude-plugin-supply-chain.md +++ b/CHANGELOG.d/1099-claude-plugin-supply-chain.md @@ -148,10 +148,16 @@ ``helm install`` fails as `claude-plugin-helm-install-command`. ``vercel deploy`` fails as `claude-plugin-vercel-deploy-command`. ``fly deploy`` and ``flyctl deploy`` fail as - `claude-plugin-fly-deploy-command`. Hook comments and + `claude-plugin-fly-deploy-command`. ``aws cloudformation deploy`` + and ``aws deploy create-deployment`` fail as + `claude-plugin-aws-deploy-command`. ``gcloud run|app|functions + deploy`` fails as `claude-plugin-gcloud-deploy-command`. + ``az webapp deploy`` fails as `claude-plugin-az-deploy-command`. + Hook comments and ``echo``/``printf`` lookalikes are not those classes. ``terraform plan``, ``helm list``, - ``vercel ls``, and ``fly status`` + ``vercel ls``, ``fly status``, ``aws s3 ls``, ``gcloud config list``, + and ``az account show`` stay inventory. Hardcoded PATs stay `claude-plugin-github-write-token`. Snippets are command labels, not tokens. diff --git a/appguardrail_core/claude_plugin_detector.py b/appguardrail_core/claude_plugin_detector.py index a2f0d1ed..d915d2c0 100644 --- a/appguardrail_core/claude_plugin_detector.py +++ b/appguardrail_core/claude_plugin_detector.py @@ -25,9 +25,13 @@ deployment-write command findings. Hook or manifest ``terraform apply`` and ``helm install`` fail closed as infra-write command findings. Hook or manifest ``vercel deploy`` and ``fly deploy`` fail closed as -hosted-deploy command findings. Unquoted ``#`` comments and +hosted-deploy command findings. Hook or manifest ``aws cloudformation +deploy``, ``aws deploy create-deployment``, ``gcloud run|app|functions +deploy``, and ``az webapp deploy`` fail closed as cloud-deploy command +findings. Unquoted ``#`` comments and ``echo``/``printf``/``print`` lookalikes are not that class. -``terraform plan``, ``helm list``, ``vercel ls``, and ``fly status`` +``terraform plan``, ``helm list``, ``vercel ls``, ``fly status``, +``aws s3 ls``, ``gcloud config list``, and ``az account show`` stay inventory. Hook or manifest paths into ``~/.netrc``, ``~/.aws/credentials``, GitHub CLI hosts, Docker auth ``config.json``, cookie jars, and @@ -35,7 +39,8 @@ Chrome and Firefox profile stores stay browser-profile findings. Hardcoded PATs stay write-token findings. ``gh issue create``, ``gh pr review``, ``kubectl get``, ``docker ps``, -``terraform plan``, ``helm list``, ``vercel ls``, and ``fly status`` +``terraform plan``, ``helm list``, ``vercel ls``, ``fly status``, +``aws s3 ls``, ``gcloud config list``, and ``az account show`` stay inventory. Skill homoglyph, injection, exfiltration, and placeholder hits reuse #1036 rule identities. Skill, command, or agent text that hides tool use, rewrites @@ -278,6 +283,21 @@ "hosted platform is write authority. Remove the command. " "[CWE-250 - Execution with Unnecessary Privileges]" ) +CLAUDE_PLUGIN_AWS_DEPLOY_COMMAND_MESSAGE: Final = ( + "Claude plugin hook or manifest runs AWS deploy writes. CloudFormation " + "deploy and CodeDeploy create-deployment are write authority. Remove " + "the command. [CWE-269 - Improper Privilege Management]" +) +CLAUDE_PLUGIN_GCLOUD_DEPLOY_COMMAND_MESSAGE: Final = ( + "Claude plugin hook or manifest runs gcloud deploy. Publishing Cloud " + "Run, App Engine, or Functions is write authority. Remove the command. " + "[CWE-250 - Execution with Unnecessary Privileges]" +) +CLAUDE_PLUGIN_AZ_DEPLOY_COMMAND_MESSAGE: Final = ( + "Claude plugin hook or manifest runs az webapp deploy. Publishing an " + "Azure web app is write authority. Remove the command. " + "[CWE-269 - Improper Privilege Management]" +) CLAUDE_PLUGIN_DOCKER_SOCKET_MESSAGE: Final = ( "Claude plugin hook reaches the host Docker socket. Socket access is host " "control, not an image push. Remove the socket bind and keep builds " @@ -413,6 +433,15 @@ ) _VERCEL_DEPLOY_COMMAND = re.compile(r"\bvercel\s+deploy\b", re.IGNORECASE) _FLY_DEPLOY_COMMAND = re.compile(r"\b(?:fly|flyctl)\s+deploy\b", re.IGNORECASE) +_AWS_DEPLOY_COMMAND = re.compile( + r"\baws\s+(?:cloudformation\s+deploy|deploy\s+create-deployment)\b", + re.IGNORECASE, +) +_GCLOUD_DEPLOY_COMMAND = re.compile( + r"\bgcloud\s+(?Prun|app|functions)\s+deploy\b", + re.IGNORECASE, +) +_AZ_DEPLOY_COMMAND = re.compile(r"\baz\s+webapp\s+deploy\b", re.IGNORECASE) _REPORTING_BUILTINS: Final = frozenset( {":", "echo", "false", "print", "printf", "true"} ) @@ -677,7 +706,9 @@ "deployment_write", re.compile( r"\b(?:kubectl\s+apply|terraform\s+apply|helm\s+install|" - r"vercel\s+deploy|fly(?:ctl)?\s+deploy|docker\s+push)\b", + r"vercel\s+deploy|fly(?:ctl)?\s+deploy|docker\s+push|" + r"aws\s+(?:cloudformation\s+deploy|deploy\s+create-deployment)|" + r"gcloud\s+(?:run|app|functions)\s+deploy|az\s+webapp\s+deploy)\b", re.IGNORECASE, ), ), @@ -933,6 +964,9 @@ def inspect_claude_plugin_file( hits.extend(_helm_install_command_hits(content, manifest=manifest)) hits.extend(_vercel_deploy_command_hits(content, manifest=manifest)) hits.extend(_fly_deploy_command_hits(content, manifest=manifest)) + hits.extend(_aws_deploy_command_hits(content, manifest=manifest)) + hits.extend(_gcloud_deploy_command_hits(content, manifest=manifest)) + hits.extend(_az_deploy_command_hits(content, manifest=manifest)) hits.extend(_docker_socket_hits(content)) hits.extend(_browser_profile_hits(content)) hits.extend(_credential_store_hits(content)) @@ -2421,6 +2455,65 @@ def _fly_deploy_command_hits( return () +def _aws_deploy_command_hits( + content: str, *, manifest: bool = False +) -> tuple[PluginHit, ...]: + """Return AWS deploy-write findings with a command label, not secrets.""" + for source, first_line in _hosted_command_sources(content, manifest=manifest): + match = _executable_command_match(source, _AWS_DEPLOY_COMMAND) + if match is None: + continue + snippet = " ".join(match.group(0).lower().split()) + return ( + PluginHit( + rule_id="claude-plugin-aws-deploy-command", + line=first_line + source[: match.start()].count("\n"), + snippet=snippet, + message=CLAUDE_PLUGIN_AWS_DEPLOY_COMMAND_MESSAGE, + ), + ) + return () + + +def _gcloud_deploy_command_hits( + content: str, *, manifest: bool = False +) -> tuple[PluginHit, ...]: + """Return gcloud deploy findings with a service-qualified command label.""" + for source, first_line in _hosted_command_sources(content, manifest=manifest): + match = _executable_command_match(source, _GCLOUD_DEPLOY_COMMAND) + if match is None: + continue + service = match.group("service").lower() + return ( + PluginHit( + rule_id="claude-plugin-gcloud-deploy-command", + line=first_line + source[: match.start()].count("\n"), + snippet="gcloud " + service + " deploy", + message=CLAUDE_PLUGIN_GCLOUD_DEPLOY_COMMAND_MESSAGE, + ), + ) + return () + + +def _az_deploy_command_hits( + content: str, *, manifest: bool = False +) -> tuple[PluginHit, ...]: + """Return Azure webapp deploy findings with a command label, not names.""" + for source, first_line in _hosted_command_sources(content, manifest=manifest): + match = _executable_command_match(source, _AZ_DEPLOY_COMMAND) + if match is None: + continue + return ( + PluginHit( + rule_id="claude-plugin-az-deploy-command", + line=first_line + source[: match.start()].count("\n"), + snippet="az webapp deploy", + message=CLAUDE_PLUGIN_AZ_DEPLOY_COMMAND_MESSAGE, + ), + ) + return () + + def _dynamic_eval_hits(content: str) -> tuple[PluginHit, ...]: """Return findings for eval/exec/compile/Function on hook surfaces.""" match = _DYNAMIC_EVAL.search(content) diff --git a/docs/TRACEABILITY.md b/docs/TRACEABILITY.md index b98dabdc..5b14a3d6 100644 --- a/docs/TRACEABILITY.md +++ b/docs/TRACEABILITY.md @@ -22,7 +22,7 @@ | structural Semgrep-style `pattern:` execution by lightweight engine | built-in scanner | not implemented unless a real structural matcher is added; fixtures are not execution | | GitHub Actions transport-only polling loop (#1087, #938 vertical slice) | owned by PR #1088 / issue #1087; YAML rules and RED precision contracts | mapped-family only; this successor does not ship or close the detector | | Password/database-url/auth-comment precision and test-file context (#1106) | existing `_scan_file` rules `hardcoded-password`, `hardcoded-database-url`, `todo-skip-auth`, `_finding_context` | implemented-branch regression lock | -| Claude plugin marketplace/package supply chain (#1099) | `claude-plugin-floating-git-ref`, `claude-plugin-provider-secret`, `claude-plugin-pipe-to-shell`, `claude-plugin-unsigned-executable-download` (hooks and package.json lifecycle scripts), `claude-plugin-unpinned-package-install`, `claude-plugin-undeclared-executable`, `claude-plugin-symlink-escape`, `claude-plugin-archive-path-traversal`, `claude-plugin-unadmitted-submodule`, `claude-plugin-duplicate-json-member`, `claude-plugin-nonstandard-json-constant`, `claude-plugin-malformed-utf8`, `claude-plugin-inconsistent-normalized-name`, `claude-plugin-vendored-scope-undeclared`, `claude-plugin-conflicting-identity`, `claude-plugin-unbounded-mcp`, `claude-plugin-license-missing`, `claude-plugin-license-mismatch`, `claude-plugin-dynamic-eval`, `claude-plugin-hidden-undeclared-executable`, `claude-plugin-concealed-identity`, `claude-plugin-oversized-package`, `claude-plugin-source-mismatch`, `claude-plugin-github-write-token`, `claude-plugin-docker-socket`, `claude-plugin-browser-profile-access`, `claude-plugin-deceptive-description`, `claude-plugin-secret-to-network`, `claude-plugin-secret-to-prompt`, `claude-plugin-secret-to-mcp`, `claude-plugin-hide-actions-directive` / `claude-plugin-self-modify-directive` / `claude-plugin-goal-escalation-directive`, `claude-plugin-setuid-executable` / `claude-plugin-world-writable-executable`, `claude-plugin-decompression-bomb`, reused #1036 `skill-name-homoglyph-confusable` / `skill-manifest-prompt-injection-payload` / `skill-doc-exfiltration-endpoint-directive` / `skill-placeholder-template-unresolved` on plugin skill/agent/command surfaces, deterministic scan receipt with catalog repository/SHA bind, SARIF 2.1.0 `sarif_sha256` bound to the same finding rule_ids, `policy_provenance` bound to the AppGuardrail release plus exact scan-policy digest, and `sbom_sha256` of a deterministic CycloneDX 1.5 document, `claude-plugin-checksum-mismatch` when a first-party SHA256SUMS or sibling `*.sha256` disagrees with bytes on disk, `claude-plugin-unsigned-checksum` when checksum digest rows have no sibling Cosign/GPG signature file, `claude-plugin-excessive-path-depth` when a materialized file or archive member nests past 32 path components, `claude-plugin-github-merge-command` for hook or manifest `gh pr merge`, `claude-plugin-github-release-command` for `gh release create|upload|delete|edit`, `claude-plugin-kubectl-apply-command` for hook or manifest `kubectl apply`, `claude-plugin-docker-push-command` for `docker push`, `claude-plugin-terraform-apply-command` for `terraform apply`, `claude-plugin-helm-install-command` for `helm install`, `claude-plugin-vercel-deploy-command` for hook or manifest `vercel deploy`, `claude-plugin-fly-deploy-command` for `fly deploy`, `claude-plugin-credential-store-access` for host cookie and token stores that are not browser profiles, fail-closed receipt verification | implemented-branch | +| Claude plugin marketplace/package supply chain (#1099) | `claude-plugin-floating-git-ref`, `claude-plugin-provider-secret`, `claude-plugin-pipe-to-shell`, `claude-plugin-unsigned-executable-download` (hooks and package.json lifecycle scripts), `claude-plugin-unpinned-package-install`, `claude-plugin-undeclared-executable`, `claude-plugin-symlink-escape`, `claude-plugin-archive-path-traversal`, `claude-plugin-unadmitted-submodule`, `claude-plugin-duplicate-json-member`, `claude-plugin-nonstandard-json-constant`, `claude-plugin-malformed-utf8`, `claude-plugin-inconsistent-normalized-name`, `claude-plugin-vendored-scope-undeclared`, `claude-plugin-conflicting-identity`, `claude-plugin-unbounded-mcp`, `claude-plugin-license-missing`, `claude-plugin-license-mismatch`, `claude-plugin-dynamic-eval`, `claude-plugin-hidden-undeclared-executable`, `claude-plugin-concealed-identity`, `claude-plugin-oversized-package`, `claude-plugin-source-mismatch`, `claude-plugin-github-write-token`, `claude-plugin-docker-socket`, `claude-plugin-browser-profile-access`, `claude-plugin-deceptive-description`, `claude-plugin-secret-to-network`, `claude-plugin-secret-to-prompt`, `claude-plugin-secret-to-mcp`, `claude-plugin-hide-actions-directive` / `claude-plugin-self-modify-directive` / `claude-plugin-goal-escalation-directive`, `claude-plugin-setuid-executable` / `claude-plugin-world-writable-executable`, `claude-plugin-decompression-bomb`, reused #1036 `skill-name-homoglyph-confusable` / `skill-manifest-prompt-injection-payload` / `skill-doc-exfiltration-endpoint-directive` / `skill-placeholder-template-unresolved` on plugin skill/agent/command surfaces, deterministic scan receipt with catalog repository/SHA bind, SARIF 2.1.0 `sarif_sha256` bound to the same finding rule_ids, `policy_provenance` bound to the AppGuardrail release plus exact scan-policy digest, and `sbom_sha256` of a deterministic CycloneDX 1.5 document, `claude-plugin-checksum-mismatch` when a first-party SHA256SUMS or sibling `*.sha256` disagrees with bytes on disk, `claude-plugin-unsigned-checksum` when checksum digest rows have no sibling Cosign/GPG signature file, `claude-plugin-excessive-path-depth` when a materialized file or archive member nests past 32 path components, `claude-plugin-github-merge-command` for hook or manifest `gh pr merge`, `claude-plugin-github-release-command` for `gh release create|upload|delete|edit`, `claude-plugin-kubectl-apply-command` for hook or manifest `kubectl apply`, `claude-plugin-docker-push-command` for `docker push`, `claude-plugin-terraform-apply-command` for `terraform apply`, `claude-plugin-helm-install-command` for `helm install`, `claude-plugin-vercel-deploy-command` for hook or manifest `vercel deploy`, `claude-plugin-fly-deploy-command` for `fly deploy`, `claude-plugin-aws-deploy-command` for hook or manifest `aws cloudformation deploy`, `claude-plugin-gcloud-deploy-command` for `gcloud run deploy`, `claude-plugin-az-deploy-command` for `az webapp deploy`, `claude-plugin-credential-store-access` for host cookie and token stores that are not browser profiles, fail-closed receipt verification | implemented-branch | | Orphaned GitHub Actions registry identities (#929) | owned by PR #966 / issue #929; live registry DAST | mapped-family only; this successor does not ship or close the detector | | Org security-failure CI tickets without copied vuln evidence | documented non-detectable family | snapshot in `tests/fixtures/cwl-security-issue-inventory.json` | diff --git a/docs/sast-dast-rule-research.md b/docs/sast-dast-rule-research.md index 5b460923..f5f0c68c 100644 --- a/docs/sast-dast-rule-research.md +++ b/docs/sast-dast-rule-research.md @@ -106,14 +106,18 @@ files being scanned, then applies the union of relevant checks. Examples: `claude-plugin-terraform-apply-command` for ``terraform apply``, `claude-plugin-helm-install-command` for ``helm install``, `claude-plugin-vercel-deploy-command` for ``vercel deploy``, - `claude-plugin-fly-deploy-command` for ``fly deploy``, and + `claude-plugin-fly-deploy-command` for ``fly deploy``, + `claude-plugin-aws-deploy-command` for ``aws cloudformation deploy``, + `claude-plugin-gcloud-deploy-command` for ``gcloud run deploy``, + `claude-plugin-az-deploy-command` for ``az webapp deploy``, and `claude-plugin-credential-store-access` for host ``~/.netrc``, ``~/.aws/credentials``, GitHub CLI hosts, Docker auth, cookie jars, and SSH private keys. Chrome/Firefox profile stores stay `claude-plugin-browser-profile-access`. Hardcoded PATs stay `claude-plugin-github-write-token`. ``gh issue create``, ``gh pr review``, ``kubectl get``, ``docker ps``, ``terraform plan``, ``helm list``, - ``vercel ls``, and ``fly status`` stay inventory. + ``vercel ls``, ``fly status``, ``aws s3 ls``, ``gcloud config list``, + and ``az account show`` stay inventory. - Mapped, not owned here: GitHub Actions transport-only poll loops (#1087, PR #1088) and orphaned workflow registry DAST (#929, PR #966). - `tool-execute-parameters-passthrough`: Strix-observed dynamic tool execution diff --git a/tests/test_claude_plugin_cloud_deploy.py b/tests/test_claude_plugin_cloud_deploy.py new file mode 100644 index 00000000..608772b7 --- /dev/null +++ b/tests/test_claude_plugin_cloud_deploy.py @@ -0,0 +1,261 @@ +"""Hook aws/gcloud/az deploy writes fail closed; reads stay inventory.""" + +from __future__ import annotations + +import json +from pathlib import Path + +from appguardrail_core.claude_plugin_detector import ( + _collect_plugin_hits, + build_claude_plugin_scan_receipt, + inspect_claude_plugin_file, + inventory_claude_plugin_capabilities, +) + + +_PINNED_COMMIT = "a727be1c7bd6064419b6f60d71993a19198adc17" +_AWS_RULE = "claude-plugin-aws-deploy-command" +_GCLOUD_RULE = "claude-plugin-gcloud-deploy-command" +_AZ_RULE = "claude-plugin-az-deploy-command" +_VERCEL_RULE = "claude-plugin-vercel-deploy-command" +_SECRET = "sk-cloud-must-not-leak" +_BIDI = "\u202e" +_THIS_CLASS = frozenset({_AWS_RULE, _GCLOUD_RULE, _AZ_RULE}) + + +def _write_json(path: Path, payload: dict) -> None: + """Write one JSON document under ``path``.""" + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8") + + +def _licensed_plugin(root: Path, hook_body: str = "#!/bin/sh\necho hello\n") -> Path: + """Write a pinned licensed plugin with one declared shell hook.""" + _write_json( + root / ".claude-plugin" / "plugin.json", + { + "name": "safe-plugin", + "version": "1.0.0", + "source": { + "source": "github", + "repo": "example/safe-plugin", + "ref": _PINNED_COMMIT, + }, + "hooks": {"PreToolUse": [{"command": "hooks/session.sh"}]}, + }, + ) + hook = root / "hooks" / "session.sh" + hook.parent.mkdir(parents=True, exist_ok=True) + hook.write_text(hook_body, encoding="utf-8") + hook.chmod(0o755) + (root / "LICENSE").write_text("MIT\n", encoding="utf-8") + return root + + +def _hits(root: Path, rule_id: str): + """Return receipt-path hits for one rule identity.""" + return [hit for hit in _collect_plugin_hits(root) if hit.rule_id == rule_id] + + +def test_hook_aws_cloudformation_deploy_fails_admission(tmp_path: Path) -> None: + """``aws cloudformation deploy`` on a hook is cloud write authority.""" + root = _licensed_plugin( + tmp_path, "#!/bin/sh\naws cloudformation deploy --stack-name app\n" + ) + hits = _hits(root, _AWS_RULE) + receipt = build_claude_plugin_scan_receipt(root) + inventory = inventory_claude_plugin_capabilities(root) + + assert hits + assert all(hit.snippet == "aws cloudformation deploy" for hit in hits) + assert receipt.scan_result == "fail" + assert _AWS_RULE in receipt.finding_summary + assert _GCLOUD_RULE not in receipt.finding_summary + assert inventory["deployment_write"] is True + + +def test_hook_gcloud_run_deploy_fails_admission(tmp_path: Path) -> None: + """``gcloud run deploy`` on a hook is cloud write authority.""" + root = _licensed_plugin(tmp_path, "#!/bin/sh\ngcloud run deploy app --image img\n") + hits = _hits(root, _GCLOUD_RULE) + receipt = build_claude_plugin_scan_receipt(root) + + assert hits + assert all(hit.snippet == "gcloud run deploy" for hit in hits) + assert receipt.scan_result == "fail" + assert _GCLOUD_RULE in receipt.finding_summary + assert _AWS_RULE not in receipt.finding_summary + + +def test_hook_az_webapp_deploy_fails_admission(tmp_path: Path) -> None: + """``az webapp deploy`` on a hook is cloud write authority.""" + root = _licensed_plugin(tmp_path, "#!/bin/sh\naz webapp deploy --name app\n") + hits = _hits(root, _AZ_RULE) + receipt = build_claude_plugin_scan_receipt(root) + + assert hits + assert all(hit.snippet == "az webapp deploy" for hit in hits) + assert receipt.scan_result == "fail" + assert _AZ_RULE in receipt.finding_summary + + +def test_aws_s3_ls_and_gcloud_config_stay_inventory(tmp_path: Path) -> None: + """Read-only cloud CLIs stay inventory, not this class.""" + root = _licensed_plugin( + tmp_path, + "#!/bin/sh\naws s3 ls\ngcloud config list\naz account show\n", + ) + receipt = build_claude_plugin_scan_receipt(root) + + assert _THIS_CLASS.isdisjoint(receipt.finding_summary) + assert receipt.scan_result == "pass" + + +def test_comment_and_echo_cloud_deploy_are_not_this_class(tmp_path: Path) -> None: + """Unquoted comments and echo lookalikes are not executable cloud deploys.""" + root = _licensed_plugin( + tmp_path, + '#!/bin/sh\n# aws cloudformation deploy\necho "gcloud run deploy"\n', + ) + receipt = build_claude_plugin_scan_receipt(root) + assert _THIS_CLASS.isdisjoint(receipt.finding_summary) + assert receipt.scan_result == "pass" + + +def test_readme_gcloud_deploy_is_not_this_class(tmp_path: Path) -> None: + """README cloud-deploy wording is repository guidance, not a hook command.""" + root = _licensed_plugin(tmp_path) + (root / "README.md").write_text("gcloud run deploy app --image img\n", encoding="utf-8") + receipt = build_claude_plugin_scan_receipt(root) + inventory = inventory_claude_plugin_capabilities(root) + + assert _hits(root, _GCLOUD_RULE) == [] + assert receipt.scan_result == "pass" + assert inventory["deployment_write"] is True + + +def test_three_clouds_on_one_hook_are_distinct_findings(tmp_path: Path) -> None: + """One hook can fail closed on aws, gcloud, and az deploy writes.""" + root = _licensed_plugin( + tmp_path, + "#!/bin/sh\n" + "aws cloudformation deploy --stack-name app\n" + "gcloud app deploy\n" + "az webapp deploy --name app\n", + ) + receipt = build_claude_plugin_scan_receipt(root) + assert _hits(root, _AWS_RULE) + assert _hits(root, _GCLOUD_RULE) + assert _hits(root, _AZ_RULE) + assert receipt.scan_result == "fail" + assert _VERCEL_RULE not in receipt.finding_summary + + +def test_aws_deploy_create_deployment_fails_admission() -> None: + """``aws deploy create-deployment`` is the same aws-deploy class.""" + body = "#!/bin/sh\naws deploy create-deployment --application-name app\n" + hits = inspect_claude_plugin_file("session.sh", "hooks/session.sh", body) + assert any( + hit.rule_id == _AWS_RULE and hit.snippet == "aws deploy create-deployment" + for hit in hits + ) + + +def test_gcloud_functions_deploy_canonicalizes_snippet() -> None: + """``gcloud functions deploy`` keeps the service token in the snippet.""" + body = "#!/bin/sh\ngcloud functions deploy fn --runtime python312\n" + hits = inspect_claude_plugin_file("session.sh", "hooks/session.sh", body) + assert any( + hit.rule_id == _GCLOUD_RULE and hit.snippet == "gcloud functions deploy" + for hit in hits + ) + + +def test_snippets_are_command_labels_not_secrets(tmp_path: Path) -> None: + """Snippets name the CLI command and omit secrets and bidi.""" + body = f"#!/bin/sh\naws cloudformation deploy --parameter-overrides t={_SECRET}{_BIDI}\n" + root = _licensed_plugin(tmp_path, body) + hits = inspect_claude_plugin_file("session.sh", "hooks/session.sh", body) + aws_hits = [hit for hit in hits if hit.rule_id == _AWS_RULE] + payload = json.dumps(build_claude_plugin_scan_receipt(root).as_dict()) + + assert aws_hits + for hit in aws_hits: + assert hit.snippet == "aws cloudformation deploy" + assert _SECRET not in hit.snippet + assert _BIDI not in hit.snippet + assert _SECRET not in hit.message + assert _SECRET not in payload + assert _BIDI not in payload + + +def test_plugin_manifest_az_webapp_deploy_fails_admission(tmp_path: Path) -> None: + """A plugin.json command string that deploys to Azure is the az class.""" + root = _licensed_plugin(tmp_path) + manifest = json.loads( + (root / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8") + ) + manifest["hooks"] = { + "PostToolUse": [{"command": "az webapp deploy --name app"}], + } + _write_json(root / ".claude-plugin" / "plugin.json", manifest) + receipt = build_claude_plugin_scan_receipt(root) + assert _hits(root, _AZ_RULE) + assert receipt.scan_result == "fail" + + +def test_vercel_deploy_without_cloud_stays_the_vercel_class() -> None: + """Hosted vercel deploy without aws/gcloud/az stays the vercel class.""" + hits = inspect_claude_plugin_file( + "session.sh", + "hooks/session.sh", + "#!/bin/sh\nvercel deploy --prod\n", + ) + rule_ids = {hit.rule_id for hit in hits} + assert _VERCEL_RULE in rule_ids + assert _THIS_CLASS.isdisjoint(rule_ids) + + +def test_manifest_cloud_prose_and_reporting_commands_are_not_this_class( + tmp_path: Path, +) -> None: + """Manifest prose and reporting-only values are not cloud deploy writes.""" + root = _licensed_plugin(tmp_path) + manifest_path = root / ".claude-plugin" / "plugin.json" + manifest = json.loads(manifest_path.read_text(encoding="utf-8")) + manifest["description"] = "operators may later run gcloud run deploy" + manifest["hooks"] = { + "PostToolUse": [ + {"command": "hooks/session.sh"}, + {"command": 'echo "aws cloudformation deploy"'}, + {"command": "printf '%s\\n' 'az webapp deploy'"}, + ], + } + _write_json(manifest_path, manifest) + + receipt = build_claude_plugin_scan_receipt(root) + + assert _THIS_CLASS.isdisjoint(receipt.finding_summary) + assert receipt.scan_result == "pass" + + +def test_manifest_reporting_command_does_not_hide_later_cloud_deploy( + tmp_path: Path, +) -> None: + """A later structural command value still exposes a real cloud deploy.""" + root = _licensed_plugin(tmp_path) + manifest_path = root / ".claude-plugin" / "plugin.json" + manifest = json.loads(manifest_path.read_text(encoding="utf-8")) + manifest["hooks"] = { + "PostToolUse": [ + {"command": 'echo "gcloud run deploy"'}, + {"command": "aws cloudformation deploy --stack-name app"}, + ], + } + _write_json(manifest_path, manifest) + + receipt = build_claude_plugin_scan_receipt(root) + + assert _GCLOUD_RULE not in receipt.finding_summary + assert _AWS_RULE in receipt.finding_summary + assert receipt.scan_result == "fail"