Metadata-Version: 2.4
Name: slopguardian
Version: 0.1.0
Summary: A supply-chain sanity check for requirements.txt: catches slopsquatting (AI-hallucinated dependency names), known CVEs, and typosquats against PyPI, plus optional cryptographic hash-pinning.
Author: dc
License: MIT
Project-URL: Homepage, https://github.com/SIMILY00/slopguardian
Keywords: security,supply-chain,slopsquatting,typosquatting,pypi,sca,dependency-confusion
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Security
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Environment :: Console
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31.0
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"
Dynamic: license-file

# slopguardian

A supply-chain sanity check for `requirements.txt`, aimed specifically at
**slopsquatting** -- attackers pre-registering package names that LLMs are
known to hallucinate, so that an AI-written dependency file or a
copy-pasted AI code suggestion installs a malicious package instead of
failing with "not found." Maps to
[OWASP LLM03: Supply Chain Vulnerabilities](https://genai.owasp.org/llm-top-10/).

Run it **before** `pip install -r requirements.txt`, not after -- the
whole point is to catch a problem before anything gets installed, not to
audit an install that already happened.

## Why

LLM-assisted coding tools sometimes hallucinate plausible-but-nonexistent
package names. Attackers have caught on and now pre-register those exact
names on PyPI with malicious payloads, betting that someone will
copy-paste an AI-written `requirements.txt` or install suggestion without
checking it first. This is a real, currently-discussed attack class (see
the [Wikipedia entry on slopsquatting](https://en.wikipedia.org/wiki/Slopsquatting)),
and it's a different problem from classic typosquatting: the victim isn't
mistyping a name, a *tool* generated a name that happens to already exist
on the registry, planted there by someone else.

## What it checks

Using PyPI's public JSON API only -- no auth, no extra dependency beyond
`requests`:

1. **Exists** -- does this name resolve on PyPI at all? A hallucinated
   name nobody has squatted yet fails here loudly, which is what you
   *want* to see.
2. **Age** -- how long has the earliest release existed? A package
   central to some ecosystem but "first published" a few weeks ago is a
   red flag.
3. **Release count** -- a single-release package claiming to be a
   mature, widely-depended-on library is suspicious on its own.
4. **Known CVEs** -- PyPI surfaces [OSV.dev](https://osv.dev/) vulnerability
   data directly in the same JSON API; a version-specific check is
   essentially free to add. This is a *different* problem from
   slopsquatting -- "is this the real package, but with a known hole in
   it" rather than "is this the real package at all" -- included because
   it's the other half of what a real SCA (software composition
   analysis) tool like Dependabot or `pip-audit` checks for.
5. **Name similarity** -- is this name suspiciously close to a real,
   widely-depended-on package (`reqeusts` vs `requests`)? Runs
   *regardless* of the candidate's age or release count, unlike checks 2
   and 3 -- deliberately, because an attacker who registers a name and
   just waits out the age threshold defeats those two entirely.

Everything above is identity/reputation checking -- it answers "should I
trust installing this," at a point in time, before you commit to it. It
does **not** protect you after that: nothing stops the same version
number being served with different bytes on a future request (index
compromise, a malicious mirror, a MITM), because none of it is
cryptographic.

`--generate-lock` closes that specific gap: it writes a
`requirements.lock.txt` with a sha256 digest per package, pulled from
PyPI's own recorded hash for the exact version you have installed right
now. From then on, `pip install --require-hashes -r requirements.lock.txt`
has pip itself refuse to install anything whose downloaded bytes don't
match -- a cryptographic integrity check, not a heuristic one.

## Install

```bash
git clone https://github.com/SIMILY00/slopguardian.git
cd slopguardian
pip install .
```

This installs a `slopguardian` command. If you'd rather not install
anything, `pip install -r requirements.txt` and run `python slopguardian.py`
directly instead.

## Usage

```bash
slopguardian                    # check requirements.txt (by name only)
slopguardian --installed        # check everything actually installed (full transitive tree, by name+version)
slopguardian --generate-lock    # write requirements.lock.txt with sha256 hashes for --require-hashes
```

Example output:

```
Checking the 6 packages listed directly in requirements.txt (NOT their transitive dependencies -- run with --installed for that) against PyPI...

  [OK         ] requests             first published 2011-02-13, 148 releases -- Python HTTP for Humans.
  [CRITICAL   ] reqeusts             does not exist on PyPI. If `pip install` for this ever succeeds, it means someone registered it after this check -- do NOT install without manually verifying the publisher first.
  [VULNERABLE ] pyyaml==5.1          1 known vulnerability/ies: PYSEC-2020-176. Fixed in: 5.2b1.
  [REVIEW     ] httpx2               first published only 43 days ago, BUT shares a publisher identity with established package 'httpx' -- looks like a legitimate versioned rewrite. Author fields are self-reported and not cryptographically verified, so this is corroborating evidence, not proof; a human should still glance at it.

4 package(s) need a manual look before you trust this environment. See above.
```

Exit code is non-zero if anything needs a look, so it's usable as a CI
gate.

## Status meanings

| Status | Meaning |
|---|---|
| `OK` | Established, multi-release, no known vulnerabilities, no name-similarity flag. |
| `REVIEW` | Looks new/low-release-count, but corroborated as a likely legitimate versioned rewrite by shared publisher identity. Still worth a glance. |
| `SUSPICIOUS` | New, low release count, or name-similar to a popular package, with no corroborating signal. Verify the publisher and read the source before trusting it. |
| `VULNERABLE` | A disclosed, unpatched CVE/GHSA/PYSEC advisory exists for this exact version. |
| `WARN` | The package exists on PyPI but this exact version, or any release files at all, can't be found there -- was it yanked, or did it come from somewhere other than PyPI? |
| `CRITICAL` | This name does not exist on PyPI at all. |
| `ERROR` | A network error prevented checking this package -- fails closed (counts as "bad") rather than silently skipping it. |

## Limitations

This is a heuristic triage tool where it *is* heuristic (identity, age,
publisher-matching), and it says so plainly rather than overselling
itself:

- **A patient attacker can still win.** Someone who registers a name,
  waits past the age threshold, and publishes a few clean releases
  before striking will not be caught by the age/release-count checks --
  and won't be caught by the name-similarity check either if the name
  isn't close to anything on the curated popular-package list.
- **Publisher-identity corroboration is not cryptographic.** It compares
  a self-reported PyPI account field (`author_email`/`author`), which
  anyone can set to anything. It's a corroborating signal, not proof --
  a production version of this tool would want something like
  [Sigstore/PEP 740](https://peps.python.org/pep-0740/) attestation
  checking instead.
- **CVE data only covers disclosed vulnerabilities in legitimate code**,
  not intentionally malicious code inserted by an attacker -- which is
  the more common shape of an actual slopsquatting payload. A clean
  `VULNERABLE`-free result is not a guarantee of safety.
- **Hash-pinning only protects going forward.** `--generate-lock`
  cryptographically locks in whatever you have installed *right now* --
  it can't tell you whether that was already compromised before you
  generated the lock file.

Verifying the maintainer identity and reading the source for anything
this tool flags is still on you.

## Testing

```bash
pip install -e ".[test]"
pytest -v
```

Most tests use mocked PyPI responses so they're fast and deterministic; a
handful make one real network call to PyPI as a smoke test that the
tool's JSON parsing still matches PyPI's actual current response shape
(see their docstrings for which, and why).

## Origin

This tool started as one component inside a larger project,
agentic-security-lab (not public yet)
-- a multi-agent + RAG assistant built specifically to be attacked, with
a real containerized tool-execution sandbox, prompt-injection and
data-poisoning red-teaming, and a write-up mapped to the OWASP LLM Top 10
and the NIST AI Risk Management Framework. It was pulled out into its own
repo because a supply-chain checker is useful independent of that
project -- and because a small, focused repo is easier for someone
searching for exactly this kind of tool to find and trust than something
buried inside a larger demo.

## License

MIT -- see `LICENSE`.



