@nodesecure/scanner 2.2.0 → 3.0.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/README.md +95 -94
- package/index.js +4 -4
- package/package.json +17 -34
- package/src/{dependency.class.js → class/dependency.class.js} +22 -21
- package/src/{logger.class.js → class/logger.class.js} +0 -0
- package/src/depWalker.js +298 -370
- package/src/manifest.js +57 -0
- package/src/npmRegistry.js +68 -0
- package/src/tarball.js +85 -189
- package/src/utils/addMissingVersionFlags.js +24 -0
- package/src/utils/analyzeDependencies.js +40 -0
- package/src/utils/booleanToFlags.js +12 -0
- package/src/utils/filterDependencyKind.js +44 -0
- package/src/utils/getPackageName.js +18 -2
- package/src/utils/getTarballComposition.js +8 -10
- package/src/utils/index.js +16 -14
- package/src/utils/isGitDependency.js +20 -0
- package/src/utils/isSensitiveFile.js +6 -0
- package/src/utils/mergeDependencies.js +26 -23
- package/src/utils/semver.js +3 -3
- package/types/logger.d.ts +2 -0
- package/types/scanner.d.ts +128 -32
package/README.md
CHANGED
|
@@ -1,94 +1,95 @@
|
|
|
1
|
-
# NodeSecure Scanner
|
|
2
|
-

