Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

- `api` (a governance-authorised user, pre-flight `api`): one proposal to
allocate through the CVE tool's API, with the form URL as the fallback and
the one `cve-tool allocate` command to run on a yes.
the one `cve-tool allocate` command to run on a yes. With `vetted_workspace`
(the secure setup's vetted operations), the command is the vetted
`cve-allocate` instead, and `title_file` is the workspace file to write the
title to first.
- `recipe` (authorised, any other pre-flight outcome): open the allocation
URL, paste the title, submit, paste the ID back.
- `relay` (not authorised): a terse request for an authorised member — the
Expand All @@ -32,6 +35,8 @@

from __future__ import annotations

import hashlib
import json
import re
from collections.abc import Mapping, Sequence
from typing import Any
Expand Down Expand Up @@ -78,6 +83,7 @@ def render(data: Mapping[str, Any]) -> dict[str, Any]:
)
block = fence(title)
command = None
title_file = None
if member and (data.get("preflight") or {}).get("path") == "api":
pmc = one_line(data.get("pmc"))
if not pmc:
Expand All @@ -89,7 +95,20 @@ def render(data: Mapping[str, Any]) -> dict[str, Any]:
"This reserves a CVE ID immediately and cannot be undone.\n"
f"(Fallback, if the API path fails: the form at {url}.)\n"
)
command = cve_tool.command(data, "allocate", "--pmc", pmc, "--title", title)
workspace = one_line(data.get("vetted_workspace"))
if workspace:
# The vetted operation reads the title from a workspace file; `pmc` lets the
# client refuse a token held for any other PMC. The file is named by a hash of
# tracker, issue and the approved title, so no other run (another tracker, or
# this issue with another title) writes the same file between the write and
# the allocation; a sanitised slug would not do (`a-b/c` and `a/b-c` collide).
key = hashlib.sha256(json.dumps([tracker, str(data["issue"]), title]).encode()).hexdigest()[:24]
title_file = {"path": f"{workspace.rstrip('/')}/cve-title-{key}.txt", "text": title + "\n"}
command = cve_tool.vetted_command(
"security-cve-allocate", "cve-allocate", pmc, title_file["path"]
)
else:
command = cve_tool.command(data, "allocate", "--pmc", pmc, "--title", title)
elif member:
path = "recipe"
indented = "\n".join(" " + line for line in block.split("\n"))
Expand All @@ -115,6 +134,7 @@ def render(data: Mapping[str, Any]) -> dict[str, Any]:
"path": path,
"text": text,
"command": command,
"title_file": title_file,
"governance_member_path": member,
"relay_message_present": path == "relay",
"api_allocation_proposed": path == "api",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
STABLE = "~/.claude/magpie/security-tools/cve-tool"
#: Where a framework checkout or snapshot install keeps the tool, run sandboxed.
PROJECT = "<framework>/tools/cve-tool"
#: The vetted-ops link, spelled as the sandbox exclusion matches it.
VETTED_OPS = "~/.claude/magpie/vetted-ops"


def stable_installed() -> bool:
Expand All @@ -64,3 +66,16 @@ def command(data: Mapping[str, Any], operation: str, *args: object) -> str:
return " ".join(("uv run --project", w(str(project)), "cve-tool", operation, *quoted))
# The literal `~`, unquoted: the sandbox exclusion and the `ask` rule match this spelling.
return " ".join(("uvx --from", STABLE, "cve-tool", operation, *quoted))


def vetted_command(caller: str, operation: str, *args: object) -> str:
"""`uvx --from <VETTED_OPS> vetted-op --caller <caller> <operation> <args>`.

The vetted operations (tools/vetted-ops, "The Vulnogram CVE-tool operations")
run the shipped Vulnogram client outside the sandbox with a fixed argv: no
override flag, no other session file. Arguments are shell-quoted here, like
`command`; a value the operation reads from a file (an allocation title, a
record) is passed as that file's workspace path, never inline.
"""
quoted = (shlex.quote(str(arg)) for arg in args)
return " ".join(("uvx --from", VETTED_OPS, "vetted-op --caller", shlex.quote(caller), operation, *quoted))
7 changes: 4 additions & 3 deletions plugins/magpie-security/skills/cve-allocate/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,12 @@ Full procedure: [`title-normalize.md`](title-normalize.md).

