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
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,45 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

### Fixed

- **The install-gate recognised one repo-argument form; the tool publishes two** (#507).
`ownerRepoArg` matched `^[\w.-]+/[\w.-]+$` — one slash, no scheme — so the payload of a
repo-fetching installer was triaged only when the argument happened to be written as
`owner/repo`. Measured against 6.7.0, with `npm install left-pad` still blocking as a control:

```
npx skills add cursor/plugins → BLOCKED
npx skills add https://github.com/cursor/plugins --skill unslop → allowed
npx skills add github.com/cursor/plugins → allowed
npx skills add git@github.com:cursor/plugins.git → allowed
```

And the bypass ran through the form the tool's own help recommends — `skills add --help` lists
both `vercel-labs/agent-skills` and `https://github.com/vercel-labs/agent-skills`, so this was
never a latent edge case. The argument is now normalised BEFORE matching (any scheme, an
optional `user@`, a host segment, scp-style `git@host:owner/repo`, a trailing `.git`, and a
deeper `…/tree/main/sub` path all reduce to `owner/repo`) rather than the pattern being
widened, which would have started matching npm scopes and file paths. `@scope/name` is still
not a repo, and neither is a filesystem path — `./local/path/file.txt` used to reduce to
`./local`, which the table test caught.

- **The pip maintainer count was declared unavailable on a claim that was wrong.** The previous
entry said PyPI publishes no maintainer list. Measured, it does: `requests` carries
`maintainer_email = "Ian Stapleton Cordasco <…>, Nate Prewitt <…>"`. Two things still keep it
from being npm's number, and both are now in the output rather than in a comment: PEP 621
leaves `maintainer` null so the value hides in `maintainer_email` (and sometimes only in
`author_email` — `opensandbox-server` had exactly that), and PyPI's list is **self-declared
package metadata** while npm's is the registry's own record of who may publish. So the probe
runs, reports `N declared maintainer(s) in <field> (self-declared package metadata)`, and when
it warns it says outright that this is *not registry publish rights* and *not comparable to
npm's maintainer count*. A package that names nobody still declares the probe unavailable —
with an accurate reason this time.

Consequence, measured: `pip opensandbox-server` goes from `100/100` with a partial-coverage
note to `88/100` with a single-maintainer warning — the same reason npm's packages scored 88.
Counting is bracket-aware, so `"Cordasco, Ian <one@example>"` is one maintainer, not two.

### Added

- **`[context]` can declare the IDENTITY a repo must use, and kit asserts it** (#503). `kit check`
Expand Down
62 changes: 52 additions & 10 deletions skills/triage/scripts/triage.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
- PASS means the SPECIFIC target — including a pinned version or dist-tag (`name@1.2.3`,
`name@next`, `name==1.2.3`) — EXISTS and clears the health checks: not-found, deprecated,
or yanked is a CRITICAL; newness / abandonment / single-maintainer / no-license are
warnings. npm and pip run the same probe set except maintainer count, which the pip
path declares as unavailable instead of leaving unmentioned. A pinned version is triaged directly, so a clean `latest` never vouches for a
warnings. npm and pip run the same probe set; the maintainer count differs in KIND rather
than presence -- npm reads the registry's publisher list, pip reads self-declared package
metadata (`maintainer_email`, falling back to `author_email`) and says so, or declares the
probe unavailable when the package names nobody. A pinned version is triaged directly, so a clean `latest` never vouches for a
yanked or malicious pinned version.
- PASS is NOT a malware verdict. This gate does no typosquat, install-script, or behavioral
analysis. Deep malware detection is GuardDog (opt-in, separate + heavier: `KIT_GUARDDOG=1`
Expand Down Expand Up @@ -395,6 +397,27 @@ def ok(t):
return cands[-1] if cands else None


def _declared_maintainers(info):
"""Count the maintainers a PyPI package DECLARES, or (None, reason) when it declares none.

Reads `maintainer_email` first (its purpose), falling back to `author_email` (what PEP 621
actually fills in). Counting is bracket-aware: display names may contain commas
("Cordasco, Ian <x@y>"), so `<...>` pairs are counted when present and only a bracket-free
value is split on commas. Returns (count, field_name) or (None, None).
"""
for field in ("maintainer_email", "author_email", "maintainer", "author"):
raw = (info.get(field) or "").strip()
if not raw:
continue
brackets = re.findall(r"<[^<>@\s]+@[^<>\s]+>", raw)
if brackets:
return len(brackets), field
parts = [p.strip() for p in raw.split(",") if p.strip()]
if parts:
return len(parts), field
return None, None


def triage_pip(rep):
pkg, spec = _split_pip_spec(rep.target)
url = f"{PYPI_INDEX}/pypi/{urllib.parse.quote(pkg)}/json"
Expand Down Expand Up @@ -460,14 +483,33 @@ def triage_pip(rep):
if first_days < NEW_DAYS:
rep.warn(f"package is very new ({first_days} days) -- limited track record")

# The one npm probe PyPI cannot answer. `info.maintainer` / `maintainer_email` are
# free-text and usually empty, and the JSON API publishes no maintainer list at all, so
# a count here would be invented. Declared instead of silently skipped.
rep.notchecked(
"maintainer count",
"PyPI's JSON API publishes no maintainer list (info.maintainer is free-text and "
"usually empty), so bus-factor / account-takeover risk was NOT assessed",
)
# Maintainer count. The earlier claim here -- "PyPI publishes no maintainer list" -- was
# wrong, and measured wrong: requests carries
# maintainer_email = "Ian Stapleton Cordasco <...>, Nate Prewitt <...>"
# which is countable. Two caveats decide how it is reported:
# 1. same trap as `author`: `maintainer` is null under PEP 621 and the value lives in
# `maintainer_email`; opensandbox-server had maintainer_email null with one entry in
# author_email, so a counter must weigh both and be able to answer "don't know";
# 2. the SEMANTICS differ from npm's. npm's list is the registry's own -- who may publish.
# PyPI's is self-declared metadata inside the package. Two names in a field are not
# evidence of two accounts with publish rights, so this must not be presented as npm's
# number.
count, source = _declared_maintainers(info)
if count is None:
rep.notchecked(
"maintainer count",
"neither maintainer_email nor author_email names anyone for this package, and "
"PyPI's JSON API does not expose registry publish rights -- bus-factor / "
"account-takeover risk was NOT assessed",
)
else:
rep.fact(f"{count} declared maintainer(s) in {source} (self-declared package metadata)")
if count <= 1:
rep.warn(
f"single declared maintainer in {source} -- bus-factor risk. NOTE: this is "
"self-declared metadata, not registry publish rights; PyPI does not expose who "
"may publish, so it is not comparable to npm's maintainer count"
)


def _owner_repo(target):
Expand Down
77 changes: 77 additions & 0 deletions src/install-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
decideBashGate,
extractCommandFromHookPayload,
explainUnverifiable,
ownerRepoArg,
} from "./install-gate.js";
import type { GateDeps } from "./triage-gate.js";
import type { TriageType } from "./triage.js";
Expand Down Expand Up @@ -1032,3 +1033,79 @@ describe("install-gate — the refusal names the hazard (#501)", () => {
assert.match(v.reason, /cannot reduce to a triage target/);
});
});

