2025-04-23 02:21:44 +05:30
|
|
|
|
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
|
|
|
|
2025-05-15 16:50:59 +05:30
|
|
|
- Wraps your favorite package manager (eg. `npm`)
|
|
|
|
|
- Blocks malicious packages at install time
|
|
|
|
|
- No configuration required, just install and use
|
2025-04-23 02:21:44 +05:30
|
|
|
|
2025-05-15 18:03:46 +05:30
|
|
|
## 🔥 PMG in Action
|
|
|
|
|
|
|
|
|
|
<img src="./docs/assets/pmg-intro.png" width="600" alt="pmg in action">
|
|
|
|
|
|
|
|
|
|
## 📦 TL;DR
|
|
|
|
|
|
|
|
|
|
Install `pmg`
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
brew install safedep/tap/pmg
|
|
|
|
|
```
|
2025-05-15 16:50:59 +05:30
|
|
|
|
|
|
|
|
Set up `pmg` to protect you development environment from malicious packages:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
echo "alias npm='pmg npm'" >> ~/.zshrc
|
|
|
|
|
echo "alias pnpm='pmg pnpm'" >> ~/.zshrc
|
|
|
|
|
source ~/.zshrc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
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-05-15 16:50:59 +05:30
|
|
|
pnpm add <package-name>
|
|
|
|
|
```
|
2025-04-23 02:21:44 +05:30
|
|
|
|
|
|
|
|
## 📑 Table of Contents
|
2025-05-15 16:50:59 +05:30
|
|
|
- [Package Manager Guard (PMG)](#package-manager-guard-pmg)
|
2025-05-15 18:03:46 +05:30
|
|
|
- [🔥 PMG in Action](#-pmg-in-action)
|
|
|
|
|
- [📦 TL;DR](#-tldr)
|
2025-05-15 16:50:59 +05:30
|
|
|
- [📑 Table of Contents](#-table-of-contents)
|
2025-05-15 18:03:46 +05:30
|
|
|
- [🔥 Features](#-features)
|
2025-05-15 16:50:59 +05:30
|
|
|
- [Supported Package Managers](#supported-package-managers)
|
|
|
|
|
- [Installation](#installation)
|
2025-05-16 19:38:06 +05:30
|
|
|
- [Homebrew](#homebrew)
|
2025-05-15 16:50:59 +05:30
|
|
|
- [Binaries](#binaries)
|
|
|
|
|
- [Build from Source](#build-from-source)
|
|
|
|
|
- [Usage](#usage)
|
|
|
|
|
- [Silent Mode](#silent-mode)
|
2025-05-16 19:38:06 +05:30
|
|
|
- [Dry Run](#dry-run)
|
2025-05-15 16:50:59 +05:30
|
|
|
- [Verbose Mode](#verbose-mode)
|
|
|
|
|
- [Debugging](#debugging)
|
2025-05-15 18:03:46 +05:30
|
|
|
- [🤝 Contributing](#-contributing)
|
|
|
|
|
- [🚫 Limitations](#-limitations)
|
2025-04-23 02:21:44 +05:30
|
|
|
|
2025-05-15 18:03:46 +05:30
|
|
|
## 🔥 Features
|
2025-05-15 16:50:59 +05:30
|
|
|
|
|
|
|
|
- 🚫 Malicious package identification using [SafeDep Cloud](https://docs.safedep.io/cloud/malware-analysis)
|
|
|
|
|
- 🌲 Deep dependency analysis and transitive dependency resolution
|
2025-05-11 22:42:27 +05:30
|
|
|
- ⚡ Fast and efficient package verification
|
|
|
|
|
- 🔄 Seamless integration with existing package managers
|
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:
|
|
|
|
|
|
|
|
|
|
| Package Manager | Status | Command |
|
|
|
|
|
| --------------- | --------- | --------------------------- |
|
|
|
|
|
| `npm` | ✅ Active | `pmg npm install <package>` |
|
|
|
|
|
| `pnpm` | ✅ Active | `pmg pnpm add <package>` |
|
|
|
|
|
| `yarn` | 🚧 Planned | |
|
|
|
|
|
| `pip` | 🚧 Planned | |
|
|
|
|
|
| `poetry` | 🚧 Planned | |
|
|
|
|
|
| `uv` | 🚧 Planned | |
|
|
|
|
|
|
|
|
|
|
> 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
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
2025-05-15 16:50:59 +05:30
|
|
|
Install a package with `npm` or `pnpm`:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pmg npm install <package-name>
|
|
|
|
|
pmg pnpm add <package-name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Set shell alias for convenience:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
alias npm="pmg npm"
|
|
|
|
|
alias pnpm="pmg pnpm"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Continue using your favorite package manager as usual:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
npm install <package-name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pnpm add <package-name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Silent Mode
|
|
|
|
|
|
|
|
|
|
Use the `--silent` flag to run PMG in silent mode:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pmg --silent npm install <package-name>
|
|
|
|
|
```
|
|
|
|
|
|
2025-05-16 19:38:06 +05:30
|
|
|
### Dry Run
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
```
|
|
|
|
|
|
2025-05-15 16:50:59 +05:30
|
|
|
### Verbose Mode
|
|
|
|
|
|
|
|
|
|
Use the `--verbose` flag to run PMG in verbose mode:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pmg --verbose npm install <package-name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Debugging
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
```
|
|
|
|
|
|
2025-05-15 18:03:46 +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
|
|
|
|
2025-05-15 18:03:46 +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.
|
|
|
|
|
|
|
|
|
|
`pmg` is required to block a malicious package *before* it is installed. Hence it applies its own heuristic
|
|
|
|
|
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>
|