2025-05-15 16:50:59 +05:30
# Package Manager Guard (PMG)
2025-05-15 21:34:41 +05:30
<p>
Created and maintained by <b><a href="https://safedep.io/">https://safedep.io</a></b> with contributions from the community 🚀
</p>
[](https://goreportcard.com/report/github.com/safedep/pmg)


[](https://api.securityscorecards.dev/projects/github.com/safedep/pmg)
[](https://github.com/safedep/pmg/actions/workflows/codeql.yml)
2025-05-15 16:50:59 +05:30
🤖 PMG protects developers from getting compromised by malicious packages.
See [example ](https://safedep.io/malicious-npm-package-express-cookie-parser/ )
2025-04-23 02:21:44 +05:30
2026-01-08 00:24:18 +05:30
- Wraps your favorite package manager (eg. `npm` , `pnpm` , `pip` and more)
- Blocks malicious packages at install time
- No configuration required, just install and use
- Maintains package installation event log for transparency and audit trail
2025-04-23 02:21:44 +05:30
2026-01-08 00:24:18 +05:30
## PMG in Action
2025-05-15 18:03:46 +05:30
<img src="./docs/assets/pmg-intro.png" width="600" alt="pmg in action">
2026-01-08 00:24:18 +05:30
## TL;DR
2025-05-15 18:03:46 +05:30
2026-01-08 00:24:18 +05:30
Install `pmg` using Homebrew:
2025-05-15 18:03:46 +05:30
```shell
brew install safedep/tap/pmg
```
2025-05-15 16:50:59 +05:30
2026-01-08 00:24:18 +05:30
**Note** : More [installation options ](#installation ) are available.
Set up `pmg` to protect your development environment from malicious packages:
2025-05-15 16:50:59 +05:30
```
2025-06-24 18:17:06 +05:30
pmg setup install
2025-05-15 16:50:59 +05:30
```
2026-01-09 19:26:48 +05:30
<details>
<summary>Custom config directory</summary>
```bash
PMG_CONFIG_DIR = /path/to/config pmg setup install
```
</details>
The setup command will:
- Create a `~/.pmg.rc` file containing package manager aliases
- Automatically add a source line to your shell configuration files
- Create a default config file. See [config template ](config/config.template.yml )
2025-05-15 16:50:59 +05:30
Continue using your favorite package manager as usual:
2025-05-15 18:03:46 +05:30
```shell
2025-05-15 16:50:59 +05:30
npm install <package-name>
2025-05-15 18:03:46 +05:30
```
```shell
2025-08-06 21:10:51 +05:30
uv pip install <package-name>
2025-05-15 16:50:59 +05:30
```
2025-04-23 02:21:44 +05:30
2026-01-08 00:24:18 +05:30
## Features
2025-11-05 13:49:19 +05:30
2026-01-08 00:24:18 +05:30
- Malicious package identification using [SafeDep Cloud ](https://docs.safedep.io/cloud/malware-analysis ) with realtime threat detection
- Deep dependency analysis and transitive dependency resolution
- Fast and efficient package verification
- Seamless integration with existing package managers
- Automated shell integration with cross-shell support
- Package installation tracking and event logging
2025-04-23 02:21:44 +05:30
2025-05-15 16:50:59 +05:30
## Supported Package Managers
2025-04-23 02:21:44 +05:30
2025-05-15 16:50:59 +05:30
PMG supports the following package managers:
2026-01-07 13:22:08 +05:30
| Package Manager | Status | Command |
| --------------- | -------- | -------------------------------------------------------- |
2025-11-05 13:49:19 +05:30
| `npm` | ✅ Active | `pmg npm install <package>` |
| `pnpm` | ✅ Active | `pmg pnpm add <package>` |
| `bun` | ✅ Active | `pmg bun add <package>` |
| `yarn` | ✅ Active | `pmg yarn add <package>` |
| `pip` | ✅ Active | `pmg pip install <package>` |
| `uv` | ✅ Active | `pmg uv add <package>` or `pmg uv pip install <package>` |
| `poetry` | ✅ Active | `pmg poetry add <package>` |
2025-05-15 16:50:59 +05:30
> Want us to support your favorite package manager? [Open an issue](https://github.com/safedep/pmg/issues) and let us know!
2025-04-23 02:21:44 +05:30
## Installation
2025-05-15 16:50:59 +05:30
2025-05-15 22:24:02 +05:30
### Homebrew
You can install `pmg` using `homebrew` in MacOS and Linux
```bash
brew tap safedep/tap
brew install safedep/tap/pmg
```
2025-05-15 16:50:59 +05:30
### Binaries
Download the latest binary from the [releases page ](https://github.com/safedep/pmg/releases ).
### Build from Source
2025-04-23 02:21:44 +05:30
> Ensure $(go env GOPATH)/bin is in your $PATH
```bash
2025-04-28 20:02:20 +05:30
go install github.com/safedep/pmg@latest
2025-04-23 02:21:44 +05:30
```
2025-06-24 18:17:06 +05:30
## Setup
PMG provides built-in commands to automatically configure shell aliases for seamless integration:
### Install Aliases
Set up PMG to intercept package manager commands:
```bash
pmg setup install
```
This command will:
2026-01-08 00:24:18 +05:30
- Create a `~/.pmg.rc` file containing package manager aliases
- Automatically add a source line to your shell configuration files
- Supports bash, zsh and fish shell
2025-06-24 18:17:06 +05:30
> **Note**: After running `pmg setup install`, restart your terminal or run `source ~/.zshrc` (or your shell's config file) to activate the aliases.
### Remove Aliases
2025-11-05 13:49:19 +05:30
2025-06-24 18:17:06 +05:30
To remove PMG aliases and restore original package manager behavior:
```bash
pmg setup remove
```
This will:
2026-01-08 00:24:18 +05:30
- Remove the source line from your shell configuration files
- Delete the `~/.pmg.rc` file
2025-06-24 18:17:06 +05:30
2025-07-30 16:42:02 +05:30
> ⚠️ Note: Aliases might still be active in your **current terminal session**. Restart your terminal or use `unalias <cmd>` to remove them instantly.
2025-04-23 02:21:44 +05:30
## Usage
2026-01-08 00:24:18 +05:30
<details>
<summary>Active Scanning</summary>
2025-08-28 20:53:24 +05:30
Use the `--paranoid` flag to perform active malware scanning on unknown packages (requires [SafeDep Cloud credentials ](https://docs.safedep.io/cloud/authentication#api-key-authentication )):
```bash
pmg --paranoid npm install <package-name>
```
2026-01-08 00:24:18 +05:30
</details>
<details>
<summary>Silent Mode</summary>
2025-05-15 16:50:59 +05:30
Use the `--silent` flag to run PMG in silent mode:
```bash
pmg --silent npm install <package-name>
```
2026-01-08 00:24:18 +05:30
</details>
<details>
<summary>Dry Run</summary>
2025-05-16 19:38:06 +05:30
Use the `--dry-run` flag to skip actual package installation. When enabled `pmg` will not execute
package manager commands. Useful for checking packages and their transitive dependencies for malware.
```bash
pmg --dry-run npm install <package-name>
```
2026-01-08 00:24:18 +05:30
</details>
<details>
<summary>Verbose Mode</summary>
2025-05-15 16:50:59 +05:30
Use the `--verbose` flag to run PMG in verbose mode:
```bash
pmg --verbose npm install <package-name>
```
2026-01-08 00:24:18 +05:30
</details>
<details>
<summary>Debugging</summary>
2025-05-15 16:50:59 +05:30
Use the `--debug` flag to enable debug mode:
```bash
pmg --debug npm install <package-name>
```
Store the debug logs in a file:
```bash
pmg --debug --log /tmp/debug.json npm install <package-name>
```
2026-01-08 00:24:18 +05:30
</details>
2025-07-02 19:09:27 +05:30
2026-01-08 00:24:18 +05:30
<details>
<summary>Insecure Installation</summary>
2025-07-02 19:09:27 +05:30
Allows bypassing the blocking behavior when malicious packages are detected during installation.
> ⚠️ **Warning**: This is a security feature bypass. Use with extreme caution and only when you understand the risks.
```bash
export PMG_INSECURE_INSTALLATION = true
pmg npm install <package-name>
```
2026-01-08 00:24:18 +05:30
</details>
2026-01-09 19:26:48 +05:30
## Advanced
- [Trusted Packages ](docs/trusted-packages.md )
- [Experimental Proxy Mode ](docs/proxy-mode.md )
2026-01-08 00:24:18 +05:30
## Contributing
2025-05-15 16:50:59 +05:30
2025-05-11 22:42:27 +05:30
Refer to [CONTRIBUTING.md ](CONTRIBUTING.md )
2025-05-15 16:50:59 +05:30
2026-01-08 00:24:18 +05:30
## Limitations
2025-05-15 16:50:59 +05:30
<details>
<summary>Approximate dependency version resolution</summary>
2025-05-15 21:34:41 +05:30
2025-05-15 16:50:59 +05:30
`pmg` resolves the transitive dependencies of a package to be installed. It does it by querying
package registry APIs such as `npmjs` and `pypi` . However, almost always, dependency versions are
specified as ranges instead of specific version. Different package managers have different ways of
resolving these ranges. It also depends on peer or host dependencies already available in the application.
2025-11-05 13:49:19 +05:30
`pmg` is required to block a malicious package _before_ it is installed. Hence it applies its own heuristic
2025-05-15 16:50:59 +05:30
to choose a version from a version range for evaluation. This is fine when all versions of a given package
is malicious. However, there is a possibility of inconsistency when a specific version of a package is malicious.
2025-05-15 21:34:41 +05:30
2025-05-15 16:50:59 +05:30
</details>
2025-06-12 21:08:41 +05:30
<details>
<summary>PyPI registry scanning only</summary>
2025-08-29 00:21:09 +05:30
`pmg` only scans packages available in the PyPI registry when using any python package manager. Packages installed from
2025-06-12 21:08:41 +05:30
alternative sources such as Git URLs, local file paths, or private registries are not analyzed for
malware detection. This limitation applies to direct installations and transitive dependencies sourced
from non-PyPI locations.
</details>
2025-06-30 09:47:14 +05:30
2026-01-07 13:22:08 +05:30
<details>
<summary>Windows support for experimental proxy mode</summary>
PMG's experimental proxy mode (enabled with `--experimental-proxy-mode` flag) is supported on Windows
with the following considerations:
**Process Suspension** : PMG uses the Windows NT API (NtSuspendProcess/NtResumeProcess) to pause the
package manager during security prompts. This prevents console output from being mixed with interactive
prompts. While this API is widely used by tools like Process Explorer and is stable, it has some known
limitations:
- **Race condition**: Threads created during suspension are not suspended (very unlikely for brief suspensions)
- **Permission requirements**: Requires Windows Vista or later (all currently supported Windows versions)
- **Antivirus detection**: Some antivirus software may flag the use of NtSuspendProcess as suspicious behavior,
which is a false positive (PMG only uses it to pause its own child processes during user interaction)
**Fallback Behavior** : If process suspension fails (e.g., due to insufficient permissions), PMG continues
with the security prompt but console output from the package manager may be mixed with the prompt text.
This doesn't affect security functionality.
</details>
2025-06-30 09:47:14 +05:30
## Telemetry
`pmg` collects anonymous telemetry to help us understand how it is used and
improve the product. To disable telemetry, set `PMG_DISABLE_TELEMETRY` environment
variable to `true` .
```bash
export PMG_DISABLE_TELEMETRY = true
```