• Stars
    star
    368
  • Rank 115,958 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript security CLI that allow you to deeply analyze the dependency tree of a given package or local Node.js project.

๐Ÿข Node-Secure CLI ๐Ÿš€

a Node.js CLI to deeply analyze the dependency tree of a given package / directory

npm version license ossf scorecard github ci workflow codecov

๐Ÿ“ข About

Node.js security Command Line Interface. The goal of the project is to a design a CLI/API that will fetch and deeply analyze the dependency tree of a given npm package (Or a local project with a package.json) and output a .json file that will contains all metadata and flags about each packages. All this data will allow to quickly identify different issues across projects and packages (related to security and quality).

The CLI allow to load the JSON into a Webpage with the open command. The page will draw a Network of all dependencies with vis.js (example in the screenshot above). We also wrote a little Google drive document a while ago that summarizes some of these points:

๐Ÿ“œ Features

  • Run an AST analysis on each .js/.mjs file in the packages tarball and sort out warnings (unsafe-regex, unsafe-import etc) and the complete list of required expr and statements (files, node.js module, etc.).
  • Return complete composition for each packages (extensions, files, tarball size, etc).
  • Packages metadata from the npm registry API (number of releases, last publish date, maintainers etc).
  • Search for licenses files in the tarball and return the SPDX expression conformance of each detected licenses.
  • Link vulnerabilities from the Security-WG repository to the package version node.
  • Add flags to each packages versions to identify well known patterns and potential security threats easily.
  • Analyze npm packages and local Node.js projects.
  • Supports OpenSSF Scorecard.

๐Ÿšง Requirements

๐Ÿ’ƒ Getting Started

$ npm install @nodesecure/cli -g

or

$ git clone https://github.com/NodeSecure/cli.git
$ cd cli

# install NPM dependencies
$ npm install

# run esbuild to bundle/compile front-end assets
$ npm run build

$ npm link

Then the nsecure binary will be available in your terminal. Give a try with the popular express package. This will automatically open the webpage in your default system browser.

$ nsecure auto express

โš ๏ธ Setup an npm token to avoid hiting the maximum request limit of the npm registry API.

๐Ÿ‘€ Usage example

To show the complete list of commands

$ nsecure --help

# Run an analysis on the current working dir (must have a package.json file).
$ nsecure cwd

# Run an analysis for a given 'npm' package (must be in the npm registry).
$ nsecure from @sindresorhus/is

Then a nsecure-result.json will be writted at the current CLI location. To open it on a web page just run

$ nsecure open

# If you want to define a specific port use the --port option.
$ nsecure open --port 8080

Available options
name shortcut default value description
--port -p Define the running port, can also be define through the environment variable PORT

The auto command can be used to chain cwd/from and open commands automatically.

$ nsecure auto jest

# if no package is given to the auto command then it will run the cwd command instead of from.
$ nsecure auto

๐Ÿ‘€ By default with the auto command the .json file is deleted when the http server is closed. It's possible to disable this behavior by using the CLI option --keep, -k.


Some options are available on both cwd, from and auto commands. The output option is not available for the auto command.

name shortcut default value description
--depth -d 4 the maximum depth we must walk (when we fetch the whole tree).
--output -o nsecure-result the name that the outputted .json file will have
$ nsecure from express -d 10 -o express-security-report

Private packages / registry

Nsecure allow you to fetch stats on private npm packages by setting up a NODE_SECURE_TOKEN env variable (which must contains an npm token).

๐Ÿ’ฌ If you link the package by yourself with npm you can create a .env file at the root of the project too.

Nsecure is capable to work behind a custom private npm registry too by searching the default registry URL in your local npm configuration.

$ npm config get registry
$ npm config set "http://your-registry/"

API

Our back-end scanner package is available here.

Flags legends

Flags and emojis legends are documented here.

Searchbar filters

