๐ Logo and cover by our beloved medhi bouchard โค๏ธ
Hello ๐,
Back for a little article about the rebranding of one of the NodeSecure tools: Vulnera (previously vuln, the vuln-era has begun!).
An opportunity for me to also write about this wonderful project that was born with the redesign of the back-end less than a year ago โ. If you don't remember I wrote an article:
Announcing new NodeSecure back-end
Thomas.G for NodeSecure ใป Sep 11 '21
Don't wait and dive in ๐ with me to discover this tool ๐.
What is Vulnera ? ๐
Vulnera is a package that allows you to programmatically fetch your Node.js project vulnerabilities from multiple sources or strategies:
- NPM Audit (Github Advisory Database)
- Sonatype OSS Index
-
deprecated
Node.js Security WG Database - Snyk
๐ข Feel free to push new sources (we have a guide on how to add/contribute one).
The code was originally designed for vulnerability management within the Scanner. Yet, its API is evolving with the objective of making it a full-fledged project.
import * as vulnera from "@nodesecure/vulnera";
const def = await vulnera.setStrategy(
vulnera.strategies.NPM_AUDIT
);
const vulnerabilities = await def.getVulnerabilities(process.cwd(), {
useStandardFormat: true
});
console.log(vulnerabilities);
Standard vulnerability format ๐ฏ
We have created a standard format to reconcile the different sources.
export interface StandardVulnerability {
/** Unique identifier for the vulnerability **/
id?: string;
/** Vulnerability origin, either Snyk, NPM or NodeSWG **/
origin: Origin;
/** Package associated with the vulnerability **/
package: string;
/** Vulnerability title **/
title: string;
/** Vulnerability description **/
description?: string;
/** Vulnerability link references on origin's website **/
url?: string;
/** Vulnerability severity levels given the strategy **/
severity?: Severity;
/** Common Vulnerabilities and Exposures dictionary */
cves?: string[];
/** Common Vulnerability Scoring System (CVSS) **/
cvssVector?: string;
/** CVSS Score **/
cvssScore?: number;
/** The range of vulnerable versions */
vulnerableRanges: string[];
/** The set of versions that are vulnerable **/
vulnerableVersions: string[];
/** The set of versions that are patched **/
patchedVersions?: string;
/** Overview of available patches **/
patches?: Patch[];
}
You can always use the original formats of each source of course ๐. We have implemented and exposed TypeScript interfaces for each of them.
Usage in Scanner ๐ฌ
On the scanner we have all the necessary information because we go through the dependency tree ๐. At the end of the process, we recover all vulnerabilities by iterating spec by spec within the hydratePayloadDependencies strategy method.
const {
hydratePayloadDependencies,
strategy
} = await vulnera.setStrategy(
userStrategyName // SNYK for example
);
await hydratePayloadDependencies(dependencies, {
useStandardFormat: true,
path: location
});
payload.vulnerabilityStrategy = strategy;
The following diagram explains the overall behavior and interactions between the Scanner and Vulnera.
If you want to learn more about the Payload you can check the TypeScript interface here.
What's next ? ๐
Some sources are more difficult to exploit than others (for NPM we use Arborist which simplifies our lives).
const { vulnerabilities } = (await arborist.audit()).toJSON();
However, we have to think and create mechanics to exploit sources like Sonatype ๐จ. This is required for API like getVulnerabilities()
.
Among the major subjects and ideas we are working on:
- Create a private database to benchmark the sources between them (see #29).
- Merging multiple sources in one (see #25).
- Fetch vulnerabilities of a given remote package (with support for private registry like verdaccio). At the moment we only support the analysis of a local manifest or a payload of the scanner.
Credits ๐
This project owes much to our core collaborator Antoine COULON who invested a lot of energy to improve it ๐ช.
Fun fact: its first contribution ๐ค on NodeSecure was also on the old version of the code Scanner that managed vulnerabilities.
But I don't forget individual contributions ๐
- Mathieu Kahlaoui for adding the getVulnerabilities() API
- Oleh Sych for adding Snyk strategy
- Medhi for his work on the logo
NodeSecure / vulnera
Programmatically fetch security vulnerabilities with one or many strategies (NPM Audit, Sonatype, Snyk, Node.js DB).
The vuln-era has begun! Programmatically fetch security vulnerabilities with one or many strategies. Originally designed to run and analyze Scanner dependencies it now also runs independently from an npm Manifest.
Requirements
- Node.js v18 or higher
Getting Started
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @nodesecure/vulnera
# or
$ yarn add @nodesecure/vulnera
Usage example
import * as vulnera from "@nodesecure/vulnera";
await vulnera.setStrategy(
vulnera.strategies.GITHUB_ADVISORY
);
const definition = await vulnera.getStrategy();
console.log(definition.strategy);
const vulnerabilities = await definition.getVulnerabilities(process.cwd(), {
useStandardFormat: true
});
console.log(vulnerabilities);
Available strategy
The default strategy is NONE which mean no strategy at all (we executeโฆ
Thanks ๐ for reading me and see you soon for another article!
Top comments (0)