Skip to content

Commit 182a872

Browse files
committed
fix(security): read the tracker title from a file
The documented "$(cat <title file>)" 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
1 parent 1adc7ad commit 182a872

11 files changed

Lines changed: 168 additions & 45 deletions

File tree

‎plugins/magpie-security/skills/issue-import-from-md/SKILL.md‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ argument-hint: "[path-to-markdown-file]"
2727
capability: capability:intake
2828
surface_hash: sha256:b741b2de80b78093
2929
license: Apache-2.0
30-
measured_tokens: 6243
30+
measured_tokens: 6272
3131
---
3232

3333
<!-- Placeholder convention (see AGENTS.md#placeholder-convention-used-in-skill-files):
@@ -348,25 +348,21 @@ The batch is a serial loop, **not** parallel, so the `gh` calls and board mutati
348348
For each confirmed finding, use `issue-create-labeled`
349349
instead of raw `gh api` or `gh issue create`.
350350

351-
Write the confirmed title to
351+
Write the confirmed title, with the Write tool, to
352352
`<scratch>/import-md-<basename>-<index>-title.txt`
353353
and confirmed rendered body to
354354
`<scratch>/import-md-<basename>-<index>-body.md`.
355355

356356
For a GitHub tracker:
357357

358358
```bash
359-
uv run --project ~/.claude/magpie/vetted-ops vetted-op \
360-
--caller security-issue-import-from-md \
361-
issue-create-labeled \
362-
"$(cat <scratch>/import-md-<basename>-<index>-title.txt)" \
363-
<scratch>/import-md-<basename>-<index>-body.md \
364-
'["needs triage","security issue"]'
359+
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"]'
365360
```
366361

367-
The title is passed as one validated argument. The body travels
368-
through stdin. The configured security labels are validated and
369-
applied atomically at creation.
362+
The finding title is attacker-controlled, so it travels as a file: the dispatcher reads and validates it, and the shell never sees it.
363+
Keep the command bare, with no `$(…)`, or it runs inside the sandbox and fails.
364+
The body travels through stdin.
365+
The configured security labels are validated and applied atomically at creation.
370366

371367
Capture `number`, `node_id`, and `url` from the JSON response.
372368

‎plugins/magpie-security/skills/issue-import-from-pr/SKILL.md‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ argument-hint: "[pr-number] [repo:owner/name]"
2020
capability: capability:intake
2121
surface_hash: sha256:26be912ca52168e5
2222
license: Apache-2.0
23-
measured_tokens: 7869
23+
measured_tokens: 7895
2424
---
2525

2626
<!-- 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.
453453

454454
Use `issue-create-labeled` instead of raw GitHub issue creation.
455455

456-
Write the confirmed title to `<scratch>/import-pr-<N>-title.txt`
456+
Write the confirmed title, with the Write tool, to `<scratch>/import-pr-<N>-title.txt`
457457
and the confirmed `render-body` text to
458458
`<scratch>/import-pr-<N>-body.md`.
459459

460-
Serialize the exact Step 5c labels into a JSON array in
461-
`<scratch>/import-pr-<N>-labels.json`. Do not invent or discard
462-
scope, PR-state, or security-marker labels.
460+
Serialize the exact Step 5c labels into a JSON array, `<labels-json>` below.
461+
Do not invent or discard scope, PR-state, or security-marker labels.
463462

464463
For a GitHub tracker:
465464

466465
```bash
467-
uv run --project ~/.claude/magpie/vetted-ops vetted-op \
468-
--caller security-issue-import-from-pr \
469-
issue-create-labeled \
470-
"$(cat <scratch>/import-pr-<N>-title.txt)" \
471-
<scratch>/import-pr-<N>-body.md \
472-
"$(cat <scratch>/import-pr-<N>-labels.json)"
466+
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>'
473467
```
474468

475-
The title is passed as one validated argument. The report body
476-
travels through stdin. All labels must be approved by the
477-
vetted-ops policy and are applied at creation.
469+
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.
470+
The labels come from configuration, so they are written in the command.
471+
Keep the command bare, with no `$(…)`, or it runs inside the sandbox and fails.
472+
The report body travels through stdin.
473+
All labels must be approved by the vetted-ops policy and are applied at creation.
478474

479475
Capture `number`, `node_id`, and `url` from the JSON response.
480476

‎plugins/magpie-security/skills/issue-import/apply.md‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,19 @@ For each confirmed `Report` or forwarder-relayed candidate:
4141
security report content. The agent guard blocks those commands.
4242

4343
Write the confirmed title to `<scratch>/issue-title-<threadId>.txt`
44-
and use the body file rendered in item 1.
44+
with the Write tool, and use the body file rendered in item 1.
4545

4646
For a GitHub tracker:
4747

4848
```bash
49-
uv run --project ~/.claude/magpie/vetted-ops vetted-op \
50-
--caller security-issue-import \
51-
issue-create-labeled \
52-
"$(cat <scratch>/issue-title-<threadId>.txt)" \
53-
<scratch>/issue-body-<threadId>.md \
54-
'["needs triage","security issue"]'
49+
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"]'
5550
```
5651

57-
The title is one validated argv argument, never evaluated as
58-
shell code. The body travels on stdin, never in command arguments.
52+
The title comes from an attacker-controlled email subject, so it
53+
travels as a file: the dispatcher reads and validates it, and the
54+
shell never sees it. Keep the command bare, with no `$(…)`, or it
55+
runs inside the sandbox and fails.
56+
The body travels on stdin, never in command arguments.
5957

6058
Capture `number`, `node_id`, and `url` from the JSON output.
6159
Both labels are applied atomically at creation.

‎plugins/magpie-vetted-ops/tools/vetted-ops/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,11 @@ The guarantees above carry over, because the translation lives in reviewed code
615615
The full mapping, from the `gh` shape in the skills to the vetted operation to
616616
the backend subcommand, is in the contract's
617617
[skill-command table](https://github.com/apache/magpie/blob/main/tools/security-tracker/contract.md#from-skill-commands-to-vetted-operations).
618-
Ten operations exist for it:
618+
Eleven operations exist for it:
619619

620620
| Operation | Kind | Parameters | Notes |
621621
|---|---|---|---|
622-
| `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`. |
622+
| `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`. |
623623
| `issue-create` | write | `title body` | GitHub: `gh api …/issues -f title=… -F body=@-`. |
624624
| `issue-reopen` | write | `number` | |
625625
| `issue-list-label` | read | `state label` | `issue-list` filtered by one configured label. |

‎plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/cli.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def _validate_params(
101101
)
102102
body = ops_mod.read_body(raw, workspace=config.workspace)
103103
resolved[name] = "-"
104+
elif name in op.title_files:
105+
resolved[name] = ops_mod.read_title(raw, workspace=config.workspace)
104106
elif (
105107
name == "number"
106108
and config.tracker_backend is not None
@@ -153,6 +155,14 @@ def _validate_params(
153155
return resolved, body
154156

155157

158+
def _without_file_titles(op: ops_mod.Op, params: dict[str, str], command: list[str]) -> list[str]:
159+
"""A dry run's argv for display: like a body, a title read from a file shows only as its size."""
160+
hidden = {
161+
f"title={params[name]}": f"title=<from file, {len(params[name])} chars>" for name in op.title_files
162+
}
163+
return [hidden.get(argument, argument) for argument in command]
164+
165+
156166
def build_argv(
157167
op: ops_mod.Op, params: dict[str, str], config: Config
158168
) -> 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
333343
if op.backend == "gh":
334344
if not isinstance(command, list):
335345
raise ops_mod.ParamError(f"operation {op.name!r} produced invalid command type")
336-
print(" ".join(command))
346+
print(" ".join(_without_file_titles(op, params, command)))
337347
else:
338348
if not isinstance(command, dict):
339349
raise ops_mod.ParamError(f"operation {op.name!r} produced invalid request descriptor")

‎plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/ops.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,20 @@ def save_output(name: str, data: bytes, *, workspace: Path) -> Path:
437437
return root / SAVED_DIR / name
438438

439439

440+
def read_title(value: str, *, workspace: Path) -> str:
441+
"""
442+
Read a title from a workspace file, under the same checks as an inline one.
443+
444+
A refusal never quotes the file: a dry run accepts any `--config`, so its
445+
workspace can be one the agent chose, and this runs outside the sandbox.
446+
"""
447+
data = read_body(value, workspace=workspace)
448+
try:
449+
return title(data.decode("utf-8").strip())
450+
except (UnicodeDecodeError, ParamError):
451+
raise ParamError(f"title file must hold one UTF-8 line of 1 to 256 characters: {value!r}") from None
452+
453+
440454
def read_body(value: str, *, workspace: Path) -> bytes:
441455
"""
442456
Validate and read body text, returning its **content**.
@@ -517,6 +531,9 @@ class Op:
517531
enums: dict[str, str] = field(default_factory=dict)
518532
#: Parameters holding a path to body content.
519533
body_files: tuple[str, ...] = ()
534+
#: Parameters holding a path to a title, for one too untrusted to write on a
535+
#: command line: the agent saves it verbatim, and the dispatcher reads it.
536+
title_files: tuple[str, ...] = ()
520537
#: Admitted on `vetted-op-tracker` although not a `procedure` — a tracker
521538
#: write that must run outside the sandbox (the local tracker's push).
522539
tracker_entry: bool = False
@@ -1154,6 +1171,7 @@ def _issue_create_labeled(cfg: dict[str, str], title: str, body: str, labels: st
11541171
writes=True,
11551172
summary="Create a GitHub tracker with policy-approved labels atomically.",
11561173
body_files=("body",),
1174+
title_files=("title",),
11571175
build=_issue_create_labeled,
11581176
)
11591177
)

‎tools/vetted-ops/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,11 @@ The guarantees above carry over, because the translation lives in reviewed code
615615
The full mapping, from the `gh` shape in the skills to the vetted operation to
616616
the backend subcommand, is in the contract's
617617
[skill-command table](../security-tracker/contract.md#from-skill-commands-to-vetted-operations).
618-
Ten operations exist for it:
618+
Eleven operations exist for it:
619619

620620
| Operation | Kind | Parameters | Notes |
621621
|---|---|---|---|
622-
| `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`. |
622+
| `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`. |
623623
| `issue-create` | write | `title body` | GitHub: `gh api …/issues -f title=… -F body=@-`. |
624624
| `issue-reopen` | write | `number` | |
625625
| `issue-list-label` | read | `state label` | `issue-list` filtered by one configured label. |

‎tools/vetted-ops/src/vetted_ops/cli.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def _validate_params(
101101
)
102102
body = ops_mod.read_body(raw, workspace=config.workspace)
103103
resolved[name] = "-"
104+
elif name in op.title_files:
105+
resolved[name] = ops_mod.read_title(raw, workspace=config.workspace)
104106
elif (
105107
name == "number"
106108
and config.tracker_backend is not None
@@ -153,6 +155,14 @@ def _validate_params(
153155
return resolved, body
154156

155157

158+
def _without_file_titles(op: ops_mod.Op, params: dict[str, str], command: list[str]) -> list[str]:
159+
"""A dry run's argv for display: like a body, a title read from a file shows only as its size."""
160+
hidden = {
161+
f"title={params[name]}": f"title=<from file, {len(params[name])} chars>" for name in op.title_files
162+
}
163+
return [hidden.get(argument, argument) for argument in command]
164+
165+
156166
def build_argv(
157167
op: ops_mod.Op, params: dict[str, str], config: Config
158168
) -> 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
333343
if op.backend == "gh":
334344
if not isinstance(command, list):
335345
raise ops_mod.ParamError(f"operation {op.name!r} produced invalid command type")
336-
print(" ".join(command))
346+
print(" ".join(_without_file_titles(op, params, command)))
337347
else:
338348
if not isinstance(command, dict):
339349
raise ops_mod.ParamError(f"operation {op.name!r} produced invalid request descriptor")

‎tools/vetted-ops/src/vetted_ops/ops.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,20 @@ def save_output(name: str, data: bytes, *, workspace: Path) -> Path:
437437
return root / SAVED_DIR / name
438438

439439

440+
def read_title(value: str, *, workspace: Path) -> str:
441+
"""
442+
Read a title from a workspace file, under the same checks as an inline one.
443+
444+
A refusal never quotes the file: a dry run accepts any `--config`, so its
445+
workspace can be one the agent chose, and this runs outside the sandbox.
446+
"""
447+
data = read_body(value, workspace=workspace)
448+
try:
449+
return title(data.decode("utf-8").strip())
450+
except (UnicodeDecodeError, ParamError):
451+
raise ParamError(f"title file must hold one UTF-8 line of 1 to 256 characters: {value!r}") from None
452+
453+
440454
def read_body(value: str, *, workspace: Path) -> bytes:
441455
"""
442456
Validate and read body text, returning its **content**.
@@ -517,6 +531,9 @@ class Op:
517531
enums: dict[str, str] = field(default_factory=dict)
518532
#: Parameters holding a path to body content.
519533
body_files: tuple[str, ...] = ()
534+
#: Parameters holding a path to a title, for one too untrusted to write on a
535+
#: command line: the agent saves it verbatim, and the dispatcher reads it.
536+
title_files: tuple[str, ...] = ()
520537
#: Admitted on `vetted-op-tracker` although not a `procedure` — a tracker
521538
#: write that must run outside the sandbox (the local tracker's push).
522539
tracker_entry: bool = False
@@ -1154,6 +1171,7 @@ def _issue_create_labeled(cfg: dict[str, str], title: str, body: str, labels: st
11541171
writes=True,
11551172
summary="Create a GitHub tracker with policy-approved labels atomically.",
11561173
body_files=("body",),
1174+
title_files=("title",),
11571175
build=_issue_create_labeled,
11581176
)
11591177
)

0 commit comments

Comments
 (0)