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
- Manual Resolution: Dependencies are NOT pre-resolved in requirements.txt
- Dependency Resolution: PMG must resolve transitive dependencies for each package
- Full Analysis: Analyze all resolved packages in the dependency tree
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
Strategy 2: Manifest File Resolution
npm/pnpm Ecosystem (Pre-resolved Dependencies):- 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
Technical Implementation Details
Lockfile Format Support: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
Behavioral Analysis
- Static analysis of package contents
- Detection of suspicious code patterns
- Identification of obfuscated malicious code
Name-based Detection
- Typosquatting pattern recognition
- Dependency confusion attack detection
- Suspicious naming convention analysis
Supported Ecosystems & Limitations
Currently Supported
Node.js Ecosystem
npm and pnpm - Full protection for JavaScript packages from npmjs.org
Python Ecosystem
pip - Protection for PyPI packages and dependencies
Registry Scope Limitations
PyPI Focus: For Python packages, pmg currently only analyzes packages from the PyPI registry. Packages installed from:- 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
Performance Characteristics
PMG introduces minimal latency through:- 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
Operating Modes
PMG supports different operational modes for various scenarios:Integration Patterns
Development Environment Integration
Security 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