|
|
3
|
-
[](https://github.com/NodeSecure/scanner/commit-activity)
|
|
4
|
-
[](https://github.com/nodejs/security-wg/blob/master/processes/responsible_disclosure_template.md
|
|
5
|
-
)
|
|
6
|
-
[](https://github.com/NodeSecure/scanner/blob/master/LICENSE)
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
⚡️ Run a static analysis of your module's dependencies.
|
|
10
|
-
|
|
11
|
-
## Requirements
|
|
12
|
-
|
|
13
|
-
- [Node.js](https://nodejs.org/en/) version 16 or higher
|
|
14
|
-
|
|
15
|
-
## Getting Started
|
|
16
|
-
|
|
17
|
-
This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
$ npm i @nodesecure/scanner
|
|
21
|
-
# or
|
|
22
|
-
$ yarn add @nodesecure/scanner
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Usage example
|
|
26
|
-
|
|
27
|
-
```js
|
|
28
|
-
import * as scanner from "@nodesecure/scanner";
|
|
29
|
-
import fs from "fs/promises";
|
|
30
|
-
|
|
31
|
-
// CONSTANTS
|
|
32
|
-
const kPackagesToAnalyze = ["mocha", "cacache", "is-wsl"];
|
|
33
|
-
|
|
34
|
-
const payloads = await Promise.all(
|
|
35
|
-
kPackagesToAnalyze.map((name) => scanner.from(name))
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const promises = [];
|
|
39
|
-
for (let i = 0; i < kPackagesToAnalyze.length; i++) {
|
|
40
|
-
const data = JSON.stringify(payloads[i], null, 2);
|
|
41
|
-
|
|
42
|
-
promises.push(fs.writeFile(`${kPackagesToAnalyze[i]}.json`, data));
|
|
43
|
-
}
|
|
44
|
-
await Promise.allSettled(promises);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## API
|
|
48
|
-
|
|
49
|
-
See `types/api.d.ts` for a complete TypeScript definition.
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
function cwd(path: string, options?: Scanner.Options): Promise<Scanner.Payload>;
|
|
53
|
-
function from(packageName: string, options?: Scanner.Options): Promise<Scanner.Payload>;
|
|
54
|
-
function verify(packageName: string): Promise<Scanner.VerifyPayload>;
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
`Options` is described with the following TypeScript interface:
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
interface Options {
|
|
61
|
-
readonly maxDepth?: number;
|
|
62
|
-
readonly usePackageLock?: boolean;
|
|
63
|
-
readonly vulnerabilityStrategy: Strategy.Kind;
|
|
64
|
-
readonly forceRootAnalysis?: boolean;
|
|
65
|
-
readonly fullLockMode?: boolean;
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Contributors ✨
|
|
70
|
-
|
|
71
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
72
|
-
[):
|
|
76
|
-
|
|
77
|
-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
78
|
-
<!-- prettier-ignore-start -->
|
|
79
|
-
<!-- markdownlint-disable -->
|
|
80
|
-
<table>
|
|
81
|
-
<tr>
|
|
82
|
-
<td align="center"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/NodeSecure/scanner/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/NodeSecure/scanner/commits?author=fraxken" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/scanner/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="#security-fraxken" title="Security">🛡️</a> <a href="https://github.com/NodeSecure/scanner/issues?q=author%3Afraxken" title="Bug reports">🐛</a></td>
|
|
83
|
-
<td align="center"><a href="http://tonygo.dev"><img src="https://avatars.githubusercontent.com/u/22824417?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tony Gorez</b></sub></a><br /><a href="https://github.com/NodeSecure/scanner/commits?author=tony-go" title="Code">💻</a> <a href="https://github.com/NodeSecure/scanner/commits?author=tony-go" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/scanner/pulls?q=is%3Apr+reviewed-by%3Atony-go" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/NodeSecure/scanner/issues?q=author%3Atony-go" title="Bug reports">🐛</a></td>
|
|
84
|
-
<td align="center"><a href="https://mickaelcroquet.fr"><img src="https://avatars.githubusercontent.com/u/23740372?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Haze</b></sub></a><br /><a href="https://github.com/NodeSecure/scanner/commits?author=CroquetMickael" title="Code">💻</a></td>
|
|
85
|
-
|
|
86
|
-
</
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
<!--
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
# NodeSecure Scanner
|
|
2
|
+

|
|
3
|
+
[](https://github.com/NodeSecure/scanner/commit-activity)
|
|
4
|
+
[](https://github.com/nodejs/security-wg/blob/master/processes/responsible_disclosure_template.md
|
|
5
|
+
)
|
|
6
|
+
[](https://github.com/NodeSecure/scanner/blob/master/LICENSE)
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
⚡️ Run a static analysis of your module's dependencies.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- [Node.js](https://nodejs.org/en/) version 16 or higher
|
|
14
|
+
|
|
15
|
+
## Getting Started
|
|
16
|
+
|
|
17
|
+
This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
$ npm i @nodesecure/scanner
|
|
21
|
+
# or
|
|
22
|
+
$ yarn add @nodesecure/scanner
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage example
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import * as scanner from "@nodesecure/scanner";
|
|
29
|
+
import fs from "fs/promises";
|
|
30
|
+
|
|
31
|
+
// CONSTANTS
|
|
32
|
+
const kPackagesToAnalyze = ["mocha", "cacache", "is-wsl"];
|
|
33
|
+
|
|
34
|
+
const payloads = await Promise.all(
|
|
35
|
+
kPackagesToAnalyze.map((name) => scanner.from(name))
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const promises = [];
|
|
39
|
+
for (let i = 0; i < kPackagesToAnalyze.length; i++) {
|
|
40
|
+
const data = JSON.stringify(payloads[i], null, 2);
|
|
41
|
+
|
|
42
|
+
promises.push(fs.writeFile(`${kPackagesToAnalyze[i]}.json`, data));
|
|
43
|
+
}
|
|
44
|
+
await Promise.allSettled(promises);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
See `types/api.d.ts` for a complete TypeScript definition.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
function cwd(path: string, options?: Scanner.Options): Promise<Scanner.Payload>;
|
|
53
|
+
function from(packageName: string, options?: Scanner.Options): Promise<Scanner.Payload>;
|
|
54
|
+
function verify(packageName: string): Promise<Scanner.VerifyPayload>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`Options` is described with the following TypeScript interface:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
interface Options {
|
|
61
|
+
readonly maxDepth?: number;
|
|
62
|
+
readonly usePackageLock?: boolean;
|
|
63
|
+
readonly vulnerabilityStrategy: Strategy.Kind;
|
|
64
|
+
readonly forceRootAnalysis?: boolean;
|
|
65
|
+
readonly fullLockMode?: boolean;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Contributors ✨
|
|
70
|
+
|
|
71
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
72
|
+
[](#contributors-)
|
|
73
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
74
|
+
|
|
75
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
76
|
+
|
|
77
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
78
|
+
<!-- prettier-ignore-start -->
|
|
79
|
+
<!-- markdownlint-disable -->
|
|
80
|
+
<table>
|
|
81
|
+
<tr>
|
|
82
|
+
<td align="center"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/NodeSecure/scanner/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/NodeSecure/scanner/commits?author=fraxken" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/scanner/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="#security-fraxken" title="Security">🛡️</a> <a href="https://github.com/NodeSecure/scanner/issues?q=author%3Afraxken" title="Bug reports">🐛</a></td>
|
|
83
|
+
<td align="center"><a href="http://tonygo.dev"><img src="https://avatars.githubusercontent.com/u/22824417?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tony Gorez</b></sub></a><br /><a href="https://github.com/NodeSecure/scanner/commits?author=tony-go" title="Code">💻</a> <a href="https://github.com/NodeSecure/scanner/commits?author=tony-go" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/scanner/pulls?q=is%3Apr+reviewed-by%3Atony-go" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/NodeSecure/scanner/issues?q=author%3Atony-go" title="Bug reports">🐛</a></td>
|
|
84
|
+
<td align="center"><a href="https://mickaelcroquet.fr"><img src="https://avatars.githubusercontent.com/u/23740372?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Haze</b></sub></a><br /><a href="https://github.com/NodeSecure/scanner/commits?author=CroquetMickael" title="Code">💻</a></td>
|
|
85
|
+
<td align="center"><a href="https://github.com/mbalabash"><img src="https://avatars.githubusercontent.com/u/16868922?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maksim Balabash</b></sub></a><br /><a href="https://github.com/NodeSecure/scanner/commits?author=mbalabash" title="Code">💻</a></td>
|
|
86
|
+
</tr>
|
|
87
|
+
</table>
|
|
88
|
+
|
|
89
|
+
<!-- markdownlint-restore -->
|
|
90
|
+
<!-- prettier-ignore-end -->
|
|
91
|
+
|
|
92
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
MIT
|
package/index.js
CHANGED
|
@@ -10,8 +10,8 @@ import { getLocalRegistryURL } from "@nodesecure/npm-registry-sdk";
|
|
|
10
10
|
|
|
11
11
|
// Import Internal Dependencies
|
|
12
12
|
import { depWalker } from "./src/depWalker.js";
|
|
13
|
-
import {
|
|
14
|
-
import Logger from "./src/logger.class.js";
|
|
13
|
+
import { NPM_TOKEN } from "./src/utils/index.js";
|
|
14
|
+
import Logger from "./src/class/logger.class.js";
|
|
15
15
|
import * as tarball from "./src/tarball.js";
|
|
16
16
|
|
|
17
17
|
// CONSTANTS
|
|
@@ -31,7 +31,7 @@ export async function cwd(cwd = process.cwd(), options = {}, logger = new Logger
|
|
|
31
31
|
export async function from(packageName, options, logger = new Logger()) {
|
|
32
32
|
logger.start("fetchManifest");
|
|
33
33
|
const manifest = await pacote.manifest(packageName, {
|
|
34
|
-
...
|
|
34
|
+
...NPM_TOKEN, registry: getLocalRegistryURL(), cache: `${os.homedir()}/.npm`
|
|
35
35
|
});
|
|
36
36
|
logger.end("fetchManifest");
|
|
37
37
|
|
|
@@ -48,7 +48,7 @@ export async function verify(packageName = null) {
|
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
await pacote.extract(packageName, dest, {
|
|
51
|
-
...
|
|
51
|
+
...NPM_TOKEN, registry: getLocalRegistryURL(), cache: `${os.homedir()}/.npm`
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
return await tarball.scanPackage(dest, packageName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodesecure/scanner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A package API to run a static analysis of your module's dependencies.",
|
|
5
5
|
"exports": "./index.js",
|
|
6
6
|
"engines": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"lint": "eslint src test",
|
|
11
11
|
"prepublishOnly": "pkg-ok",
|
|
12
12
|
"test": "npm run lint && npm run test-only",
|
|
13
|
-
"test-only": "cross-env
|
|
13
|
+
"test-only": "cross-env esm-tape-runner 'test/**/*.spec.js' | tap-monkey",
|
|
14
|
+
"coverage": "c8 -r html npm run test-only"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"src",
|
|
@@ -46,54 +47,36 @@
|
|
|
46
47
|
"url": "https://github.com/NodeSecure/scanner/issues"
|
|
47
48
|
},
|
|
48
49
|
"homepage": "https://github.com/NodeSecure/scanner#readme",
|
|
49
|
-
"jest": {
|
|
50
|
-
"setupFilesAfterEnv": [
|
|
51
|
-
"./jest.setup.js"
|
|
52
|
-
],
|
|
53
|
-
"collectCoverage": true,
|
|
54
|
-
"collectCoverageFrom": [
|
|
55
|
-
"**/src/**/*.js"
|
|
56
|
-
],
|
|
57
|
-
"testEnvironment": "node",
|
|
58
|
-
"testMatch": [
|
|
59
|
-
"**/test/**/*.js"
|
|
60
|
-
],
|
|
61
|
-
"testPathIgnorePatterns": [
|
|
62
|
-
"/test/fixtures/"
|
|
63
|
-
],
|
|
64
|
-
"moduleNameMapper": {
|
|
65
|
-
"^@nodesecure/npm-registry-sdk$": "@nodesecure/npm-registry-sdk/dist/index.js",
|
|
66
|
-
"^@nodesecure/sec-literal$": "@nodesecure/sec-literal/src/index.js",
|
|
67
|
-
"^estree-walker$": "estree-walker/src/index.js"
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
50
|
"devDependencies": {
|
|
71
51
|
"@nodesecure/eslint-config": "^1.3.0",
|
|
72
52
|
"@slimio/is": "^1.5.1",
|
|
73
|
-
"@
|
|
74
|
-
"@
|
|
53
|
+
"@small-tech/esm-tape-runner": "^1.0.3",
|
|
54
|
+
"@small-tech/tap-monkey": "^1.3.0",
|
|
55
|
+
"@types/node": "^16.11.10",
|
|
56
|
+
"c8": "^7.10.0",
|
|
75
57
|
"cross-env": "^7.0.3",
|
|
76
58
|
"dotenv": "^10.0.0",
|
|
77
|
-
"eslint": "^8.
|
|
59
|
+
"eslint": "^8.3.0",
|
|
78
60
|
"get-folder-size": "^3.1.0",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
61
|
+
"pkg-ok": "^2.3.1",
|
|
62
|
+
"sinon": "^12.0.1",
|
|
63
|
+
"snap-shot-core": "^10.2.4",
|
|
64
|
+
"tape": "^5.3.2"
|
|
81
65
|
},
|
|
82
66
|
"dependencies": {
|
|
83
67
|
"@nodesecure/flags": "^2.2.0",
|
|
84
68
|
"@nodesecure/fs-walk": "^1.0.0",
|
|
85
|
-
"@nodesecure/i18n": "^1.2.
|
|
86
|
-
"@nodesecure/js-x-ray": "^4.0
|
|
69
|
+
"@nodesecure/i18n": "^1.2.1",
|
|
70
|
+
"@nodesecure/js-x-ray": "^4.2.0",
|
|
87
71
|
"@nodesecure/npm-registry-sdk": "^1.3.0",
|
|
88
|
-
"@nodesecure/ntlp": "^2.
|
|
72
|
+
"@nodesecure/ntlp": "^2.1.0",
|
|
89
73
|
"@nodesecure/utils": "^1.0.0",
|
|
90
|
-
"@nodesecure/vuln": "^1.4.
|
|
74
|
+
"@nodesecure/vuln": "^1.4.1",
|
|
91
75
|
"@npm/types": "^1.0.1",
|
|
92
|
-
"@npmcli/arborist": "^4.0
|
|
76
|
+
"@npmcli/arborist": "^4.1.0",
|
|
93
77
|
"@slimio/lock": "^1.0.0",
|
|
94
78
|
"builtins": "^4.0.0",
|
|
95
79
|
"combine-async-iterators": "^2.0.1",
|
|
96
|
-
"is-minified-code": "^2.0.0",
|
|
97
80
|
"itertools": "^1.7.1",
|
|
98
81
|
"lodash.difference": "^4.5.0",
|
|
99
82
|
"pacote": "^12.0.2",
|
|
@@ -56,28 +56,29 @@ export default class Dependency {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
versions: {
|
|
60
|
+
[this.version]: {
|
|
61
|
+
id: typeof customId === "number" ? customId : Dependency.currentId++,
|
|
62
|
+
usedBy: this.parent,
|
|
63
|
+
flags: this.flags,
|
|
64
|
+
description: "",
|
|
65
|
+
size: 0,
|
|
66
|
+
author: {},
|
|
67
|
+
warnings: this.warnings,
|
|
68
|
+
composition: {
|
|
69
|
+
extensions: [],
|
|
70
|
+
files: [],
|
|
71
|
+
minified: [],
|
|
72
|
+
unused: [],
|
|
73
|
+
missing: [],
|
|
74
|
+
required_files: [],
|
|
75
|
+
required_nodejs: [],
|
|
76
|
+
required_thirdparty: []
|
|
77
|
+
},
|
|
78
|
+
license: "unkown license",
|
|
79
|
+
gitUrl: this.gitUrl
|
|
80
|
+
}
|
|
79
81
|
},
|
|
80
|
-
versions: [this.version],
|
|
81
82
|
vulnerabilities: [],
|
|
82
83
|
metadata: {
|
|
83
84
|
dependencyCount: this.dependencyCount,
|
|
File without changes
|