Since version 0.6.0 of Node-secure the UI include a brand new searchbar that allow to search anything on the tree (graph) by multiple criteria (filters). The current available filters are:

  • package (the default filter if there is none).
  • version (take a semver range as an argument).
  • flag (list of available flags in the current payload/tree).
  • license (list of available licenses in the current payload/tree).
  • author (author name/email/url).
  • ext (list of available file extensions in the current payload/tree).
  • builtin (available Node.js core module name).
  • size (see here

Exemple of query:

version: >=1.2 | 2, ext: .js, builtin: fs

FAQ

Why some nodes are red in the UI ?

Nodes are red when the project/package has been flagged with ๐Ÿ”ฌ hasMinifiedCode or โš ๏ธ hasWarnings.

Why the node-secure package size is so different from Bundlephobia ?

Node-secure will analyze the complete size of the npm tarball with no filters or particular optimization. Bundlephobia on the other side will bundle and remove most of the useless files from the tarball (Like the documentation, etc.).

Why some packages don't have OSSF Scorecard ?

See Scorecard Public Data:

We run a weekly Scorecard scan of the 1 million most critical open source projects judged by their direct dependencies and publish the results in a BigQuery public dataset. Currently, this list is derived from projects hosted on GitHub ONLY.

Contributors guide

If you are a developer wishing to contribute to the project, you must first read the CONTRIBUTING guide.

If you have already cloned and installed the project with npm locally, you still need to build and bundle front-end assets using the npm build script:

$ npm run build

Warning restart this command when modifying files in the public root folder

Once you have finished your development, check that the tests (and linter) are still good by running the following script:

$ npm test

Note If you add a feature, try adding tests for it along.

Workspaces

Click on one of the links to access the documentation of the workspace:

name package and link
documentation-ui @nodesecure/documentation-ui
vis-network @nodesecure/vis-network

These packages are available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @nodesecure/documentation-ui
# or
$ yarn add @nodesecure/documentation-ui

Contributors โœจ

All Contributors

Thanks goes to these wonderful people (emoji key):

Haze
Haze

๐Ÿ’ป ๐ŸŽจ
fraxken
fraxken

๐Ÿ’ป ๐Ÿ› ๐Ÿ“ โš ๏ธ ๐Ÿ“– ๐ŸŽจ
Xavier Stouder
Xavier Stouder

๐Ÿ’ป ๐ŸŽจ ๐Ÿ“–
Tony Gorez
Tony Gorez

๐Ÿ’ป ๐Ÿ“– ๐Ÿ‘€
abdellah-housni
abdellah-housni

๐Ÿ›
Vincent Dhennin
Vincent Dhennin

๐Ÿ’ป ๐Ÿ›
halcin
halcin

๐Ÿ’ป
Ange TEKEU
Ange TEKEU

๐Ÿ’ป
PierreDemailly
PierreDemailly

๐Ÿ’ป
Inรจs & Mรฉlusine LUJAN-ALVAREZ
Inรจs & Mรฉlusine LUJAN-ALVAREZ

๐Ÿ’ป
Yefis
Yefis

๐Ÿ’ป
Kouadio Fabrice Nguessan
Kouadio Fabrice Nguessan

๐Ÿšง

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT

More Repositories

1

js-x-ray

JavaScript & Node.js open-source SAST scanner. A static analyser for detecting most common malicious patterns ๐Ÿ”ฌ.
JavaScript
228
star
2

vulnera

Programmatically fetch security vulnerabilities with one or many strategies (NPM Audit, Sonatype, Snyk, Node.js DB).
TypeScript
30
star
3

scanner

โšก๏ธ A package API to run a static analysis of your module's dependencies. This is the CLI engine!
TypeScript
28
star
4

ci

NodeSecure tool enabling secured continuous integration
TypeScript
21
star
5

report

NodeSecure HTML & PDF report generator for any public and/or private git repositories.
JavaScript
14
star
6

Governance

NodeSecure Governance (Code of conduct & Contribution guidelines)
13
star
7

ci-action

The official GitHub action of the @nodesecure/ci package
JavaScript
9
star
8

npm-registry-sdk

Node.js SDK to fetch data from the npm API.
TypeScript
9
star
9

domain-check

Node.js module which helps you to check informations about domains
JavaScript
9
star
10

rc

NodeSecure runtime configuration
TypeScript
7
star
11

eslint-config

NodeSecure ESLint configuration (Work for both JavaScript and TypeScript projects).
JavaScript
6
star
12

ossf-scorecard-sdk

Node.js SDK for OpenSSF scorecard
TypeScript
5
star
13

Dependency-Analyser

Draw a graphic network of a given Github or Gitlab organization
JavaScript
4
star
14

github

Download and Extract Github repository
TypeScript
4
star
15

dependa

Identitfy and categorize Node.js dependencies (builtins, third parties..)
JavaScript
4
star
16

sec-literal

Security utilities to analyze ESTree Literal and JavaScript string primitive. Detect Hexadecimal, Base64, suffix and prefix patterns etc..
JavaScript
4
star
17

preview

Scan your node packages in your browser!
TypeScript
4
star
18

gitlab

Download and extract gitlab repository
TypeScript
3
star
19

vis-network

NodeSecure vis.js network front-end module
JavaScript
3
star
20

npm-security-fetcher

a Node.js CLI created to simplify the analysis of npm registry packages.
TypeScript
3
star
21

flags

NodeSecure security flags ๐Ÿšฉ (configuration and documentation)
HTML
2
star
22

estree-ast-utils

Utilities for AST (ESTree compliant)
JavaScript
2
star
23

i18n

NodeSecure Internationalization
JavaScript
1
star
24

database

NodeSecure Security Database
1
star
25

authors

DEPRECATED (replaced by @nodesecure/contact)
JavaScript
1
star
26

licenses-conformance

Parse spdx license expressions into structured object
TypeScript
1
star