Skip to content
C0KERNELPublic

About

BloodHound OpenGraph extension for NPM package dependencies

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

NPMHound

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.

Example Query

Installation

git clone https://github.com/C0KERNEL/NPMHound.git
cd NPMHound 
go build -o npmhound .

Usage

./npmhound -package <package-name> [options]

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

Examples

Single package with default depth:

npmhound -package lodash

Multiple packages with deeper traversal:

npmhound -package express,fastify -depth 3

Include dev dependencies:

npmhound -package react -depth 2 -include-dev

Custom output path:

npmhound -package webpack -depth 4 -output webpack-deps.json

Anchored to a root node:

npmhound -package @babel/[email protected],@emotion/[email protected] -depth 4 -output some_bloodhoundce_deps.json -root bloodhoundce-deps

Request Logging

Each 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

OpenGraph Schema

---
title: NPMBase Technology Subgraph
---
graph 
    node1[Software]
    node2[NPMPackage]
    node1 -- NPMDependsOn --> node2 -- NPMDependsOn --> node2
Loading

Nodes

Nodes correspond to each object type.

Node Description Icon Color
NPMPackage NPM package nodes folder #D33115
Software Software nodes that act as the root node in a dependency tree code #2EAEED

Software Node Properties

Property Type Description
name string Software identifier that helps with cypher
npm_dep_mapped boolean Whether npm dependencies have been mapped

NPMPackage Node Properties

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

Edges represent dependency relationships between packages.

Edge Description Direction
NPMDependsOn Package depends on another package NPMPackage -> NPMPackage

Edge Properties

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

Dependencies

Cypher

Get a sample of the NPMBase technology subgraph:

MATCH p = (a:NPMBase)-[r:NPMDependsOn]->(:NPMBase)
RETURN p
LIMIT 50

Filter 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 50

Get relationships with a specific constraint type:

MATCH p = (a:NPMBase)-[r:NPMDependsOn]->(:NPMBase)
WHERE r.constraint_type = 'caret'
RETURN p LIMIT 50

Get 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

Future Work

  • Connect NPMPackage nodes to their corresponding git repositories in GHBase

Acknowledgements

Thank you to a few folks:

  • @wald0
  • @cobbler
  • @Podalirius (gopengraph lib)

About

BloodHound OpenGraph extension for NPM package dependencies

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages