The Problem: Growing Supply Chain Threats
The open source ecosystem faces increasing threats from bad actors who publish malicious packages to popular repositories like npm, PyPI, and others. These threats include:Common Attack Vectors
- Typosquatting attacks where malicious packages mimic popular library names
- Dependency confusion attacks targeting private package names
- Supply chain compromises where legitimate packages are hijacked
- Malicious packages designed to steal credentials or inject backdoors
Current Detection Gaps
Traditional security approaches only detect these threats after packages are already installed, often too late to prevent damage. Most development teams rely on:- Manual package review processes that don’t scale
- Post-installation vulnerability scanning that misses many threats
- Static analysis tools that run after packages are already in the codebase
- Security policies that developers may forget to follow
The PMG Solution: Real-Time Protection
PMG (Package Manager Guard) solves the problem of malicious package installation by providing real-time protection at the package manager level. It intercepts package installation commands and blocks malicious packages before they can be installed.Real-Time Protection
Block malicious packages before they’re installed in your environment
Zero Configuration
Works immediately without any setup or configuration changes
Seamless Integration
Transparent wrapper that works with your existing package managers
Threat Intelligence
Powered by SafeDep Cloud’s continuously updated threat database
Key Benefits
- Proactive Security: Stop threats before they enter your environment
- Zero Friction: No changes to your development workflow
- Real-Time Intelligence: Protection updates automatically as new threats are discovered
- Deep Analysis: Scans transitive dependencies to catch hidden threats
- Developer Focused: Minimal interruption for legitimate development work
Why Now?
The threat landscape for software supply chains has evolved dramatically:- Scale of attacks: Thousands of malicious packages published monthly
- Sophistication: Advanced techniques like dependency confusion
- Impact: Major breaches affecting enterprise and government systems
- Speed: Attacks spread faster than traditional detection methods
About PMG
SafeDep PMG is a free and open source Package Manager Guard that protects developers from malicious packages by wrapping your favorite package managers and blocking dangerous packages at install time.Architecture Overview
PMG operates through two primary installation workflows, each with distinct dependency resolution strategies:Workflow 1: Direct Package Installation
When users install individual packages directly:- Command Interception: PMG intercepts the package manager command
- Dependency Resolution: PMG resolves all transitive dependencies for the requested package
- Threat Analysis: All packages in the dependency tree are analyzed for malware
- Installation Decision: Clean packages proceed to installation, malicious packages are blocked
Workflow 2: Manifest File Installation
When users install from manifest files:- Lockfile Analysis: Dependencies are already resolved in lockfiles (package-lock.json, pnpm-lock.yaml)
- Direct Analysis: PMG analyzes the pre-resolved dependency list
- No Resolution Needed: Skip dependency resolution step
- Efficient Processing: Faster analysis due to pre-resolved state
- Manual Resolution: Dependencies are NOT pre-resolved in requirements.txt
- Dependency Resolution: PMG must resolve transitive dependencies for each package
- Version Constraint Handling: Processes version specifiers (>=, ==, ~=, etc.)
- Complete Tree Building: Builds full dependency tree similar to direct installs
Core Technical Components
1. Command Interception Layer
PMG creates intelligent aliases for supported package managers:- Shell alias creation for transparent command wrapping
- Cross-shell compatibility (bash, zsh, fish)
- Argument parsing and forwarding to maintain compatibility
2. Dependency Resolution Engine
PMG employs different dependency resolution strategies based on the installation method: Strategy 1: Direct Package Installation Resolution For direct package installations (npm install express, pip install requests):
- PMG queries package registries to build complete dependency tree
- Applies semantic versioning rules to resolve version ranges
- Considers peer dependencies and optional dependencies
- Builds complete manifest of all packages that would be installed
- Lockfile Parsing: Dependencies already resolved with exact versions
- Direct Analysis: PMG reads resolved dependency list from lockfiles
- No Version Resolution: Skip dependency resolution since versions are locked
- Efficient Processing: Faster analysis due to pre-resolved state
- Manual Resolution Required: requirements.txt contains only direct dependencies
- Transitive Resolution: PMG must resolve all transitive dependencies
- Version Constraint Handling: Processes version specifiers (>=, ==, ~=, etc.)
- Complete Tree Building: Builds full dependency tree similar to direct installs
package-lock.jsonpnpm-lock.yaml(pnpm)- Future:
yarn.locksupport planned
- Approximate Version Resolution: Intelligently resolves version ranges (e.g.,
^1.2.0) - Semver Compatibility: Understands semantic versioning rules
- Peer Dependency Analysis: Considers peer dependency requirements
- Lock File Interpretation: Respects existing lock file constraints
3. Threat Detection System
PMG employs multiple detection mechanisms: Malicious Package Database- Continuously updated database of known malicious packages
- Real-time scanning of new packages as they’re published
- Community-driven threat intelligence sharing
- Static analysis of package contents
- Detection of suspicious code patterns
- Identification of obfuscated malicious code
- Typosquatting pattern recognition
- Dependency confusion attack detection
- Suspicious naming convention analysis
Supported Ecosystems & Limitations
Currently SupportedNode.js Ecosystem
npm and pnpm - Full protection for JavaScript packages from npmjs.org
Python Ecosystem
pip - Protection for PyPI packages and dependencies
- Git URLs (
pip install git+https://...) - Local file paths (
pip install ./local-package) - Private registries (
pip install -i private-index) - Alternative indexes (
--extra-index-url)
Technical Considerations
Version Resolution Accuracy PMG must make intelligent approximations about final package versions since it operates before package manager execution: Challenges:- Complex dependency resolution algorithms vary between package managers
- Version ranges can resolve differently based on existing dependencies
- Lock file states affect final resolution
- Implements heuristic-based resolution that mirrors package manager behavior
- Prioritizes security over perfect version matching
- Continuously improves resolution accuracy based on real-world usage
- Network Requests: API calls to SafeDep Cloud for threat intelligence
- Dependency Computation: Local dependency tree analysis
- Threat Evaluation: Package risk assessment
- Intelligent caching of threat intelligence data
- Parallel dependency analysis where possible
- Minimal network overhead through efficient API design
Integration Patterns
Development Environment IntegrationSecurity Model
PMG operates on a default-deny security model for known threats:- Known malicious packages: Blocked immediately with detailed warnings
- Suspicious packages: Prompt for user confirmation with a detailed report link for review
- Verified clean packages: Allowed without interference

