@cyberhub/shieldpm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +239 -0
- package/dist/analyzer/static.d.ts +35 -0
- package/dist/analyzer/static.d.ts.map +1 -0
- package/dist/analyzer/static.js +416 -0
- package/dist/analyzer/static.js.map +1 -0
- package/dist/analyzer/typosquat.d.ts +30 -0
- package/dist/analyzer/typosquat.d.ts.map +1 -0
- package/dist/analyzer/typosquat.js +211 -0
- package/dist/analyzer/typosquat.js.map +1 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +621 -0
- package/dist/cli.js.map +1 -0
- package/dist/diff/dependency.d.ts +51 -0
- package/dist/diff/dependency.d.ts.map +1 -0
- package/dist/diff/dependency.js +222 -0
- package/dist/diff/dependency.js.map +1 -0
- package/dist/fingerprint/profile.d.ts +68 -0
- package/dist/fingerprint/profile.d.ts.map +1 -0
- package/dist/fingerprint/profile.js +233 -0
- package/dist/fingerprint/profile.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/monitor/permissions.d.ts +45 -0
- package/dist/monitor/permissions.d.ts.map +1 -0
- package/dist/monitor/permissions.js +265 -0
- package/dist/monitor/permissions.js.map +1 -0
- package/dist/sandbox/runner.d.ts +46 -0
- package/dist/sandbox/runner.d.ts.map +1 -0
- package/dist/sandbox/runner.js +216 -0
- package/dist/sandbox/runner.js.map +1 -0
- package/dist/utils/colors.d.ts +31 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/colors.js +54 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/logger.d.ts +26 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +77 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +24 -0
- package/src/analyzer/static.ts +483 -0
- package/src/analyzer/typosquat.ts +272 -0
- package/src/cli.ts +700 -0
- package/src/diff/dependency.ts +297 -0
- package/src/fingerprint/profile.ts +333 -0
- package/src/index.ts +34 -0
- package/src/monitor/permissions.ts +330 -0
- package/src/sandbox/runner.ts +302 -0
- package/src/utils/colors.ts +58 -0
- package/src/utils/logger.ts +87 -0
- package/tsconfig.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nrupak Shah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
```
|
|
2
|
+
███████╗██╗ ██╗██╗███████╗██╗ ██████╗ ██████╗ ███╗ ███╗
|
|
3
|
+
██╔════╝██║ ██║██║██╔════╝██║ ██╔══██╗██╔══██╗████╗ ████║
|
|
4
|
+
███████╗███████║██║█████╗ ██║ ██║ ██║██████╔╝██╔████╔██║
|
|
5
|
+
╚════██║██╔══██║██║██╔══╝ ██║ ██║ ██║██╔═══╝ ██║╚██╔╝██║
|
|
6
|
+
███████║██║ ██║██║███████╗███████╗██████╔╝██║ ██║ ╚═╝ ██║
|
|
7
|
+
╚══════╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═╝
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# ShieldPM
|
|
11
|
+
|
|
12
|
+
[](LICENSE)
|
|
13
|
+
[](https://nodejs.org)
|
|
14
|
+
[](https://www.npmjs.com/package/shieldpm)
|
|
15
|
+
|
|
16
|
+
**Runtime-aware package firewall for Node.js** — sandbox, monitor, and enforce least-privilege on every npm dependency.
|
|
17
|
+
|
|
18
|
+
ShieldPM scans packages for malicious patterns, blocks typosquatting attempts, sandboxes install scripts, and enforces a permission manifest so your dependencies only access what you allow.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install -g shieldpm
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or use without installing:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx shieldpm audit
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Install a package with full protection (typosquat check + static analysis + sandbox)
|
|
38
|
+
shieldpm install axios
|
|
39
|
+
|
|
40
|
+
# Audit all current dependencies for risks
|
|
41
|
+
shieldpm audit
|
|
42
|
+
|
|
43
|
+
# Deep audit with per-finding detail
|
|
44
|
+
shieldpm audit --deep
|
|
45
|
+
|
|
46
|
+
# Inspect what a specific package actually does
|
|
47
|
+
shieldpm inspect lodash
|
|
48
|
+
|
|
49
|
+
# Run any command in a sandboxed environment (no network, stripped env)
|
|
50
|
+
shieldpm sandbox node scripts/postinstall.js
|
|
51
|
+
|
|
52
|
+
# Auto-generate a permission manifest from your dependencies
|
|
53
|
+
shieldpm manifest generate
|
|
54
|
+
|
|
55
|
+
# Show what changed in your dependency tree since last commit
|
|
56
|
+
shieldpm diff
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## What It Does
|
|
60
|
+
|
|
61
|
+
### Static Analysis Engine
|
|
62
|
+
Scans every `.js`/`.ts` file in a package for:
|
|
63
|
+
- **Code execution**: `eval()`, `Function()`, `vm.runInContext()`
|
|
64
|
+
- **Process spawning**: `child_process`, `exec`, `spawn`
|
|
65
|
+
- **Network access**: `http.request`, `fetch()`, `dns.lookup`, `WebSocket`
|
|
66
|
+
- **File system access**: reads/writes to sensitive paths (`/etc/passwd`, `~/.ssh`, `~/.npmrc`)
|
|
67
|
+
- **Environment exfiltration**: `JSON.stringify(process.env)`
|
|
68
|
+
- **Obfuscation**: `String.fromCharCode`, hex escape sequences, base64 decode
|
|
69
|
+
- **Prototype pollution**: `__proto__` access, `constructor.prototype`
|
|
70
|
+
- **Install scripts**: `preinstall`/`postinstall` scripts
|
|
71
|
+
|
|
72
|
+
Each package gets a **risk score from 0-10** with detailed findings.
|
|
73
|
+
|
|
74
|
+
### Typosquatting Detection
|
|
75
|
+
Checks package names against the top npm packages using:
|
|
76
|
+
- Levenshtein distance (edit distance <= 2)
|
|
77
|
+
- Character transposition (`exprses` vs `express`)
|
|
78
|
+
- Hyphen/underscore/dot confusion (`lo-dash` vs `lodash`)
|
|
79
|
+
- Scope confusion (`@tyeps/react` vs `@types/react`)
|
|
80
|
+
- Repeated/missing characters (`expresss`, `expres`)
|
|
81
|
+
|
|
82
|
+
### Sandboxed Execution
|
|
83
|
+
Runs postinstall scripts and arbitrary commands in a restricted environment:
|
|
84
|
+
- **Network blocked** via proxy redirection
|
|
85
|
+
- **Environment stripped** (only PATH, HOME, NODE_ENV pass through)
|
|
86
|
+
- **Sensitive vars removed** (AWS keys, tokens, database URLs)
|
|
87
|
+
- **30-second timeout** with kill
|
|
88
|
+
- Full stdout/stderr capture
|
|
89
|
+
|
|
90
|
+
### Permission Manifest
|
|
91
|
+
Define exactly what each dependency is allowed to do in `shieldpm.json`:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"version": 1,
|
|
96
|
+
"permissions": {
|
|
97
|
+
"axios": { "net": ["*.api.example.com"], "fs": false },
|
|
98
|
+
"lodash": { "net": false, "fs": false },
|
|
99
|
+
"sharp": { "fs": ["./uploads", "./cache"], "net": false, "native": true }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Auto-generate it with `shieldpm manifest generate`, then review and tighten.
|
|
105
|
+
|
|
106
|
+
### Behavioral Fingerprinting
|
|
107
|
+
Creates a cryptographic profile of each package:
|
|
108
|
+
- SHA-256 hash of all source files
|
|
109
|
+
- Complete import/require graph
|
|
110
|
+
- Network endpoints found in source
|
|
111
|
+
- File paths accessed
|
|
112
|
+
- Native module bindings
|
|
113
|
+
|
|
114
|
+
Compare profiles across versions to detect supply chain attacks.
|
|
115
|
+
|
|
116
|
+
### Dependency Diff
|
|
117
|
+
Compare your dependency tree before and after changes:
|
|
118
|
+
- New packages, removed packages, version bumps
|
|
119
|
+
- Flags: new install scripts, new native modules, major version bumps, version downgrades
|
|
120
|
+
- Works with `package-lock.json` via git history
|
|
121
|
+
|
|
122
|
+
## Feature Comparison
|
|
123
|
+
|
|
124
|
+
| Feature | ShieldPM | npm audit | Socket.dev |
|
|
125
|
+
|---------|----------|-----------|------------|
|
|
126
|
+
| Known vulnerability check | Planned | Yes | Yes |
|
|
127
|
+
| Static code analysis | Yes | No | Yes |
|
|
128
|
+
| Typosquatting detection | Yes | No | Yes |
|
|
129
|
+
| Sandboxed install scripts | Yes | No | No |
|
|
130
|
+
| Permission manifest | Yes | No | No |
|
|
131
|
+
| Behavioral fingerprinting | Yes | No | Partial |
|
|
132
|
+
| Dependency diff | Yes | No | Partial |
|
|
133
|
+
| Runtime enforcement | Yes | No | No |
|
|
134
|
+
| Free & open source | Yes | Yes | Freemium |
|
|
135
|
+
| Zero dependencies | Yes | N/A | N/A |
|
|
136
|
+
|
|
137
|
+
## Architecture
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
shieldpm
|
|
141
|
+
├── src/
|
|
142
|
+
│ ├── cli.ts # CLI entry point (process.argv parsing)
|
|
143
|
+
│ ├── index.ts # Public API exports
|
|
144
|
+
│ ├── analyzer/
|
|
145
|
+
│ │ ├── static.ts # Pattern-based static analysis engine
|
|
146
|
+
│ │ └── typosquat.ts # Typosquatting detection (Levenshtein + heuristics)
|
|
147
|
+
│ ├── sandbox/
|
|
148
|
+
│ │ └── runner.ts # Restricted process execution
|
|
149
|
+
│ ├── monitor/
|
|
150
|
+
│ │ └── permissions.ts # shieldpm.json manifest load/validate/generate
|
|
151
|
+
│ ├── fingerprint/
|
|
152
|
+
│ │ └── profile.ts # Behavioral profiling and diff
|
|
153
|
+
│ ├── diff/
|
|
154
|
+
│ │ └── dependency.ts # package-lock.json diff engine
|
|
155
|
+
│ └── utils/
|
|
156
|
+
│ ├── colors.ts # ANSI terminal colors (zero deps)
|
|
157
|
+
│ └── logger.ts # Leveled logger
|
|
158
|
+
├── package.json
|
|
159
|
+
├── tsconfig.json
|
|
160
|
+
└── shieldpm.json # (generated) permission manifest
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## CLI Reference
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
shieldpm install <package> Install with protection (typosquat + analysis + sandbox)
|
|
167
|
+
shieldpm audit Audit current dependencies
|
|
168
|
+
shieldpm audit --deep Deep audit with per-finding detail
|
|
169
|
+
shieldpm inspect <package> Show what a package does
|
|
170
|
+
shieldpm sandbox <command> Run command in sandbox
|
|
171
|
+
shieldpm manifest generate Auto-generate permission manifest
|
|
172
|
+
shieldpm manifest enforce Validate manifest coverage
|
|
173
|
+
shieldpm diff Show dependency changes since last commit
|
|
174
|
+
shieldpm help Show help
|
|
175
|
+
shieldpm version Show version
|
|
176
|
+
|
|
177
|
+
Options:
|
|
178
|
+
--verbose Enable debug logging
|
|
179
|
+
--no-color Disable colored output
|
|
180
|
+
--json Machine-readable output
|
|
181
|
+
--force Bypass typosquatting blocks
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Permission Manifest Reference
|
|
185
|
+
|
|
186
|
+
The `shieldpm.json` file controls what each dependency is allowed to do:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"version": 1,
|
|
191
|
+
"permissions": {
|
|
192
|
+
"<package-name>": {
|
|
193
|
+
"net": ["<glob-pattern>"] | false,
|
|
194
|
+
"fs": ["<path>"] | false,
|
|
195
|
+
"native": true | false,
|
|
196
|
+
"exec": true | false,
|
|
197
|
+
"env": ["<VAR_NAME>"] | true | false
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
| Field | Type | Description |
|
|
204
|
+
|-------|------|-------------|
|
|
205
|
+
| `net` | `string[] \| false` | Allowed network destinations (glob). `false` = no network. |
|
|
206
|
+
| `fs` | `string[] \| false` | Allowed filesystem paths. `false` = no fs access. |
|
|
207
|
+
| `native` | `boolean` | Whether native C++ addons are allowed. |
|
|
208
|
+
| `exec` | `boolean` | Whether `child_process` is allowed. |
|
|
209
|
+
| `env` | `string[] \| boolean` | Allowed env vars, `true` = all, `false` = none. |
|
|
210
|
+
|
|
211
|
+
## Contributing
|
|
212
|
+
|
|
213
|
+
Contributions are welcome! This is a free, open-source project.
|
|
214
|
+
|
|
215
|
+
1. Fork the repository
|
|
216
|
+
2. Create your feature branch: `git checkout -b feature/my-feature`
|
|
217
|
+
3. Make your changes
|
|
218
|
+
4. Run tests: `npm test`
|
|
219
|
+
5. Build: `npm run build`
|
|
220
|
+
6. Submit a pull request
|
|
221
|
+
|
|
222
|
+
### Development
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
git clone https://github.com/nrupaks/shieldpm.git
|
|
226
|
+
cd shieldpm
|
|
227
|
+
npm install
|
|
228
|
+
npm run dev -- help # Run CLI in development mode
|
|
229
|
+
npm run build # Compile TypeScript
|
|
230
|
+
npm test # Run tests
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Built with Claude
|
|
234
|
+
|
|
235
|
+
This project was built with [Claude](https://claude.ai) by Anthropic.
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
[MIT](LICENSE) - Nrupak Shah
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShieldPM — Static Analysis Engine
|
|
3
|
+
* Scans package source code for suspicious patterns, network calls,
|
|
4
|
+
* filesystem access, obfuscation, and dynamic code execution.
|
|
5
|
+
*/
|
|
6
|
+
export type Severity = 'critical' | 'high' | 'medium' | 'low' | 'info';
|
|
7
|
+
export interface Finding {
|
|
8
|
+
severity: Severity;
|
|
9
|
+
category: string;
|
|
10
|
+
message: string;
|
|
11
|
+
file: string;
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
snippet: string;
|
|
15
|
+
rule: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RiskReport {
|
|
18
|
+
/** Overall risk score 0 (safe) – 10 (dangerous) */
|
|
19
|
+
score: number;
|
|
20
|
+
findings: Finding[];
|
|
21
|
+
summary: string;
|
|
22
|
+
/** Breakdown by category */
|
|
23
|
+
categoryCounts: Record<string, number>;
|
|
24
|
+
/** Total files scanned */
|
|
25
|
+
filesScanned: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Analyze a package directory for security risks via static pattern matching.
|
|
29
|
+
*/
|
|
30
|
+
export declare function analyzePackage(packageDir: string): Promise<RiskReport>;
|
|
31
|
+
/**
|
|
32
|
+
* Analyze a single source string (useful for quick checks).
|
|
33
|
+
*/
|
|
34
|
+
export declare function analyzeSource(source: string, filename?: string): Finding[];
|
|
35
|
+
//# sourceMappingURL=static.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/analyzer/static.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAEvE,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,0BAA0B;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB;AAwYD;;GAEG;AACH,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CA+C5E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAY,GAAG,OAAO,EAAE,CAE7E"}
|