/**
* The gate recognised one argument form; the tool documents two.
*
* `skills add --help` lists both `vercel-labs/agent-skills` and
* `https://github.com/vercel-labs/agent-skills`. Measured against 6.7.0: the short form was
* BLOCKED and every equivalent spelling went through — so the bypass ran through the invocation
* the tool's own help recommends (#507). The fix normalises before matching; a looser regex
* would start matching npm scopes and file paths, and the defect was never strictness.
*/
describe("install-gate — repo argument forms (#507)", () => {
it("reduces every equivalent spelling to owner/repo", () => {
const cases: Array<[string, string | null]> = [
["cursor/plugins", "cursor/plugins"],
["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/cursor/plugins", "cursor/plugins"],
["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/cursor/plugins", "cursor/plugins"],
["github.com/cursor/plugins", "cursor/plugins"],
["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/cursor/plugins.git", "cursor/plugins"],
["git@github.com:cursor/plugins.git", "cursor/plugins"],
["git@github.com:cursor/plugins", "cursor/plugins"],
["ssh://git@github.com/cursor/plugins.git", "cursor/plugins"],
["git+https://github.com/cursor/plugins.git", "cursor/plugins"],
["https://gitlab.example.com/cursor/plugins", "cursor/plugins"],
["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/cursor/plugins/", "cursor/plugins"],
// A deeper URL still names the repo that gets fetched.
["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/cursor/plugins/tree/main/unslop", "cursor/plugins"],
];
for (const [input, expected] of cases) {
assert.equal(ownerRepoArg(input), expected, input);
}
});

it("still refuses what is not a repo reference", () => {
for (const input of [
"@scope/name", // npm scope
"left-pad", // bare npm name
"/cursor", // one segment
"github.com", // host only
"--skill", // a flag
"", // nothing
"./local/path/file.txt", // a filesystem path, not a repo
"../sibling/repo",
"~/notes/file.md",
"/abs/path/thing",
]) {
assert.equal(ownerRepoArg(input), null, input);
}
});

it("every form yields the same github: ref through the real parser", () => {
const forms = [
"npx skills add cursor/plugins",
"npx skills add cursor/plugins --skill unslop",
"npx skills add https://github.com/cursor/plugins --skill unslop",
"npx skills add github.com/cursor/plugins",
"npx skills add git@github.com:cursor/plugins.git",
"npx skills add ssh://git@github.com/cursor/plugins.git",
"npx skills add https://github.com/cursor/plugins/tree/main/unslop",
];
for (const cmd of forms) {
const probe = parseInstallCommand(cmd);
assert.ok(
probe.refs.some((r) => String(r).includes("github:cursor/plugins")),
`${cmd} — the repo payload must be triaged, not just the wrapper package`,
);
}
});

it("an npm scope passed to the fetcher does not become a repo ref", () => {
const probe = parseInstallCommand("npx skills add @scope/name");
assert.equal(
probe.refs.some((r) => String(r).startsWith("github:")),
false,
);
});
});
55 changes: 52 additions & 3 deletions src/install-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,59 @@ function hasExecCallFlag(tokens: string[]): boolean {
*/
const REPO_FETCHER_PACKAGES = new Set(["skills"]);

/** `owner/repo` shape — no npm scope (`@scope/name`), no scheme, no protocol. */
function ownerRepoArg(tok: string): string | null {
/**
* Reduce every spelling of a repo argument to `owner/repo`, or null when the token is not one.
*
* The gate recognised ONE form and the tool documents two. `skills add --help` lists both
* `vercel-labs/agent-skills` and `https://github.com/vercel-labs/agent-skills`, and measured
* against 6.7.0 the short form was BLOCKED while every equivalent form went through:
*
* npx skills add cursor/plugins → BLOCKED
* npx skills add https://github.com/cursor/plugins → allowed
* npx skills add github.com/cursor/plugins → allowed
* npx skills add git@github.com:cursor/plugins.git → allowed
*
* So the bypass ran through the invocation the tool's own help recommends. The fix normalises
* BEFORE matching rather than widening the pattern: a looser regex would start matching npm
* scopes and file paths, and the defect was never that the pattern was too strict — it was that
* one form was implemented and its equivalents were not.
*
* Deliberately kept out: `@scope/name` (an npm package, not a repo) and anything that does not
* reduce to exactly two path segments after the host.
*/
export function ownerRepoArg(tok: string): string | null {
if (!tok || tok.startsWith("-")) return null;
if (tok.startsWith("@")) return null; // npm scope, not a repo
return /^[\w.-]+\/[\w.-]+$/.test(tok) ? tok : null;
// A filesystem path is not a repo reference. Without this, `./local/path/file.txt` reduced to
// `./local` — caught by the table test, and exactly the kind of over-eager match that
// widening the regex would have produced everywhere.
if (/^[./~]/.test(tok)) return null;

let t = tok.trim();
// scp-style SSH: git@host:owner/repo(.git) — the colon separates host from path.
const scp = /^[\w.-]+@([\w.-]+):(.+)$/.exec(t);
if (scp) {
t = scp[2];
} else {
// Any scheme (https, http, ssh, git, git+ssh) plus optional user@host, then the path.
t = t.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").replace(/^[\w.-]+@/, "");
// A leading host segment: something with a dot (github.com, gitlab.example.com) or
// localhost, optionally with a port. Bare `owner/repo` has neither and is left alone.
t = t.replace(/^(?:localhost|[\w-]+(?:\.[\w-]+)+)(?::\d+)?\//, "");
}

t = t
.replace(/\.git$/, "")
.replace(/^\/+/, "")
.replace(/\/+$/, "");
const parts = t.split("/").filter(Boolean);
// Exactly two segments. A deeper URL (…/tree/main/sub) still names the repo it fetches, so
// the first two win; a single segment is not a repo reference.
if (parts.length < 2) return null;
const [owner, repo] = parts;
if (owner.startsWith("@")) return null;
if (owner === "." || owner === ".." || repo === "." || repo === "..") return null;
return /^[\w.-]+$/.test(owner) && /^[\w.-]+$/.test(repo) ? `${owner}/${repo}` : null;
}

/**
Expand Down
Loading
Loading