**Ask first** whether the user is authorised under `governance.cve_allocation_gate` (Step 0 item 3 may already have the answer).
Then write `{tracker, issue, title, governance_member, allocate_url, preflight, pmc, authorised_handles}` and run `<sm> recipe`;
present its `text` as it is. Its `path` is one of:
under the secure setup, with `security-cve-allocate` granted `cve-allocate`, also pass `vetted_workspace` (the vetted-ops policy's `workspace`).
Present its `text` as it is. Its `path` is one of:

- **`api`** — a governance-authorised user whose Step 0 pre-flight chose `api`: a proposal to allocate through the CVE tool's API, with `cve_authority.allocate_url` as the fallback.
On the user's yes, run its `command` (one `cve-tool allocate` call, the title shell-quoted) **once**,
write `{exit, stdout, stderr, pmc}` and run `<sm> allocate-result`: its `next` is `step-4` with the `cve_id`, `stop` (the ID comes back by mail), `setup`, `check-records` or `recipe`,
On the user's yes, write a non-null `title_file`'s `text` to its `path` with the Write tool, then run its `command` (one `cve-tool allocate` call, the title shell-quoted, or the vetted `cve-allocate`) **once**,
write `{exit, stdout, stderr, pmc}` and run `<sm> allocate-result` (after a vetted call, read its exit per [`api-allocation.md`](api-allocation.md#allocate-step-3-api-path) first): its `next` is `step-4` with the `cve_id`, `stop` (the ID comes back by mail), `setup`, `check-records` or `recipe`,
per [`api-allocation.md` § *Allocate*](api-allocation.md#allocate-step-3-api-path). `rerun_allocate` is false except after an expired token, and even then only on a fresh yes.
- **`recipe`** — a governance-authorised user otherwise: open the allocation URL (authenticate per [`<cve-tool>/README.md`](../../../../tools/cve-tool/README.md)), paste the title, submit, paste the ID back.
- **`relay`** — a user who is not authorised: the CVE tool will not let them submit, so they never get "click *Allocate*".
Expand Down
18 changes: 18 additions & 0 deletions plugins/magpie-security/skills/cve-allocate/api-allocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ On a yes, run the allocation **once**:
Pass the title as a single shell-quoted argument; it is attacker-influenced
text, so escape any quote it contains rather than interpolating it raw.

**Under the secure setup**, when the vetted-ops policy grants `security-cve-allocate` the `cve-allocate` operation,
allocate through it instead (`<sm> recipe` returns this command when given `vetted_workspace`):
write the recipe's `title_file` `text` to its `path` (`<workspace>/cve-title-<hash>.txt`) with the Write tool, then run

```bash
uvx --from ~/.claude/magpie/vetted-ops vetted-op --caller security-cve-allocate cve-allocate <pmc> <workspace>/cve-title-<hash>.txt
```

It runs the shipped Vulnogram client with a fixed argv, outside the sandbox, with no override flag reachable
([vetted-ops § *The Vulnogram CVE-tool operations*](../../../../tools/vetted-ops/README.md#the-vulnogram-cve-tool-operations)),
and passes `--pmc <pmc>`, so the client refuses a token held for any other PMC.
The title travels as a file, so it is never quoted into a command line.
On success it exits 0 and the ID is the first stdout line, as below.
When the client fails, `vetted-op` exits 4 and names the client's own code on stderr (`CVE tool exit N`): read the table below with that `N`.
An exit 3 whose stderr says the caller `is not permitted to run 'cve-allocate'` means the policy does not grant it and nothing was allocated: run the `cve-tool allocate` command above instead, on the same yes.
Any other exit 2 or 3 is `vetted-op` refusing the arguments (the PMC, the title file): nothing was allocated, but do not route around the refusal; show its stderr and stop.
Any other outcome (an exit 4 without a `CVE tool exit` line, an interrupted run) is unclear: treat it like exit 3 / 4 in the table, and check `<pmc>`'s records in Vulnogram before anything else.

| Exit | Meaning | Next |
|---|---|---|
| 0 | The first stdout line is the `CVE-YYYY-NNNNN` | Step 4 with that ID; no paste-back needed |
Expand Down
20 changes: 19 additions & 1 deletion plugins/magpie-security/skills/issue-sync/apply-and-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ When the state fetch fails, pass `fetched_state: "unknown"`.
or extract it from the body via `awk` between the
`<!-- generate-cve-json: cve=<CVE> version=v1 -->` / `<!-- generate-cve-json:end ... -->` markers —
the generator is deterministic, so both yield the same bytes.
Conventional path: `<scratch>/cve-<CVE-ID>-<N>.json`.
Conventional path: `<scratch>/cve-<CVE-ID>-<N>.json`, or `<workspace>/cve-<CVE-ID>-<N>.json` for the vetted push in step 3, which reads only the workspace.
`<scratch>` is the session scratch directory as an absolute path (fall back to `$TMPDIR`); `gh` may run outside the sandbox, where `$TMPDIR` differs, so pass it absolute paths.

3. **Push the update through the adapter's `push_update` method**
Expand All @@ -491,6 +491,24 @@ When the state fetch fails, pass `fetched_state: "unknown"`.
--cve-id <CVE-ID> --json-file <scratch>/cve-<CVE-ID>-<N>.json
```

**Under the secure setup**, when the vetted-ops policy grants `security-issue-sync` the `cve-record-update` operation,
push through it instead, with the JSON at `<workspace>/cve-<CVE-ID>-<N>.json` (the vetted-ops policy's `workspace`):

```bash
uvx --from ~/.claude/magpie/vetted-ops vetted-op --caller security-issue-sync cve-record-update <CVE-ID> <workspace>/cve-<CVE-ID>-<N>.json
```

It runs the same Vulnogram push with a fixed argv and no override flag
([vetted-ops § *The Vulnogram CVE-tool operations*](../../../../tools/vetted-ops/README.md#the-vulnogram-cve-tool-operations)),
so it covers every push above except three, which keep the `cve-tool push` command:
a JSON whose `CNA_private.state` is `PUBLIC` while the live record is not (the vetted push never promotes a record to `PUBLIC`),
and the two overrides below.
When the client fails, `vetted-op` exits 4 and names the client's own code on stderr (`CVE tool exit N`), which reads as the `cve-tool push` exit `N`;
an exit 3 whose stderr says the caller `is not permitted to run 'cve-record-update'` means the policy does not grant it: use `cve-tool push`.
Any other exit 2 or 3 is `vetted-op` rejecting the record (a forbidden key, an ID that does not match `<CVE-ID>`) or the arguments:
nothing was pushed, and the push stops there; report the stderr, and never send the same JSON through `cve-tool push` to get past the refusal.
Any other outcome (an interrupted run) may or may not have saved: push again, which the idempotence note below makes safe.

For Vulnogram, the push merges into the live record and refuses to rename an affected product or package.
Two explicit overrides exist; use them only after confirming with the user:

Expand Down
2 changes: 1 addition & 1 deletion plugins/magpie-vetted-ops/tools/vetted-ops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ overrides. Three operations run it instead, outside the sandbox through
|---|---|---|
| `cve-record-fetch` (read) | `cve_id` | `vulnogram-api-record-fetch --cve-id <id>` |
| `cve-record-update` (write) | `cve_id body` | `vulnogram-api-record-update --cve-id <id> --json-file -`, the record on stdin |
| `cve-allocate` (write) | `title` (a workspace file) | `vulnogram-api-allocate --title <title>` |
| `cve-allocate` (write) | `pmc title` (title a workspace file) | `vulnogram-api-allocate --pmc <pmc> --title <title>`; the client refuses a token held for another PMC |

- The client is the copy shipped in this plugin beside vetted-ops
(`tools/cve-tool-vulnogram/oauth-api`, resolved like the tracker backends),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def _validate_params(
resolved[name] = ops_mod.commit_hash(raw)
elif name == "cve_id":
resolved[name] = ops_mod.cve_id(raw)
elif name == "pmc":
resolved[name] = ops_mod.pmc(raw)
elif name == "date":
resolved[name] = ops_mod.date(raw)
elif name == "cursor":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* the client is the copy shipped beside vetted-ops (``tool_dir``), never a path
the agent can write;
* only the CVE id, the record JSON (piped on stdin, the bytes vetted-ops
validated) and the allocation title are the caller's; every override flag
validated), the allocation PMC and the allocation title are the caller's; every override flag
stays off, so the record commands' merge-mode guards always apply;
* the child gets an allowlisted environment (``child_env``): ``HOME`` from the
password database, a fixed ``PATH``, locale and ``TMPDIR`` only. No
Expand Down
14 changes: 12 additions & 2 deletions plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ def cve_id(value: str) -> str:
return _check(_CVE_ID, value, "CVE id")


#: A Vulnogram PMC / committee id (`airflow`, `incubator-foo`): lowercase, no path or flag.
_PMC = re.compile(r"^[a-z][a-z0-9-]{0,63}$")


def pmc(value: str) -> str:
return _check(_PMC, value, "PMC")


#: Top-level keys a CVE record pushed through `cve-record-update` may not carry:
#: Vulnogram reads `go` as a request envelope rather than record content.
_CVE_RECORD_FORBIDDEN_KEYS = frozenset({"go"})
Expand Down Expand Up @@ -3018,12 +3026,14 @@ def _stats_closed_page(cfg: dict[str, str], cursor: str) -> list[str]:
_register(
Op(
name="cve-allocate",
params=("title",),
params=("pmc", "title"),
backend="cve-tool",
writes=True,
summary="Allocate a CVE id for a title through the Vulnogram CVE tool.",
title_files=("title",),
build=lambda cfg, title: cve_tool.argv("vulnogram-api-allocate", "--title", title),
# `--pmc` lets the client refuse a token held for any other PMC, so the
# id is reserved for the PMC the user approved, whatever session is current.
build=lambda cfg, pmc, title: cve_tool.argv("vulnogram-api-allocate", "--pmc", pmc, "--title", title),
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

- `api` (a governance-authorised user, pre-flight `api`): one proposal to
allocate through the CVE tool's API, with the form URL as the fallback and
the one `cve-tool allocate` command to run on a yes.
the one `cve-tool allocate` command to run on a yes. With `vetted_workspace`
(the secure setup's vetted operations), the command is the vetted
`cve-allocate` instead, and `title_file` is the workspace file to write the
title to first.
- `recipe` (authorised, any other pre-flight outcome): open the allocation
URL, paste the title, submit, paste the ID back.
- `relay` (not authorised): a terse request for an authorised member — the
Expand All @@ -32,6 +35,8 @@

from __future__ import annotations

import hashlib
import json
import re
from collections.abc import Mapping, Sequence
from typing import Any
Expand Down Expand Up @@ -78,6 +83,7 @@ def render(data: Mapping[str, Any]) -> dict[str, Any]:
)
block = fence(title)
command = None
title_file = None
if member and (data.get("preflight") or {}).get("path") == "api":
pmc = one_line(data.get("pmc"))
if not pmc:
Expand All @@ -89,7 +95,20 @@ def render(data: Mapping[str, Any]) -> dict[str, Any]:
"This reserves a CVE ID immediately and cannot be undone.\n"
f"(Fallback, if the API path fails: the form at {url}.)\n"
)
command = cve_tool.command(data, "allocate", "--pmc", pmc, "--title", title)
workspace = one_line(data.get("vetted_workspace"))
if workspace:
# The vetted operation reads the title from a workspace file; `pmc` lets the
# client refuse a token held for any other PMC. The file is named by a hash of
# tracker, issue and the approved title, so no other run (another tracker, or
# this issue with another title) writes the same file between the write and
# the allocation; a sanitised slug would not do (`a-b/c` and `a/b-c` collide).
key = hashlib.sha256(json.dumps([tracker, str(data["issue"]), title]).encode()).hexdigest()[:24]
title_file = {"path": f"{workspace.rstrip('/')}/cve-title-{key}.txt", "text": title + "\n"}
command = cve_tool.vetted_command(
"security-cve-allocate", "cve-allocate", pmc, title_file["path"]
)
else:
command = cve_tool.command(data, "allocate", "--pmc", pmc, "--title", title)
elif member:
path = "recipe"
indented = "\n".join(" " + line for line in block.split("\n"))
Expand All @@ -115,6 +134,7 @@ def render(data: Mapping[str, Any]) -> dict[str, Any]:
"path": path,
"text": text,
"command": command,
"title_file": title_file,
"governance_member_path": member,
"relay_message_present": path == "relay",
"api_allocation_proposed": path == "api",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
STABLE = "~/.claude/magpie/security-tools/cve-tool"
#: Where a framework checkout or snapshot install keeps the tool, run sandboxed.
PROJECT = "<framework>/tools/cve-tool"
#: The vetted-ops link, spelled as the sandbox exclusion matches it.
VETTED_OPS = "~/.claude/magpie/vetted-ops"


def stable_installed() -> bool:
Expand All @@ -64,3 +66,16 @@ def command(data: Mapping[str, Any], operation: str, *args: object) -> str:
return " ".join(("uv run --project", w(str(project)), "cve-tool", operation, *quoted))
# The literal `~`, unquoted: the sandbox exclusion and the `ask` rule match this spelling.
return " ".join(("uvx --from", STABLE, "cve-tool", operation, *quoted))


def vetted_command(caller: str, operation: str, *args: object) -> str:
"""`uvx --from <VETTED_OPS> vetted-op --caller <caller> <operation> <args>`.

The vetted operations (tools/vetted-ops, "The Vulnogram CVE-tool operations")
run the shipped Vulnogram client outside the sandbox with a fixed argv: no
override flag, no other session file. Arguments are shell-quoted here, like
`command`; a value the operation reads from a file (an allocation title, a
record) is passed as that file's workspace path, never inline.
"""
quoted = (shlex.quote(str(arg)) for arg in args)
return " ".join(("uvx --from", VETTED_OPS, "vetted-op --caller", shlex.quote(caller), operation, *quoted))
Loading
Loading