Stops malicious PyPI packages before installation
Project description
pip-guardian
pip-guardian is a security gate in front of pip install to reduce PyPI supply-chain risk.
Why this exists
Package ecosystems are a common attack path. pip-guardian checks package metadata and distribution contents before install, then decides ALLOW, WARN, or BLOCK.
Feature set
1) Pre-install risk policy
- Version age rules:
- block if version is very new (default
< 5h) - warn if version is recent (default
< 48h)
- block if version is very new (default
- Blocks yanked releases.
- Blocks known-compromised versions from local blocklist.
- Blocks maintainer identities from local blocklist.
2) Deep artifact scanning
- Downloads wheel/sdist artifacts from PyPI before install.
- Verifies artifact SHA256 against PyPI metadata.
- Static scan heuristics for:
- executable
.pthstartup hooks sitecustomize.py/usercustomize.py- obfuscated payload patterns (e.g., long base64 + dynamic execution)
- credential-exfiltration-like behavior
- persistence indicators (e.g., systemd artifacts)
- Kubernetes lateral-movement indicators
- executable
3) Built-in incident guard (LiteLLM March 2026)
- Blocks:
litellm==1.82.7litellm==1.82.8
- Runbook:
docs/INCIDENT_LITELLM_2026.md
4) CI-friendly JSON mode
--jsonemits one machine-readable JSON object.--yesallows non-interactive proceed onWARN.- Exit codes:
0install succeeded1blocked, warn-not-confirmed, or pip install failure2usage/argument errors
5) Logging
- Decision logs written as JSONL.
- Primary path:
~/.pip_guardian/guardian.log - Fallback path (if home not writable):
./.pip_guardian/guardian.log
Installation
Not published on PyPI yet.
Install from source:
git clone https://github.com/AnantDhavale/pip-guardian.git
cd pip-guardian
pip install .
Usage
guardian install requests
guardian install litellm==1.82.8
guardian install fastapi --index-url https://pypi.org/simple
guardian install requests --json --yes
Policy and IOC files
policies/config.yaml:- age thresholds
- deep-scan score thresholds
- executable
.pthblocking toggle
policies/blocklist.json:- package/version deny list
- maintainer deny list
Repository structure
guardian/cli.py- command entrypointguardian/policy_engine.py- risk decision logicguardian/scanner.py- deep artifact scanningguardian/pypi_checker.py- PyPI metadata collectionguardian/logger.py- local decision logging
Notes
- This reduces risk but is not a full malware sandbox.
- For production, use pinned dependencies and hash-locked installs.
Author
Anant Dhavale
anantdhavale@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pip_guardian-1.0.0.tar.gz.
File metadata
- Download URL: pip_guardian-1.0.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11759a71a3944fe1a5b81da2543405f3331ab5069cfa9907eebc2853972c8af2
|
|
| MD5 |
f2ec3fefb42b38b47626c317bb605dae
|
|
| BLAKE2b-256 |
8b05dc46b28c9ad460399273270798120060457c9128ae755b379d8f1bb37996
|
Provenance
The following attestation bundles were made for pip_guardian-1.0.0.tar.gz:
Publisher:
python-publish.yml on AnantDhavale/pip-guardian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pip_guardian-1.0.0.tar.gz -
Subject digest:
11759a71a3944fe1a5b81da2543405f3331ab5069cfa9907eebc2853972c8af2 - Sigstore transparency entry: 1226313939
- Sigstore integration time:
-
Permalink:
AnantDhavale/pip-guardian@8b12f038d8b9e31aeefca5ffc01992211a428be9 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/AnantDhavale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8b12f038d8b9e31aeefca5ffc01992211a428be9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pip_guardian-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pip_guardian-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
063c5bbc376a7e63534d1b84285835120b68cfb81a29ebc017236107e35d5050
|
|
| MD5 |
3e311cc229d22e4872d1c200d7deee8e
|
|
| BLAKE2b-256 |
ecdab58aa5ca72c442cebea7033bdb66c1142da08a8ec03409fb03a80cfa2a44
|
Provenance
The following attestation bundles were made for pip_guardian-1.0.0-py3-none-any.whl:
Publisher:
python-publish.yml on AnantDhavale/pip-guardian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pip_guardian-1.0.0-py3-none-any.whl -
Subject digest:
063c5bbc376a7e63534d1b84285835120b68cfb81a29ebc017236107e35d5050 - Sigstore transparency entry: 1226313981
- Sigstore integration time:
-
Permalink:
AnantDhavale/pip-guardian@8b12f038d8b9e31aeefca5ffc01992211a428be9 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/AnantDhavale
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8b12f038d8b9e31aeefca5ffc01992211a428be9 -
Trigger Event:
release
-
Statement type: