Repository navigation
feat(tools): verify_package — registry existence check before installs (anti-slopsquatting) - #153
Merged
Merged
Conversation
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
🔍 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
added a commit
that referenced
this pull request
Oct 1, 2026
This was referenced Oct 2, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).{ecosystem: "crates"|"npm", name, exact?}; ReadOnly risk = always callable, zero approval friction; the actual install still flows through the normal Write gate.status: "rate_limited", verdict "unknown — DO NOT treat as nonexistent". An unknown is never reported as "not found" (404 alone producesexists: false).typo_squat_warning.-rejected,..rejected,@scope/pkgsupported, URL-encoded per segment) — malformed names fail loudly as errors, never as a verdict.Err(StatusCode(code))and are unwrapped into verdicts, not treated as transport failures (found by the mock tests, not by reading docs).verify_packagebefore anycargo add/bun add/npm install.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)
rate_limited(assertsexistsis ABSENT), scoped-npm not-found → bare-name candidate via the SAME base override (a real bug the mock caught: the probe ignored the override).--workspace --all-targets -- -D warningsclean; fmt clean.serde→ exists 1.0.229,left-pad→ exists 1.3.0, hallucinated names → honest verdicts; burst-rate throttling correctly surfaced asrate_limited(the honesty contract working, not a failure).--no-verifyper the documented workaround; CI Cora Review is the gate for this PR.