Skip to content

feat(tools): verify_package — registry existence check before installs (anti-slopsquatting) - #153

Merged
ajianaz merged 3 commits into
developfrom
feat/verify-package-tool
Oct 1, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/verify-package-tool

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

What (description of the change)

New ReadOnly tool verify_package (#144): checks a package name against the crates.io / npm registry before the model runs any install command — the slopsquatting defense (models hallucinate package names; attackers pre-register them with malware; research numbers: 43% of hallucinated names recur across runs, 13% differ by one character from a real package).

  • Schema {ecosystem: "crates"|"npm", name, exact?}; ReadOnly risk = always callable, zero approval friction; the actual install still flows through the normal Write gate.
  • Honesty contract: 429/5xx/network errors → status: "rate_limited", verdict "unknown — DO NOT treat as nonexistent". An unknown is never reported as "not found" (404 alone produces exists: false).
  • Typo-squat signal: not-found (or non-exact exists) pulls registry candidates; any candidate within edit distance 1 raises an explicit typo_squat_warning.
  • Name validation up front (charset allowlist, leading - rejected, .. rejected, @scope/pkg supported, URL-encoded per segment) — malformed names fail loudly as errors, never as a verdict.
  • ureq 3 semantics handled correctly: 4xx/5xx arrive as Err(StatusCode(code)) and are unwrapped into verdicts, not treated as transport failures (found by the mock tests, not by reading docs).
  • User-Agent set on every request (crates.io policy).
  • The default system prompt (both feature profiles) now instructs: verify a package with verify_package before any cargo add / bun add / npm install.
  • Zero new dependencies (ureq 3 + json feature already in the workspace).

Why (the problem you're solving)

Slopsquatting is the newest supply-chain class in the agentic era. tole is positioned as the trust-first harness; shipping the check as a first-class ReadOnly tool makes the safe path the cheap path — no approval-gate friction pushing the model to route around, unlike gating installs directly.

Testing (how you verified this works)

  • 11 unit tests: name validation shapes, URL encoding, edit-distance cap, spec truth (advertises exactly what execute reads), malformed-name loud failure.
  • 4 deterministic mock-server tests (local TcpListener + base_override): exists+version, 404+typo-squat warning, 429 → honest rate_limited (asserts exists is ABSENT), scoped-npm not-found → bare-name candidate via the SAME base override (a real bug the mock caught: the probe ignored the override).
  • Suites: workspace 265 passed / 0 failed; mobile lib 69/69; clippy --workspace --all-targets -- -D warnings clean; fmt clean.
  • Live E2E against both real registries (release binary, model-driven): serde → exists 1.0.229, left-pad → exists 1.3.0, hallucinated names → honest verdicts; burst-rate throttling correctly surfaced as rate_limited (the honesty contract working, not a failure).
  • Local cora pre-commit hung in its LLM retry loop (known pattern) — committed --no-verify per the documented workaround; CI Cora Review is the gate for this PR.

ReadOnly tool that checks a package name against crates.io / npm
before the model runs any install command — the slopsquatting defense.
Not-found answers include registry candidates; a candidate within edit
distance 1 raises an explicit typo-squat warning (13% of hallucinated
names are one character from a real package); 429/5xx honestly report
rate_limited instead of a fake 'not found'. The default system prompt
tells the model to verify before installing. Zero new deps (ureq 3
already in the workspace); deterministic mock-server tests cover
exists / 404+typo-squat / 429 / scoped-npm paths; live E2E verified
against both real registries.

Closes #144
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

.iter()
.filter(|c| {
edit_distance_capped(name.trim_start_matches('@'), c.trim_start_matches('@')) <= 1
})
The CodeCora check caught a real spec bug: exact=false never fetched
candidates when the name existed (silent no-op vs the advertised
behavior), while exact=true still returned candidates on a not-found.
Now: exact=false always searches; a not-found searches regardless of
exact; exact=true + exists skips the search. Regression test covers
the exact=false path (previously untested).
@ajianaz
ajianaz merged commit 0fb1f9a into develop Oct 1, 2026
16 checks passed
@ajianaz
ajianaz deleted the feat/verify-package-tool branch October 1, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants