@mharoon07/slopguard
v0.1.1
Published
Zero-config CLI defense against AI package hallucination and slopsquatting
Maintainers
Readme
@mharoon07/slopguard
Zero-config CLI defense and programmatic validation against AI package hallucination and slopsquatting.
Overview
AI coding assistants (ChatGPT, GitHub Copilot, Claude, Cursor, and others) regularly hallucinate non-existent package names when generating code. Threat actors actively monitor these common hallucinations, register the fake package names on npm, and backfill them with malicious payloads—an attack vector known as slopsquatting.
slopguard sits between your AI assistant and your terminal. It verifies package existence, release recency, download velocity, and deprecation status in real time before you execute npm install.
Key Capabilities
- Zero Runtime Dependencies: Built entirely with native Node.js 18+ standard APIs and native
fetch. - High Concurrency: Parallel asynchronous registry queries with built-in in-memory caching and retries.
- AST-Free Heuristic Code Extractor: Safely extracts package names from standard input, markdown snippets, CommonJS
require, and ESMimportdeclarations. - CI/CD Ready: Provides deterministic exit codes and structured
--jsonoutput for automated pipelines. - Dual Interface: Full CLI suite with interactive colored tables and an exportable TypeScript/JavaScript SDK.
Quick Start
Run directly with npx (No installation needed)
# Check one or more package names directly
npx @mharoon07/slopguard check express fake-ai-package-helper
# Scan project dependencies and lockfile
npx @mharoon07/slopguard scan
# Inspect piped AI code or terminal output
cat snippet.ts | npx @mharoon07/slopguard codeInstall globally
npm install -g @mharoon07/slopguardAfter global installation, the binary is available as slopguard:
slopguard check react @tanstack/react-queryInstall locally as a development dependency
npm install --save-dev @mharoon07/slopguardCLI Reference
1. slopguard check <pkg> [pkg2 ...]
Validates one or more package names directly against the npm registry.
slopguard check express lodash hallucinated-package-xyzOutput:
┌────────────┬────────────────────────────┬──────────┬──────────────┬─────────────────────────────────────────────────────────────┐
│ STATUS │ PACKAGE │ AGE │ DOWNLOADS │ DETAILS │
├────────────┼────────────────────────────┼──────────┼──────────────┼─────────────────────────────────────────────────────────────┤
│ CRITICAL │ hallucinated-package-xyz │ n/a │ n/a │ Does not exist on npm (hallucination risk). Do NOT install. │
│ LOW │ express │ 15.9y │ 196.6M/wk │ Established package (active repository, verified) │
│ LOW │ lodash │ 14.5y │ 206.5M/wk │ Established package (active repository, verified) │
└────────────┴────────────────────────────┴──────────┴──────────────┴─────────────────────────────────────────────────────────────┘
Summary: Checked 3 packages: 1 critical, 0 high, 0 medium, 2 low.
Status: FAILED (1 unverified package poses hallucination risk)2. slopguard scan [path]
Scans package.json in the specified directory (defaults to current working directory) for both dependencies and devDependencies. If package-lock.json exists, it evaluates resolved dependency packages while ignoring workspace and link references.
# Scan current repository
slopguard scan
# Scan subfolder or monorepo workspace package
slopguard scan ./packages/api --fail-on high3. slopguard code
Reads source code, markdown snippets, or terminal logs from stdin. Automatically extracts package names from:
- ESM import statements (
import x from "pkg",import "pkg",import("pkg")) - CommonJS require calls (
require("pkg")) - Package manager commands (
npm i pkg,yarn add pkg,pnpm add pkg,bun add pkg)
Automatically ignores relative paths (./, ../), built-in Node.js modules (fs, node:path, etc.), flags, and subpath imports.
# Pipe from file
cat prompt-output.md | slopguard code
# Pipe from clipboard on Linux
xclip -selection clipboard -o | slopguard code
# Pipe from clipboard on macOS
pbpaste | slopguard code
# Pipe from clipboard on Windows PowerShell
Get-Clipboard | slopguard codeRisk Assessment Matrix
| Risk Level | Heuristic Criteria | Action Required |
| :--- | :--- | :--- |
| CRITICAL | Package does not exist on npm (HTTP 404). Prime indicator of AI hallucination. | Abort immediately. Do not install. |
| HIGH | Created less than 30 days ago AND under 500 weekly downloads. High slopsquatting indicator. | Audit source repository and maintainer identity before proceeding. |
| MEDIUM | Created less than 90 days ago, OR under 100 weekly downloads, OR marked deprecated by author. | Proceed with caution; verify package legitimacy. |
| LOW | Established package with proven tenure, download volume, and active maintenance. | Safe to install under standard developer hygiene. |
| UNKNOWN | Registry network timeout, connection dropped, or HTTP 429 rate limit encountered. | Verification incomplete. Never treated as safe. |
CLI Options
| Flag | Description | Default |
| :--- | :--- | :--- |
| --fail-on <level> | Exit with status code 1 if any package meets or exceeds the specified level (critical, high, medium, low). | high |
| --json | Output findings in machine-readable JSON format. | false |
| --no-color | Suppress ANSI terminal formatting. Also respects NO_COLOR=1. | false |
| -h, --help | Show usage documentation and options. | - |
| -v, --version | Display installed binary version. | - |
Exit Codes
| Code | Status | Meaning |
| :--- | :--- | :--- |
| 0 | Clean | All packages evaluated below the configured --fail-on threshold. |
| 1 | Alert | One or more packages met or exceeded the --fail-on risk threshold. |
| 2 | Error | CLI invocation error (missing required arguments, unreadable path, or bad flag). |
CI / GitHub Actions Integration
Prevent untrusted or hallucinated dependencies from entering pull requests by adding a check step to your workflow:
name: Supply Chain Defense
on:
pull_request:
branches: [main]
jobs:
slopguard-audit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Audit dependencies with slopguard
run: npx @mharoon07/slopguard scan --fail-on highProgrammatic API
@mharoon07/slopguard can be consumed as an ES module in TypeScript or JavaScript projects:
import {
checkPackage,
checkPackages,
extractPackages,
assessRisk,
scanDirectory
} from '@mharoon07/slopguard';
// Verify a single package
const result = await checkPackage('express');
console.log(result.level); // 'LOW'
console.log(result.downloads); // e.g. 196600000
// Extract packages from arbitrary code or text
const extracted = extractPackages(`
import { test } from "ai-hallucinated-module";
import react from "react";
`);
console.log(extracted); // ['ai-hallucinated-module', 'react']
// Batch verification with concurrency control
const batchResults = await checkPackages(extracted, { concurrency: 5 });
for (const item of batchResults) {
if (item.level === 'CRITICAL') {
throw new Error(`Hallucinated package detected: ${item.name}`);
}
}Limitations
- Registry Verification Only: Checks existence, age, download metrics, and deprecation metadata. It does not perform static analysis of package source code or ASTs.
- Install Scripts: Does not analyze
preinstallorpostinstallshell script contents. - Complementary Tool: Designed as an initial defense perimeter to block hallucinated packages before package managers download them. It complements, but does not replace, CVE scanners such as
npm audit.
License
MIT © Slopguard Contributors
