NPMHound is an OpenGraph extension for NPM package dependencies. It uses a breadth-first search (BFS) of configurable depth to find dependencies of packages. Disclaimer: I am not an NPM package maintainer so consider this a PoC.
git clone https://github.com/C0KERNEL/NPMHound.git
cd NPMHound
go build -o npmhound ../npmhound -package <package-name> [options]| Flag | Default | Description |
|---|---|---|
-package |
(required) | Starting package(s), comma-separated |
-depth |
1 |
Max depth for dependency tree traversal |
-include-dev |
false |
Include devDependencies |
-output |
npmhound-opengraph.json |
Output file path |
-root |
Optional: supply a node id | This anchors a run to specific software |
-log |
timestamped filename | HTTP request log file path |
Single package with default depth:
npmhound -package lodashMultiple packages with deeper traversal:
npmhound -package express,fastify -depth 3Include dev dependencies:
npmhound -package react -depth 2 -include-devCustom output path:
npmhound -package webpack -depth 4 -output webpack-deps.jsonAnchored to a root node:
npmhound -package @babel/[email protected],@emotion/[email protected] -depth 4 -output some_bloodhoundce_deps.json -root bloodhoundce-depsEach run creates a CSV log file (e.g., npmhound-requests_2025-01-20_143052.log) containing HTTP requests made to the npm registry:
timestamp,method,status_code,content_length,duration_ms,error,url
2025-01-20T14:30:52Z,GET,200,12543,45.32,,https://registry.npmjs.org/lodash/latest
---
title: NPMBase Technology Subgraph
---
graph
node1[Software]
node2[NPMPackage]
node1 -- NPMDependsOn --> node2 -- NPMDependsOn --> node2
Nodes correspond to each object type.
| Node | Description | Icon | Color |
|---|---|---|---|
| NPM package nodes | folder | #D33115 | |
| Software nodes that act as the root node in a dependency tree | code | #2EAEED |
| Property | Type | Description |
|---|---|---|
| name | string | Software identifier that helps with cypher |
| npm_dep_mapped | boolean | Whether npm dependencies have been mapped |
| Property | Type | Description |
|---|---|---|
| name | string | Full package identifier (name@version) |
| package_name | string | Full package identifier with case preserved (name@version) |
| package_short_name | string | Package name without version |
| version | string | Resolved version |
| description | string | Package description |
| license | string | License type |
| author | string | Package author |
| homepage | string | Project homepage URL |
| keywords | []string | Package keywords |
| maintainers | []string | List of maintainer names |
| maintainer_emails | []string | List of maintainer emails |
| dependency_count | int | Number of runtime dependencies |
| dev_dependency_count | int | Number of dev dependencies |
| bugs | string | Bug tracker URL |
| repository | string | Repository URL |
| npm_version | string | npm version used to publish |
| npm_user | string | Publishing user |
| trusted_publisher | boolean | Whether published via trusted publisher |
Edges represent dependency relationships between packages.
| Edge | Description | Direction |
|---|---|---|
| NPMDependsOn | Package depends on another package | NPMPackage -> NPMPackage |
| Property | Type | Description |
|---|---|---|
| version_constraint | string | Semver constraint (e.g., ^1.2.3, ~2.0.0) |
| constraint_type | string | Type: caret, tilde, range, exact, any, complex |
| is_dev_dependency | boolean | True if this is a devDependency |
- gopengraph - OpenGraph library for Go
Get a sample of the NPMBase technology subgraph:
MATCH p = (a:NPMBase)-[r:NPMDependsOn]->(:NPMBase)
RETURN p
LIMIT 50Filter npm packages based on a keyword in the the keywords node property:
MATCH p = (a:NPMBase)-[]->(:NPMBase)
WHERE a.keywords CONTAINS 'browser'
RETURN p LIMIT 50Get relationships with a specific constraint type:
MATCH p = (a:NPMBase)-[r:NPMDependsOn]->(:NPMBase)
WHERE r.constraint_type = 'caret'
RETURN p LIMIT 50Get dependencies (depth of 1) for software based on -root flag used during collection:
MATCH p = (a:Software {name: 'BLOODHOUNDCE-DEPS'})-[:NPMDependsOn]->(:NPMPackage)
RETURN p LIMIT 50- Connect
NPMPackagenodes to their corresponding git repositories inGHBase
Thank you to a few folks:
- @wald0
- @cobbler
- @Podalirius (gopengraph lib)
