From 9de5c3ea1bf500e79c529c99ca820d4719b58edd Mon Sep 17 00:00:00 2001 From: Kavya Katal Date: Wed, 4 Nov 2026 12:02:46 +0530 Subject: [PATCH 1/3] fix(security): route tracker imports through vetted issue creation --- .../skills/issue-import-from-md/SKILL.md | 52 +++-- .../skills/issue-import-from-md/reference.md | 2 +- .../skills/issue-import-from-pr/SKILL.md | 41 +++- .../skills/issue-import-from-pr/reference.md | 2 +- .../skills/issue-import/apply.md | 38 +++- plugins/magpie-setup/skills/setup/config.md | 9 + .../tools/vetted-ops/README.md | 9 +- .../tools/vetted-ops/src/vetted_ops/cli.py | 2 + .../tools/vetted-ops/src/vetted_ops/ops.py | 62 ++++++ .../src/vetted_ops/tracker_backends.py | 1 + tools/vetted-ops/README.md | 9 +- tools/vetted-ops/src/vetted_ops/cli.py | 2 + tools/vetted-ops/src/vetted_ops/ops.py | 62 ++++++ .../src/vetted_ops/tracker_backends.py | 1 + .../tests/test_issue_create_labeled.py | 184 ++++++++++++++++++ .../vetted-ops/tests/test_tracker_backends.py | 1 + tools/vetted-ops/tests/test_vetted_ops.py | 6 + 17 files changed, 435 insertions(+), 48 deletions(-) create mode 100644 tools/vetted-ops/tests/test_issue_create_labeled.py diff --git a/plugins/magpie-security/skills/issue-import-from-md/SKILL.md b/plugins/magpie-security/skills/issue-import-from-md/SKILL.md index 0938e6892..c60714a41 100644 --- a/plugins/magpie-security/skills/issue-import-from-md/SKILL.md +++ b/plugins/magpie-security/skills/issue-import-from-md/SKILL.md @@ -25,9 +25,9 @@ when_to_use: | anchor the import on (`security-issue-import-from-pr`). argument-hint: "[path-to-markdown-file]" capability: capability:intake -surface_hash: sha256:e2437e84cdf98aa5 +surface_hash: sha256:b741b2de80b78093 license: Apache-2.0 -measured_tokens: 6282 +measured_tokens: 6243 --- + +The configured skill is `security-issue-import-from-md`. +All configuration and override-anchor checks pass. +Tracker backend: `github`. + +Saved caller grants include `rollup-append` and +`issue-create-labeled`. + +The saved label allowlist contains `needs triage` +but lacks `security issue`. + +The proposed diff adds only `security issue`. +The operator explicitly declined the change. +The saved policy remains unchanged. + +The skill must not be stamped clean. diff --git a/tools/skill-evals/evals/setup/step-reconcile-confirmation/fixtures/output-spec.md b/tools/skill-evals/evals/setup/step-reconcile-confirmation/fixtures/output-spec.md index ed8818bf5..d96967010 100644 --- a/tools/skill-evals/evals/setup/step-reconcile-confirmation/fixtures/output-spec.md +++ b/tools/skill-evals/evals/setup/step-reconcile-confirmation/fixtures/output-spec.md @@ -7,7 +7,7 @@ Return ONLY valid JSON with these fields: - `decision`: `"declined"` or `"confirmed"` - `policy_verified`: boolean; true only when the saved policy has been - re-read and all required grants are present. + re-read and all required grants and applicable GitHub import labels are present. - `policy_changed`: boolean; whether the saved policy actually changed. - `stamp_written`: boolean; whether this skill was stamped clean. diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/expected.json b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/expected.json index 9e6886291..46d67ca1d 100644 --- a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/expected.json +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/expected.json @@ -4,19 +4,19 @@ "kind": "policy", "skill": "security-issue-import", "override_file": null, - "detail": "Missing caller security-issue-import in .apache-magpie-overrides/tools/vetted-ops/config.toml; propose issue-list-with-bodies and rollup-append." + "detail": "Missing caller security-issue-import in .apache-magpie-overrides/tools/vetted-ops/config.toml; propose issue-list-with-bodies and rollup-append. Also require issue-create-labeled." }, { "kind": "policy", "skill": "security-issue-import-from-md", "override_file": null, - "detail": "Existing caller security-issue-import-from-md lacks rollup-append; preserve its issue-view grant." + "detail": "Existing caller security-issue-import-from-md lacks rollup-append; preserve its issue-view grant. Also require issue-create-labeled." }, { "kind": "policy", "skill": "security-issue-import-from-pr", "override_file": null, - "detail": "Existing caller security-issue-import-from-pr lacks pr-view-with-body; preserve its rollup-append grant." + "detail": "Existing caller security-issue-import-from-pr lacks pr-view-with-body; preserve its rollup-append grant. Also require issue-create-labeled." } ], "unchecked": [], diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/report.md b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/report.md index 419c62fa3..af9a48dd9 100644 --- a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/report.md +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-4-import-policy-grants/report.md @@ -30,8 +30,12 @@ Tracker backend: `github`. The framework's vetted-ops README provides this example: [callers] -"security-issue-import" = ["issue-list-with-bodies", "rollup-append"] -"security-issue-import-from-md" = ["rollup-append"] -"security-issue-import-from-pr" = ["pr-view-with-body", "rollup-append"] +"security-issue-import" = ["issue-list-with-bodies", "rollup-append", "issue-create-labeled"] +"security-issue-import-from-md" = ["rollup-append", "issue-create-labeled"] +"security-issue-import-from-pr" = ["pr-view-with-body", "rollup-append", "issue-create-labeled"] + +The PR importer is configured for `scope:core` and a merged PR. +The existing `[values] labels` contains `needs triage`, `security issue`, +`scope:core`, and `pr merged`; all applicable required labels are approved. No policy changes have been confirmed during this run. diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/expected.json b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/expected.json index dbc075b62..c7725e2ee 100644 --- a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/expected.json +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/expected.json @@ -4,7 +4,7 @@ "kind": "policy", "skill": "security-issue-import-from-md", "override_file": null, - "detail": "Caller security-issue-import-from-md lacks rollup-append. The operator declined the grant; preserve issue-view and leave the policy finding unresolved." + "detail": "Caller security-issue-import-from-md lacks rollup-append and issue-create-labeled. The operator declined the grants; preserve issue-view and leave the policy finding unresolved." } ], "unchecked": [], diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/report.md b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/report.md index 5007d4473..81c7f8386 100644 --- a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/report.md +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-5-declined-import-grant/report.md @@ -16,10 +16,11 @@ The policy is valid TOML. Its caller entry is: "security-issue-import-from-md" = ["issue-view"] The vetted-ops README configuration example contains: - "security-issue-import-from-md" = ["rollup-append"] + "security-issue-import-from-md" = ["rollup-append", "issue-create-labeled"] During confirmation, the operator declined the proposal -to add `rollup-append` to this caller. +to add `rollup-append` and `issue-create-labeled` to this caller. The policy remains unchanged. +Its label allowlist already contains `needs triage` and `security issue`. The current reconciliation stamp contains no entry for this skill. diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-6-upgrade-old-import-policy/expected.json b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-6-upgrade-old-import-policy/expected.json new file mode 100644 index 000000000..faf857266 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-6-upgrade-old-import-policy/expected.json @@ -0,0 +1,12 @@ +{ + "proposals": [ + { + "kind": "policy", + "skill": "security-issue-import", + "override_file": null, + "detail": "Existing caller lacks issue-create-labeled and the label allowlist lacks security issue. Do not stamp clean." + } + ], + "unchecked": [], + "stamp_written": false +} diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-6-upgrade-old-import-policy/report.md b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-6-upgrade-old-import-policy/report.md new file mode 100644 index 000000000..e03806657 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-6-upgrade-old-import-policy/report.md @@ -0,0 +1,25 @@ + + +Install method: `git-branch` (pinned snapshot). + +The configured skill `security-issue-import` is in scope. +Required configuration and override-anchor checks pass. + +Existing stamp hash: `sha256:079bd7106b8b78ef`. +Current skill hash: `sha256:3210ccb4763beb17`. + +Tracker backend: `github`. + +Existing policy: + + [callers] + "security-issue-import" = ["issue-list-with-bodies", "rollup-append"] + + [values] + labels = ["needs triage"] + +The new requirements include `issue-create-labeled` and the +`security issue` label. + +No policy changes have been approved or applied. diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-7-missing-intake-label/expected.json b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-7-missing-intake-label/expected.json new file mode 100644 index 000000000..daf9bc833 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-7-missing-intake-label/expected.json @@ -0,0 +1,12 @@ +{ + "proposals": [ + { + "kind": "policy", + "skill": "security-issue-import-from-md", + "override_file": null, + "detail": "Caller grants are complete, but security issue is missing from the label allowlist. Propose the missing label; do not stamp clean." + } + ], + "unchecked": [], + "stamp_written": false +} diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-7-missing-intake-label/report.md b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-7-missing-intake-label/report.md new file mode 100644 index 000000000..1c22d8370 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-7-missing-intake-label/report.md @@ -0,0 +1,20 @@ + + +Install method: `git-branch` (pinned snapshot). + +The configured skill `security-issue-import-from-md` is in scope. +All configuration and override-anchor checks pass. +Tracker backend: `github`. + +Existing policy: + + [callers] + "security-issue-import-from-md" = ["rollup-append", "issue-create-labeled"] + + [values] + labels = ["needs triage"] + +All required caller grants exist. +The required `security issue` label is missing. +No policy change has been approved or applied. diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-8-missing-pr-scope-label/expected.json b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-8-missing-pr-scope-label/expected.json new file mode 100644 index 000000000..48c7c6003 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-8-missing-pr-scope-label/expected.json @@ -0,0 +1,12 @@ +{ + "proposals": [ + { + "kind": "policy", + "skill": "security-issue-import-from-pr", + "override_file": null, + "detail": "Caller grants are complete, but scope:core is missing from the label allowlist. Propose only that label; do not stamp clean." + } + ], + "unchecked": [], + "stamp_written": false +} diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-8-missing-pr-scope-label/report.md b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-8-missing-pr-scope-label/report.md new file mode 100644 index 000000000..358099224 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-8-missing-pr-scope-label/report.md @@ -0,0 +1,23 @@ + + +Install method: `git-branch` (pinned snapshot). + +The configured skill `security-issue-import-from-pr` is in scope. +All configuration and override-anchor checks pass. +Tracker backend: `github`. + +The configured PR importer requires these labels: +`security issue`, `scope:core`, `pr merged`. + +Existing policy: + + [callers] + "security-issue-import-from-pr" = ["pr-view-with-body", "rollup-append", "issue-create-labeled"] + + [values] + labels = ["security issue", "pr merged"] + +All caller grants exist. +The required project-specific `scope:core` label is missing. +No policy change has been approved or applied. diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-9-missing-pr-state-label/expected.json b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-9-missing-pr-state-label/expected.json new file mode 100644 index 000000000..8f566ec53 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-9-missing-pr-state-label/expected.json @@ -0,0 +1,12 @@ +{ + "proposals": [ + { + "kind": "policy", + "skill": "security-issue-import-from-pr", + "override_file": null, + "detail": "Caller grants are complete, but pr merged is missing from the label allowlist. Propose only that label; do not stamp clean." + } + ], + "unchecked": [], + "stamp_written": false +} diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-9-missing-pr-state-label/report.md b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-9-missing-pr-state-label/report.md new file mode 100644 index 000000000..655541722 --- /dev/null +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/case-9-missing-pr-state-label/report.md @@ -0,0 +1,23 @@ + + +Install method: `git-branch` (pinned snapshot). + +The configured skill `security-issue-import-from-pr` is in scope. +All configuration and override-anchor checks pass. +Tracker backend: `github`. + +The configured PR importer requires these labels: +`security issue`, `scope:core`, `pr merged`. + +Existing policy: + + [callers] + "security-issue-import-from-pr" = ["pr-view-with-body", "rollup-append", "issue-create-labeled"] + + [values] + labels = ["security issue", "scope:core"] + +All caller grants exist. +The required project-specific `pr merged` label is missing. +No policy change has been approved or applied. diff --git a/tools/skill-evals/evals/setup/step-reconcile/fixtures/output-spec.md b/tools/skill-evals/evals/setup/step-reconcile/fixtures/output-spec.md index 6bfb5a1db..90272165f 100644 --- a/tools/skill-evals/evals/setup/step-reconcile/fixtures/output-spec.md +++ b/tools/skill-evals/evals/setup/step-reconcile/fixtures/output-spec.md @@ -12,7 +12,7 @@ Return ONLY valid JSON with this structure: "kind": "reanchor" | "config" | "policy", "skill": "", "override_file": "", - "detail": "" + "detail": "" } ], "unchecked": ["anchor-resolution" | "requires_config" | "policy-grants"], @@ -24,16 +24,19 @@ Return ONLY valid JSON with this structure: when an override's referenced anchor no longer resolves in the target skill's current `SKILL.md`; `kind: "config"` when a `requires_config` entry does not resolve through the lookup chain; `kind: "policy"` when - an applicable import caller or required operation is absent from an + an applicable import caller, required operation, or required label is absent from an existing vetted-ops policy. Use the caller name as `skill` and name - the exact missing operations in `detail`. Empty when all applicable + the exact missing operations or labels in `detail`. + Policy findings may group missing grants and labels for the same caller. + Required labels include intake labels and the configured PR scope, PR-state, and security-marker labels, as applicable. + Empty when all applicable checks pass cleanly for everything in scope. - `unchecked` — which check(s) could not be completed for at least one skill in scope, because that skill's `SKILL.md` was not readable this session (a marketplace install's plugin cache, denied under the sandbox). `requires_config` resolution needs only files already in the repository, so it is never unchecked. Use `policy-grants` when an - existing vetted-ops policy cannot be read or parsed. A missing + existing vetted-ops policy or its required label values cannot be verified. A missing policy is not applicable, not unchecked. Empty when nothing was skipped. - `stamp_written` is `true` only when `proposals` and `unchecked` are both empty — nothing changed, so the stamp is written immediately with no From 182a87226bc82160d1d007cb86cbf4d5647c9c0e Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Wed, 4 Nov 2026 05:36:31 -0800 Subject: [PATCH 3/3] fix(security): read the tracker title from a file The documented "$(cat )" kept vetted-op out of the sandbox exclusion, so every GitHub import failed under the secure setup. The title is now a workspace file the dispatcher reads and validates, like the body, so the command stays bare and the shell never sees it. A dry run accepts any --config, so it never prints a title read from a file, and a refused title file is not quoted in the error. Also corrects the operation count in the vetted-ops README. Generated-by: Claude Opus 5 --- .../skills/issue-import-from-md/SKILL.md | 18 ++-- .../skills/issue-import-from-pr/SKILL.md | 24 +++--- .../skills/issue-import/apply.md | 16 ++-- .../tools/vetted-ops/README.md | 4 +- .../tools/vetted-ops/src/vetted_ops/cli.py | 12 ++- .../tools/vetted-ops/src/vetted_ops/ops.py | 18 ++++ tools/vetted-ops/README.md | 4 +- tools/vetted-ops/src/vetted_ops/cli.py | 12 ++- tools/vetted-ops/src/vetted_ops/ops.py | 18 ++++ .../tests/test_issue_create_labeled.py | 82 ++++++++++++++++++- .../vetted-ops/tests/test_tracker_backends.py | 5 +- 11 files changed, 168 insertions(+), 45 deletions(-) diff --git a/plugins/magpie-security/skills/issue-import-from-md/SKILL.md b/plugins/magpie-security/skills/issue-import-from-md/SKILL.md index c60714a41..8201f2a6e 100644 --- a/plugins/magpie-security/skills/issue-import-from-md/SKILL.md +++ b/plugins/magpie-security/skills/issue-import-from-md/SKILL.md @@ -27,7 +27,7 @@ argument-hint: "[path-to-markdown-file]" capability: capability:intake surface_hash: sha256:b741b2de80b78093 license: Apache-2.0 -measured_tokens: 6243 +measured_tokens: 6272 --- <!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files): @@ -348,7 +348,7 @@ The batch is a serial loop, **not** parallel, so the `gh` calls and board mutati For each confirmed finding, use `issue-create-labeled` instead of raw `gh api` or `gh issue create`. -Write the confirmed title to +Write the confirmed title, with the Write tool, to `<scratch>/import-md-<basename>-<index>-title.txt` and confirmed rendered body to `<scratch>/import-md-<basename>-<index>-body.md`. @@ -356,17 +356,13 @@ and confirmed rendered body to For a GitHub tracker: ```bash -uv run --project ~/.claude/magpie/vetted-ops vetted-op \ - --caller security-issue-import-from-md \ - issue-create-labeled \ - "$(cat <scratch>/import-md-<basename>-<index>-title.txt)" \ - <scratch>/import-md-<basename>-<index>-body.md \ - '["needs triage","security issue"]' +uv run --project ~/.claude/magpie/vetted-ops vetted-op --caller security-issue-import-from-md issue-create-labeled <scratch>/import-md-<basename>-<index>-title.txt <scratch>/import-md-<basename>-<index>-body.md '["needs triage","security issue"]' ``` -The title is passed as one validated argument. The body travels -through stdin. The configured security labels are validated and -applied atomically at creation. +The finding title is attacker-controlled, so it travels as a file: the dispatcher reads and validates it, and the shell never sees it. +Keep the command bare, with no `$(…)`, or it runs inside the sandbox and fails. +The body travels through stdin. +The configured security labels are validated and applied atomically at creation. Capture `number`, `node_id`, and `url` from the JSON response. diff --git a/plugins/magpie-security/skills/issue-import-from-pr/SKILL.md b/plugins/magpie-security/skills/issue-import-from-pr/SKILL.md index eab05b627..7e728a5ec 100644 --- a/plugins/magpie-security/skills/issue-import-from-pr/SKILL.md +++ b/plugins/magpie-security/skills/issue-import-from-pr/SKILL.md @@ -20,7 +20,7 @@ argument-hint: "[pr-number] [repo:owner/name]" capability: capability:intake surface_hash: sha256:26be912ca52168e5 license: Apache-2.0 -measured_tokens: 7869 +measured_tokens: 7895 --- <!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files): @@ -453,28 +453,24 @@ Sequenced. Each step depends on the previous one's output. Use `issue-create-labeled` instead of raw GitHub issue creation. -Write the confirmed title to `<scratch>/import-pr-<N>-title.txt` +Write the confirmed title, with the Write tool, to `<scratch>/import-pr-<N>-title.txt` and the confirmed `render-body` text to `<scratch>/import-pr-<N>-body.md`. -Serialize the exact Step 5c labels into a JSON array in -`<scratch>/import-pr-<N>-labels.json`. Do not invent or discard -scope, PR-state, or security-marker labels. +Serialize the exact Step 5c labels into a JSON array, `<labels-json>` below. +Do not invent or discard scope, PR-state, or security-marker labels. For a GitHub tracker: ```bash -uv run --project ~/.claude/magpie/vetted-ops vetted-op \ - --caller security-issue-import-from-pr \ - issue-create-labeled \ - "$(cat <scratch>/import-pr-<N>-title.txt)" \ - <scratch>/import-pr-<N>-body.md \ - "$(cat <scratch>/import-pr-<N>-labels.json)" +uv run --project ~/.claude/magpie/vetted-ops vetted-op --caller security-issue-import-from-pr issue-create-labeled <scratch>/import-pr-<N>-title.txt <scratch>/import-pr-<N>-body.md '<labels-json>' ``` -The title is passed as one validated argument. The report body -travels through stdin. All labels must be approved by the -vetted-ops policy and are applied at creation. +The title derives from the attacker-controlled PR title, so it travels as a file: the dispatcher reads and validates it, and the shell never sees it. +The labels come from configuration, so they are written in the command. +Keep the command bare, with no `$(…)`, or it runs inside the sandbox and fails. +The report body travels through stdin. +All labels must be approved by the vetted-ops policy and are applied at creation. Capture `number`, `node_id`, and `url` from the JSON response. diff --git a/plugins/magpie-security/skills/issue-import/apply.md b/plugins/magpie-security/skills/issue-import/apply.md index cc5b7f4b0..fcb242bd2 100644 --- a/plugins/magpie-security/skills/issue-import/apply.md +++ b/plugins/magpie-security/skills/issue-import/apply.md @@ -41,21 +41,19 @@ For each confirmed `Report` or forwarder-relayed candidate: security report content. The agent guard blocks those commands. Write the confirmed title to `<scratch>/issue-title-<threadId>.txt` - and use the body file rendered in item 1. + with the Write tool, and use the body file rendered in item 1. For a GitHub tracker: ```bash - uv run --project ~/.claude/magpie/vetted-ops vetted-op \ - --caller security-issue-import \ - issue-create-labeled \ - "$(cat <scratch>/issue-title-<threadId>.txt)" \ - <scratch>/issue-body-<threadId>.md \ - '["needs triage","security issue"]' + uv run --project ~/.claude/magpie/vetted-ops vetted-op --caller security-issue-import issue-create-labeled <scratch>/issue-title-<threadId>.txt <scratch>/issue-body-<threadId>.md '["needs triage","security issue"]' ``` - The title is one validated argv argument, never evaluated as - shell code. The body travels on stdin, never in command arguments. + The title comes from an attacker-controlled email subject, so it + travels as a file: the dispatcher reads and validates it, and the + shell never sees it. Keep the command bare, with no `$(…)`, or it + runs inside the sandbox and fails. + The body travels on stdin, never in command arguments. Capture `number`, `node_id`, and `url` from the JSON output. Both labels are applied atomically at creation. diff --git a/plugins/magpie-vetted-ops/tools/vetted-ops/README.md b/plugins/magpie-vetted-ops/tools/vetted-ops/README.md index f36d86161..16e5fd2fd 100644 --- a/plugins/magpie-vetted-ops/tools/vetted-ops/README.md +++ b/plugins/magpie-vetted-ops/tools/vetted-ops/README.md @@ -615,11 +615,11 @@ The guarantees above carry over, because the translation lives in reviewed code The full mapping, from the `gh` shape in the skills to the vetted operation to the backend subcommand, is in the contract's [skill-command table](https://github.com/apache/magpie/blob/main/tools/security-tracker/contract.md#from-skill-commands-to-vetted-operations). -Ten operations exist for it: +Eleven operations exist for it: | Operation | Kind | Parameters | Notes | |---|---|---|---| -| `issue-create-labeled` | write | `title body labels` | GitHub only: create a private tracker with a JSON array of policy-approved labels, applied atomically. Body travels on stdin; returns `number`, `node_id`, and `url`. | +| `issue-create-labeled` | write | `title body labels` | GitHub only: create a private tracker with a JSON array of policy-approved labels, applied atomically. `title` and `body` are paths to workspace files: the title is read and validated here, and the body travels on stdin. Returns `number`, `node_id`, and `url`. | | `issue-create` | write | `title body` | GitHub: `gh api …/issues -f title=… -F body=@-`. | | `issue-reopen` | write | `number` | | | `issue-list-label` | read | `state label` | `issue-list` filtered by one configured label. | diff --git a/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/cli.py b/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/cli.py index c6aa1391f..c15c55707 100644 --- a/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/cli.py +++ b/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/cli.py @@ -101,6 +101,8 @@ def _validate_params( ) body = ops_mod.read_body(raw, workspace=config.workspace) resolved[name] = "-" + elif name in op.title_files: + resolved[name] = ops_mod.read_title(raw, workspace=config.workspace) elif ( name == "number" and config.tracker_backend is not None @@ -153,6 +155,14 @@ def _validate_params( return resolved, body +def _without_file_titles(op: ops_mod.Op, params: dict[str, str], command: list[str]) -> list[str]: + """A dry run's argv for display: like a body, a title read from a file shows only as its size.""" + hidden = { + f"title={params[name]}": f"title=<from file, {len(params[name])} chars>" for name in op.title_files + } + return [hidden.get(argument, argument) for argument in command] + + def build_argv( op: ops_mod.Op, params: dict[str, str], config: Config ) -> list[str] | dict[str, object] | procedures.Plan | tracker_backends.BackendCall: @@ -333,7 +343,7 @@ def main(argv: list[str] | None = None, *, read_only: bool = False, tracker_only if op.backend == "gh": if not isinstance(command, list): raise ops_mod.ParamError(f"operation {op.name!r} produced invalid command type") - print(" ".join(command)) + print(" ".join(_without_file_titles(op, params, command))) else: if not isinstance(command, dict): raise ops_mod.ParamError(f"operation {op.name!r} produced invalid request descriptor") diff --git a/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/ops.py b/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/ops.py index 9d325ea47..7e5f603a5 100644 --- a/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/ops.py +++ b/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/ops.py @@ -437,6 +437,20 @@ def save_output(name: str, data: bytes, *, workspace: Path) -> Path: return root / SAVED_DIR / name +def read_title(value: str, *, workspace: Path) -> str: + """ + Read a title from a workspace file, under the same checks as an inline one. + + A refusal never quotes the file: a dry run accepts any `--config`, so its + workspace can be one the agent chose, and this runs outside the sandbox. + """ + data = read_body(value, workspace=workspace) + try: + return title(data.decode("utf-8").strip()) + except (UnicodeDecodeError, ParamError): + raise ParamError(f"title file must hold one UTF-8 line of 1 to 256 characters: {value!r}") from None + + def read_body(value: str, *, workspace: Path) -> bytes: """ Validate and read body text, returning its **content**. @@ -517,6 +531,9 @@ class Op: enums: dict[str, str] = field(default_factory=dict) #: Parameters holding a path to body content. body_files: tuple[str, ...] = () + #: Parameters holding a path to a title, for one too untrusted to write on a + #: command line: the agent saves it verbatim, and the dispatcher reads it. + title_files: tuple[str, ...] = () #: Admitted on `vetted-op-tracker` although not a `procedure` — a tracker #: write that must run outside the sandbox (the local tracker's push). tracker_entry: bool = False @@ -1154,6 +1171,7 @@ def _issue_create_labeled(cfg: dict[str, str], title: str, body: str, labels: st writes=True, summary="Create a GitHub tracker with policy-approved labels atomically.", body_files=("body",), + title_files=("title",), build=_issue_create_labeled, ) ) diff --git a/tools/vetted-ops/README.md b/tools/vetted-ops/README.md index 6da03375f..f39edfc44 100644 --- a/tools/vetted-ops/README.md +++ b/tools/vetted-ops/README.md @@ -615,11 +615,11 @@ The guarantees above carry over, because the translation lives in reviewed code The full mapping, from the `gh` shape in the skills to the vetted operation to the backend subcommand, is in the contract's [skill-command table](../security-tracker/contract.md#from-skill-commands-to-vetted-operations). -Ten operations exist for it: +Eleven operations exist for it: | Operation | Kind | Parameters | Notes | |---|---|---|---| -| `issue-create-labeled` | write | `title body labels` | GitHub only: create a private tracker with a JSON array of policy-approved labels, applied atomically. Body travels on stdin; returns `number`, `node_id`, and `url`. | +| `issue-create-labeled` | write | `title body labels` | GitHub only: create a private tracker with a JSON array of policy-approved labels, applied atomically. `title` and `body` are paths to workspace files: the title is read and validated here, and the body travels on stdin. Returns `number`, `node_id`, and `url`. | | `issue-create` | write | `title body` | GitHub: `gh api …/issues -f title=… -F body=@-`. | | `issue-reopen` | write | `number` | | | `issue-list-label` | read | `state label` | `issue-list` filtered by one configured label. | diff --git a/tools/vetted-ops/src/vetted_ops/cli.py b/tools/vetted-ops/src/vetted_ops/cli.py index c6aa1391f..c15c55707 100644 --- a/tools/vetted-ops/src/vetted_ops/cli.py +++ b/tools/vetted-ops/src/vetted_ops/cli.py @@ -101,6 +101,8 @@ def _validate_params( ) body = ops_mod.read_body(raw, workspace=config.workspace) resolved[name] = "-" + elif name in op.title_files: + resolved[name] = ops_mod.read_title(raw, workspace=config.workspace) elif ( name == "number" and config.tracker_backend is not None @@ -153,6 +155,14 @@ def _validate_params( return resolved, body +def _without_file_titles(op: ops_mod.Op, params: dict[str, str], command: list[str]) -> list[str]: + """A dry run's argv for display: like a body, a title read from a file shows only as its size.""" + hidden = { + f"title={params[name]}": f"title=<from file, {len(params[name])} chars>" for name in op.title_files + } + return [hidden.get(argument, argument) for argument in command] + + def build_argv( op: ops_mod.Op, params: dict[str, str], config: Config ) -> list[str] | dict[str, object] | procedures.Plan | tracker_backends.BackendCall: @@ -333,7 +343,7 @@ def main(argv: list[str] | None = None, *, read_only: bool = False, tracker_only if op.backend == "gh": if not isinstance(command, list): raise ops_mod.ParamError(f"operation {op.name!r} produced invalid command type") - print(" ".join(command)) + print(" ".join(_without_file_titles(op, params, command))) else: if not isinstance(command, dict): raise ops_mod.ParamError(f"operation {op.name!r} produced invalid request descriptor") diff --git a/tools/vetted-ops/src/vetted_ops/ops.py b/tools/vetted-ops/src/vetted_ops/ops.py index 9d325ea47..7e5f603a5 100644 --- a/tools/vetted-ops/src/vetted_ops/ops.py +++ b/tools/vetted-ops/src/vetted_ops/ops.py @@ -437,6 +437,20 @@ def save_output(name: str, data: bytes, *, workspace: Path) -> Path: return root / SAVED_DIR / name +def read_title(value: str, *, workspace: Path) -> str: + """ + Read a title from a workspace file, under the same checks as an inline one. + + A refusal never quotes the file: a dry run accepts any `--config`, so its + workspace can be one the agent chose, and this runs outside the sandbox. + """ + data = read_body(value, workspace=workspace) + try: + return title(data.decode("utf-8").strip()) + except (UnicodeDecodeError, ParamError): + raise ParamError(f"title file must hold one UTF-8 line of 1 to 256 characters: {value!r}") from None + + def read_body(value: str, *, workspace: Path) -> bytes: """ Validate and read body text, returning its **content**. @@ -517,6 +531,9 @@ class Op: enums: dict[str, str] = field(default_factory=dict) #: Parameters holding a path to body content. body_files: tuple[str, ...] = () + #: Parameters holding a path to a title, for one too untrusted to write on a + #: command line: the agent saves it verbatim, and the dispatcher reads it. + title_files: tuple[str, ...] = () #: Admitted on `vetted-op-tracker` although not a `procedure` — a tracker #: write that must run outside the sandbox (the local tracker's push). tracker_entry: bool = False @@ -1154,6 +1171,7 @@ def _issue_create_labeled(cfg: dict[str, str], title: str, body: str, labels: st writes=True, summary="Create a GitHub tracker with policy-approved labels atomically.", body_files=("body",), + title_files=("title",), build=_issue_create_labeled, ) ) diff --git a/tools/vetted-ops/tests/test_issue_create_labeled.py b/tools/vetted-ops/tests/test_issue_create_labeled.py index 76b79ae3e..223f982ad 100644 --- a/tools/vetted-ops/tests/test_issue_create_labeled.py +++ b/tools/vetted-ops/tests/test_issue_create_labeled.py @@ -45,6 +45,12 @@ def policy(tmp_path: Path) -> Path: return cfg +def _title_file(policy: Path, text: str) -> str: + path = policy.parent / "scratch" / "title.txt" + path.write_text(text) + return str(path) + + def test_creation_is_pinned_to_private_tracker(policy: Path) -> None: command = ops.OPS["issue-create-labeled"].build( config.load(policy).as_mapping(), @@ -101,7 +107,7 @@ def test_unapproved_label_refused(policy: Path, capsys: pytest.CaptureFixture[st "security-issue-import", "--dry-run", "issue-create-labeled", - "Security report", + _title_file(policy, "Security report\n"), str(body), json.dumps(["public-disclosure"]), ] @@ -135,7 +141,7 @@ def fake_run(argv: list[str], *, check: bool, input: bytes) -> subprocess.Comple "--caller", "security-issue-import", "issue-create-labeled", - "Private security report", + _title_file(policy, "Private security report\n"), str(body), '["needs triage","security issue"]', ] @@ -149,6 +155,76 @@ def fake_run(argv: list[str], *, check: bool, input: bytes) -> subprocess.Comple assert "repos/apache/public/issues" not in observed["argv"] assert "labels[]=needs triage" in observed["argv"] assert "labels[]=security issue" in observed["argv"] + assert "title=Private security report" in observed["argv"] + + +@pytest.mark.parametrize("title", ["", " \n", "two\nlines"]) +def test_a_title_file_gets_the_title_checks( + policy: Path, title: str, capsys: pytest.CaptureFixture[str] +) -> None: + body = policy.parent / "scratch" / "body.md" + body.write_text("Report\n") + code = cli.main( + [ + "--config", + str(policy), + "--caller", + "security-issue-import", + "--dry-run", + "issue-create-labeled", + _title_file(policy, title), + str(body), + '["needs triage"]', + ] + ) + assert code != cli.EXIT_OK + assert "title" in capsys.readouterr().err.lower() + + +@pytest.mark.parametrize("secret", ["hunter2", "hunter2\nsecond line", "hunter2" * 50]) +def test_a_title_file_is_never_echoed(policy: Path, secret: str, capsys: pytest.CaptureFixture[str]) -> None: + """A dry run takes any --config, so its output must not disclose a file it read.""" + body = policy.parent / "scratch" / "body.md" + body.write_text("Report\n") + cli.main( + [ + "--config", + str(policy), + "--caller", + "security-issue-import", + "--dry-run", + "issue-create-labeled", + _title_file(policy, secret), + str(body), + '["needs triage"]', + ] + ) + captured = capsys.readouterr() + assert "hunter2" not in captured.out + captured.err + + +def test_a_title_file_must_live_in_the_workspace( + policy: Path, tmp_path: Path, capsys: pytest.CaptureFixture[str] +) -> None: + outside = tmp_path / "title.txt" + outside.write_text("Report\n") + body = policy.parent / "scratch" / "body.md" + body.write_text("Report\n") + code = cli.main( + [ + "--config", + str(policy), + "--caller", + "security-issue-import", + "--dry-run", + "issue-create-labeled", + str(outside), + str(body), + '["needs triage"]', + ] + ) + assert code != cli.EXIT_OK + assert "workspace" in capsys.readouterr().err.lower() def test_github_failure_returns_command_error(policy: Path, monkeypatch: pytest.MonkeyPatch) -> None: @@ -173,7 +249,7 @@ def fake_run(argv: list[str], *, check: bool, input: bytes) -> subprocess.Comple "--caller", "security-issue-import", "issue-create-labeled", - "Private security report", + _title_file(policy, "Private security report\n"), str(body), '["needs triage","security issue"]', ] diff --git a/tools/vetted-ops/tests/test_tracker_backends.py b/tools/vetted-ops/tests/test_tracker_backends.py index 5c28b340a..eb6112b0f 100644 --- a/tools/vetted-ops/tests/test_tracker_backends.py +++ b/tools/vetted-ops/tests/test_tracker_backends.py @@ -114,7 +114,7 @@ def _body(policy: Path, text: str = "hello\n") -> str: def _args(op: ops.Op, policy: Path) -> list[str]: - return [(_body(policy) if p in op.body_files else SAMPLE[p]) for p in op.params] + return [(_body(policy) if p in op.body_files + op.title_files else SAMPLE[p]) for p in op.params] # --- the mapping is complete ------------------------------------------------- @@ -134,7 +134,8 @@ def test_every_operation_that_addresses_the_tracker_is_mapped(tmp_path: Path) -> addressing = set() for name, op in ops.OPS.items(): params = { - p: (str(workspace / "b.md") if p in op.body_files else SAMPLE.get(p, "1")) for p in op.params + p: (str(workspace / "b.md") if p in op.body_files + op.title_files else SAMPLE.get(p, "1")) + for p in op.params } try: op.build(trackerless, **params)