@socketsecurity/cli-with-sentry 0.14.55 → 0.14.57
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/bin/cli.js +8 -10
- package/bin/npm-cli.js +1 -1
- package/bin/npx-cli.js +3 -1
- package/dist/constants.d.ts +21 -11
- package/dist/constants.js +47 -33
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +3 -3
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +760 -497
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/color-or-markdown.d.ts +16 -0
- package/dist/module-sync/edge.d.ts +1 -1
- package/dist/module-sync/index.d.ts +3 -173
- package/dist/module-sync/node.d.ts +1 -1
- package/dist/module-sync/override-set.d.ts +37 -0
- package/dist/module-sync/path-resolve.d.ts +2 -3
- package/dist/module-sync/shadow-bin.d.ts +1 -1
- package/dist/module-sync/shadow-bin.js +16 -24
- package/dist/module-sync/shadow-bin.js.map +1 -1
- package/dist/module-sync/{index.js → shadow-npm-inject.js} +46 -41
- package/dist/module-sync/shadow-npm-inject.js.map +1 -0
- package/dist/module-sync/{npm-paths.js → shadow-npm-paths.js} +5 -16
- package/dist/module-sync/shadow-npm-paths.js.map +1 -0
- package/dist/module-sync/socket-url.d.ts +3 -0
- package/dist/require/cli.js +760 -497
- package/dist/require/cli.js.map +1 -1
- package/dist/require/shadow-npm-inject.js +3 -0
- package/dist/require/shadow-npm-paths.js +3 -0
- package/package.json +41 -63
- package/dist/module-sync/index.js.map +0 -1
- package/dist/module-sync/npm-injection.js +0 -26
- package/dist/module-sync/npm-injection.js.map +0 -1
- package/dist/module-sync/npm-paths.js.map +0 -1
- package/dist/module-sync/proc-log.d.ts +0 -3
- package/dist/module-sync/reify.d.ts +0 -1018
- package/dist/require/index.js +0 -3
- package/dist/require/npm-injection.js +0 -3
- package/dist/require/npm-paths.js +0 -3
- /package/dist/module-sync/{npm-injection.d.ts → shadow-npm-inject.d.ts} +0 -0
- /package/dist/module-sync/{npm-paths.d.ts → shadow-npm-paths.d.ts} +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import indentString from '@socketregistry/indent-string/index.cjs';
|
|
2
|
+
declare class ColorOrMarkdown {
|
|
3
|
+
useMarkdown: boolean;
|
|
4
|
+
constructor(useMarkdown: boolean);
|
|
5
|
+
bold(text: string): string;
|
|
6
|
+
header(text: string, level?: number): string;
|
|
7
|
+
hyperlink(text: string, url: string | undefined, { fallback, fallbackToUrl }?: {
|
|
8
|
+
fallback?: boolean | undefined;
|
|
9
|
+
fallbackToUrl?: boolean | undefined;
|
|
10
|
+
}): string;
|
|
11
|
+
indent(...args: Parameters<typeof indentString>): ReturnType<typeof indentString>;
|
|
12
|
+
italic(text: string): string;
|
|
13
|
+
json(value: any): string;
|
|
14
|
+
list(items: string[]): string;
|
|
15
|
+
}
|
|
16
|
+
export { ColorOrMarkdown };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="npmcli__arborist" />
|
|
2
2
|
import { SafeNode } from "./node.js";
|
|
3
|
-
import { SafeOverrideSet } from "./
|
|
3
|
+
import { SafeOverrideSet } from "./override-set.js";
|
|
4
4
|
import { DependencyProblem } from '@npmcli/arborist';
|
|
5
5
|
import { Edge as BaseEdge } from "@npmcli/arborist";
|
|
6
6
|
type EdgeClass = Omit<BaseEdge, 'accept' | 'detach' | 'optional' | 'overrides' | 'peer' | 'peerConflicted' | 'rawSpec' | 'reload' | 'satisfiedBy' | 'spec' | 'to'> & {
|
|
@@ -1,177 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { kRiskyReify } from "./shadow-npm-inject.js";
|
|
2
|
+
import { ArboristClass } from "./types.js";
|
|
3
3
|
import { SafeNode } from "./node.js";
|
|
4
|
-
import indentString from "@socketregistry/indent-string/index.cjs";
|
|
5
|
-
import { LogSymbols } from "@socketsecurity/registry/lib/logger";
|
|
6
|
-
import { SocketSdkResultType } from "@socketsecurity/sdk";
|
|
7
|
-
import { Diff, ArboristClass } from "./types.js";
|
|
8
|
-
import { ObjectEncodingOptions, OpenMode, PathLike } from "node:fs";
|
|
9
|
-
import { promises as fs } from "node:fs";
|
|
10
|
-
import { readFileSync as fsReadFileSync } from "node:fs";
|
|
11
|
-
import { Abortable } from "node:events";
|
|
12
|
-
import { FileHandle } from "node:fs/promises";
|
|
13
|
-
import { kRiskyReify } from "./reify.js";
|
|
14
|
-
interface OverrideSetClass {
|
|
15
|
-
children: Map<string, SafeOverrideSet>;
|
|
16
|
-
key: string | undefined;
|
|
17
|
-
keySpec: string | undefined;
|
|
18
|
-
name: string | undefined;
|
|
19
|
-
parent: SafeOverrideSet | undefined;
|
|
20
|
-
value: string | undefined;
|
|
21
|
-
version: string | undefined;
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-new
|
|
23
|
-
new (...args: any[]): OverrideSetClass;
|
|
24
|
-
get isRoot(): boolean;
|
|
25
|
-
get ruleset(): Map<string, SafeOverrideSet>;
|
|
26
|
-
ancestry(): Generator<SafeOverrideSet>;
|
|
27
|
-
childrenAreEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
|
|
28
|
-
getEdgeRule(edge: SafeEdge): SafeOverrideSet;
|
|
29
|
-
getNodeRule(node: SafeNode): SafeOverrideSet;
|
|
30
|
-
getMatchingRule(node: SafeNode): SafeOverrideSet | null;
|
|
31
|
-
isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
|
|
32
|
-
}
|
|
33
|
-
declare const OverrideSet: OverrideSetClass;
|
|
34
|
-
// Implementation code not related to patch https://github.com/npm/cli/pull/8089
|
|
35
|
-
// is based on https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/override-set.js:
|
|
36
|
-
declare class SafeOverrideSet extends OverrideSet {
|
|
37
|
-
// Patch adding doOverrideSetsConflict is based on
|
|
38
|
-
// https://github.com/npm/cli/pull/8089.
|
|
39
|
-
static doOverrideSetsConflict(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): boolean;
|
|
40
|
-
// Patch adding findSpecificOverrideSet is based on
|
|
41
|
-
// https://github.com/npm/cli/pull/8089.
|
|
42
|
-
static findSpecificOverrideSet(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): SafeOverrideSet | undefined;
|
|
43
|
-
// Patch adding childrenAreEqual is based on
|
|
44
|
-
// https://github.com/npm/cli/pull/8089.
|
|
45
|
-
childrenAreEqual(otherOverrideSet: SafeOverrideSet): boolean;
|
|
46
|
-
getEdgeRule(edge: SafeEdge): SafeOverrideSet;
|
|
47
|
-
// Patch adding isEqual is based on
|
|
48
|
-
// https://github.com/npm/cli/pull/8089.
|
|
49
|
-
isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
|
|
50
|
-
}
|
|
51
|
-
declare const depValid: (child: SafeNode, requested: string, accept: string | undefined, requester: SafeNode) => boolean;
|
|
52
|
-
declare function getSocketDevAlertUrl(alertType: string): string;
|
|
53
|
-
declare function getSocketDevPackageOverviewUrl(eco: string, name: string, version?: string | undefined): string;
|
|
54
|
-
declare class ColorOrMarkdown {
|
|
55
|
-
useMarkdown: boolean;
|
|
56
|
-
constructor(useMarkdown: boolean);
|
|
57
|
-
bold(text: string): string;
|
|
58
|
-
header(text: string, level?: number): string;
|
|
59
|
-
hyperlink(text: string, url: string | undefined, { fallback, fallbackToUrl }?: {
|
|
60
|
-
fallback?: boolean | undefined;
|
|
61
|
-
fallbackToUrl?: boolean | undefined;
|
|
62
|
-
}): string;
|
|
63
|
-
indent(...args: Parameters<typeof indentString>): ReturnType<typeof indentString>;
|
|
64
|
-
italic(text: string): string;
|
|
65
|
-
json(value: any): string;
|
|
66
|
-
list(items: string[]): string;
|
|
67
|
-
get logSymbols(): LogSymbols;
|
|
68
|
-
}
|
|
69
|
-
type AlertUxLookup = ReturnType<typeof createAlertUXLookup>;
|
|
70
|
-
type AlertUxLookupSettings = Parameters<AlertUxLookup>[0];
|
|
71
|
-
type AlertUxLookupResult = ReturnType<AlertUxLookup>;
|
|
72
|
-
type RuleActionUX = {
|
|
73
|
-
block: boolean;
|
|
74
|
-
display: boolean;
|
|
75
|
-
};
|
|
76
|
-
type SettingsType = (SocketSdkResultType<"postSettings"> & {
|
|
77
|
-
success: true;
|
|
78
|
-
})["data"];
|
|
79
|
-
declare function createAlertUXLookup(settings: SettingsType): (context: {
|
|
80
|
-
package: {
|
|
81
|
-
name: string;
|
|
82
|
-
version: string;
|
|
83
|
-
};
|
|
84
|
-
alert: {
|
|
85
|
-
type: string;
|
|
86
|
-
};
|
|
87
|
-
}) => RuleActionUX;
|
|
88
|
-
declare function uxLookup(settings: AlertUxLookupSettings): Promise<AlertUxLookupResult>;
|
|
89
|
-
type CveAlertType = "cve" | "mediumCVE" | "mildCVE" | "criticalCVE";
|
|
90
|
-
type ArtifactAlertCveFixable = Omit<SocketArtifactAlert, "props" | "title"> & {
|
|
91
|
-
type: CveAlertType;
|
|
92
|
-
props: {
|
|
93
|
-
firstPatchedVersionIdentifier: string;
|
|
94
|
-
vulnerableVersionRange: string;
|
|
95
|
-
[key: string]: any;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
type ArtifactAlertFixable = ArtifactAlertCveFixable & {
|
|
99
|
-
type: CveAlertType | "socketUpgradeAvailable";
|
|
100
|
-
};
|
|
101
|
-
type SocketArtifactAlert = {
|
|
102
|
-
key: string;
|
|
103
|
-
type: string;
|
|
104
|
-
severity: string;
|
|
105
|
-
category: string;
|
|
106
|
-
action?: string | undefined;
|
|
107
|
-
actionPolicyIndex?: number | undefined;
|
|
108
|
-
file?: string | undefined;
|
|
109
|
-
props?: any | undefined;
|
|
110
|
-
start?: number | undefined;
|
|
111
|
-
end?: number | undefined;
|
|
112
|
-
};
|
|
113
|
-
type SocketArtifact = {
|
|
114
|
-
type: string;
|
|
115
|
-
name: string;
|
|
116
|
-
namespace?: string | undefined;
|
|
117
|
-
version?: string | undefined;
|
|
118
|
-
subpath?: string | undefined;
|
|
119
|
-
release?: string | undefined;
|
|
120
|
-
id?: string | undefined;
|
|
121
|
-
author?: string[];
|
|
122
|
-
license?: string | undefined;
|
|
123
|
-
licenseDetails?: Array<{
|
|
124
|
-
spdxDisj: string;
|
|
125
|
-
provenance: string;
|
|
126
|
-
filepath: string;
|
|
127
|
-
match_strength: number;
|
|
128
|
-
}>;
|
|
129
|
-
licenseAttrib?: Array<{
|
|
130
|
-
attribText: string;
|
|
131
|
-
attribData: Array<{
|
|
132
|
-
purl: string;
|
|
133
|
-
foundInFilepath: string;
|
|
134
|
-
spdxExpr: string;
|
|
135
|
-
foundAuthors: string[];
|
|
136
|
-
}>;
|
|
137
|
-
}>;
|
|
138
|
-
score?: {
|
|
139
|
-
supplyChain: number;
|
|
140
|
-
quality: number;
|
|
141
|
-
maintenance: number;
|
|
142
|
-
vulnerability: number;
|
|
143
|
-
license: number;
|
|
144
|
-
overall: number;
|
|
145
|
-
};
|
|
146
|
-
alerts?: SocketArtifactAlert[];
|
|
147
|
-
size?: number | undefined;
|
|
148
|
-
batchIndex?: number | undefined;
|
|
149
|
-
};
|
|
150
|
-
declare function batchScan(pkgIds: string[], concurrencyLimit?: number): AsyncGenerator<SocketArtifact>;
|
|
151
|
-
declare function isArtifactAlertCveFixable(alert: SocketArtifactAlert): alert is ArtifactAlertCveFixable;
|
|
152
|
-
declare function isArtifactAlertUpgradeFixable(alert: SocketArtifactAlert): alert is ArtifactAlertFixable;
|
|
153
|
-
declare function isArtifactAlertFixable(alert: SocketArtifactAlert): alert is ArtifactAlertFixable;
|
|
154
|
-
type PackageDetail = {
|
|
155
|
-
node: SafeNode;
|
|
156
|
-
existing?: SafeNode | undefined;
|
|
157
|
-
};
|
|
158
|
-
type GetPackagesToQueryFromDiffOptions = {
|
|
159
|
-
includeUnchanged?: boolean | undefined;
|
|
160
|
-
includeUnknownOrigin?: boolean | undefined;
|
|
161
|
-
};
|
|
162
|
-
declare function getPackagesToQueryFromDiff(diff_: Diff | null, options?: GetPackagesToQueryFromDiffOptions | undefined): PackageDetail[];
|
|
163
|
-
declare function findUp(name: string | string[], { cwd }: {
|
|
164
|
-
cwd: string;
|
|
165
|
-
}): Promise<string | undefined>;
|
|
166
|
-
type ReadFileOptions = ObjectEncodingOptions & Abortable & {
|
|
167
|
-
flag?: OpenMode | undefined;
|
|
168
|
-
};
|
|
169
|
-
declare function readFileBinary(filepath: PathLike | FileHandle, options?: ReadFileOptions | undefined): Promise<Buffer>;
|
|
170
|
-
declare function readFileUtf8(filepath: PathLike | FileHandle, options?: ReadFileOptions | undefined): Promise<string>;
|
|
171
|
-
declare function safeReadFile(...args: Parameters<typeof fs.readFile>): ReturnType<typeof fs.readFile> | undefined;
|
|
172
|
-
declare function safeReadFileSync(...args: Parameters<typeof fsReadFileSync>): ReturnType<typeof fsReadFileSync> | undefined;
|
|
173
4
|
declare const Arborist: ArboristClass;
|
|
174
|
-
declare const kCtorArgs: unique symbol;
|
|
175
5
|
declare const SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES: {
|
|
176
6
|
__proto__: null;
|
|
177
7
|
audit: boolean;
|
|
@@ -189,4 +19,4 @@ declare class SafeArborist extends Arborist {
|
|
|
189
19
|
// @ts-ignore Incorrectly typed.
|
|
190
20
|
reify(this: SafeArborist, ...args: Parameters<InstanceType<ArboristClass>['reify']>): Promise<SafeNode>;
|
|
191
21
|
}
|
|
192
|
-
export {
|
|
22
|
+
export { Arborist, SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES, SafeArborist };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="npmcli__arborist" />
|
|
2
|
-
import { SafeOverrideSet } from "./
|
|
2
|
+
import { SafeOverrideSet } from "./override-set.js";
|
|
3
3
|
import { SafeEdge } from "./edge.js";
|
|
4
4
|
import { Link } from '@npmcli/arborist';
|
|
5
5
|
import { Node as BaseNode } from "@npmcli/arborist";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SafeEdge } from "./edge.js";
|
|
2
|
+
import { SafeNode } from "./node.js";
|
|
3
|
+
interface OverrideSetClass {
|
|
4
|
+
children: Map<string, SafeOverrideSet>;
|
|
5
|
+
key: string | undefined;
|
|
6
|
+
keySpec: string | undefined;
|
|
7
|
+
name: string | undefined;
|
|
8
|
+
parent: SafeOverrideSet | undefined;
|
|
9
|
+
value: string | undefined;
|
|
10
|
+
version: string | undefined;
|
|
11
|
+
new (...args: any[]): OverrideSetClass;
|
|
12
|
+
get isRoot(): boolean;
|
|
13
|
+
get ruleset(): Map<string, SafeOverrideSet>;
|
|
14
|
+
ancestry(): Generator<SafeOverrideSet>;
|
|
15
|
+
childrenAreEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
|
|
16
|
+
getEdgeRule(edge: SafeEdge): SafeOverrideSet;
|
|
17
|
+
getNodeRule(node: SafeNode): SafeOverrideSet;
|
|
18
|
+
getMatchingRule(node: SafeNode): SafeOverrideSet | null;
|
|
19
|
+
isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
|
|
20
|
+
}
|
|
21
|
+
declare const OverrideSet: OverrideSetClass;
|
|
22
|
+
declare class SafeOverrideSet extends OverrideSet {
|
|
23
|
+
// Patch adding doOverrideSetsConflict is based on
|
|
24
|
+
// https://github.com/npm/cli/pull/8089.
|
|
25
|
+
static doOverrideSetsConflict(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): boolean;
|
|
26
|
+
// Patch adding findSpecificOverrideSet is based on
|
|
27
|
+
// https://github.com/npm/cli/pull/8089.
|
|
28
|
+
static findSpecificOverrideSet(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): SafeOverrideSet | undefined;
|
|
29
|
+
// Patch adding childrenAreEqual is based on
|
|
30
|
+
// https://github.com/npm/cli/pull/8089.
|
|
31
|
+
childrenAreEqual(otherOverrideSet: SafeOverrideSet): boolean;
|
|
32
|
+
getEdgeRule(edge: SafeEdge): SafeOverrideSet;
|
|
33
|
+
// Patch adding isEqual is based on
|
|
34
|
+
// https://github.com/npm/cli/pull/8089.
|
|
35
|
+
isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
|
|
36
|
+
}
|
|
37
|
+
export { SafeOverrideSet };
|
|
@@ -6,6 +6,5 @@ declare function findBinPathDetailsSync(binName: string): {
|
|
|
6
6
|
shadowed: boolean;
|
|
7
7
|
};
|
|
8
8
|
declare function findNpmPathSync(npmBinPath: string): string | undefined;
|
|
9
|
-
declare function
|
|
10
|
-
|
|
11
|
-
export { findBinPathDetailsSync, findNpmPathSync, getPackageFiles, getPackageFilesFullScans };
|
|
9
|
+
declare function getPackageFilesFullScans(cwd: string, inputPaths: string[], supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], config?: SocketYml | undefined): Promise<string[]>;
|
|
10
|
+
export { findBinPathDetailsSync, findNpmPathSync, getPackageFilesFullScans };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function shadowBin(binName: 'npm' | 'npx', args?: string[]): Promise<void>;
|
|
1
|
+
declare function shadowBin(binName: 'npm' | 'npx', args?: string[], level?: number): Promise<void>;
|
|
2
2
|
export { shadowBin as default };
|
|
@@ -14,7 +14,7 @@ var npm = require('@socketsecurity/registry/lib/npm');
|
|
|
14
14
|
var spawn = require('@socketsecurity/registry/lib/spawn');
|
|
15
15
|
var path = require('node:path');
|
|
16
16
|
var cmdShim = _socketInterop(require('cmd-shim'));
|
|
17
|
-
var
|
|
17
|
+
var shadowNpmPaths = require('./shadow-npm-paths.js');
|
|
18
18
|
var constants = require('./constants.js');
|
|
19
19
|
|
|
20
20
|
const {
|
|
@@ -24,7 +24,7 @@ const {
|
|
|
24
24
|
async function installLinks(realBinPath, binName) {
|
|
25
25
|
const isNpx = binName === NPX;
|
|
26
26
|
// Find package manager being shadowed by this process.
|
|
27
|
-
const binPath = isNpx ?
|
|
27
|
+
const binPath = isNpx ? shadowNpmPaths.getNpxBinPath() : shadowNpmPaths.getNpmBinPath();
|
|
28
28
|
// Lazily access constants.WIN32.
|
|
29
29
|
const {
|
|
30
30
|
WIN32
|
|
@@ -33,7 +33,7 @@ async function installLinks(realBinPath, binName) {
|
|
|
33
33
|
if (WIN32 && binPath) {
|
|
34
34
|
return binPath;
|
|
35
35
|
}
|
|
36
|
-
const shadowed = isNpx ?
|
|
36
|
+
const shadowed = isNpx ? shadowNpmPaths.isNpxBinPathShadowed() : shadowNpmPaths.isNpmBinPathShadowed();
|
|
37
37
|
// Move our bin directory to front of PATH so its found first.
|
|
38
38
|
if (!shadowed) {
|
|
39
39
|
if (WIN32) {
|
|
@@ -47,22 +47,14 @@ async function installLinks(realBinPath, binName) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const {
|
|
50
|
-
NPM,
|
|
51
|
-
SOCKET_CLI_LEGACY_PACKAGE_NAME,
|
|
52
|
-
SOCKET_CLI_PACKAGE_NAME,
|
|
53
50
|
SOCKET_CLI_SAFE_WRAPPER,
|
|
54
51
|
SOCKET_CLI_SENTRY_BUILD,
|
|
55
|
-
SOCKET_CLI_SENTRY_PACKAGE_NAME,
|
|
56
52
|
SOCKET_IPC_HANDSHAKE
|
|
57
53
|
} = constants;
|
|
58
|
-
async function shadowBin(binName, args = process.argv.slice(2)) {
|
|
54
|
+
async function shadowBin(binName, args = process.argv.slice(2), level = 1) {
|
|
59
55
|
process.exitCode = 1;
|
|
60
56
|
const terminatorPos = args.indexOf('--');
|
|
61
|
-
const
|
|
62
|
-
let binArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos);
|
|
63
|
-
if (!skipSocketCliUpgrade) {
|
|
64
|
-
binArgs = binArgs.filter(a => !npm.isProgressFlag(a));
|
|
65
|
-
}
|
|
57
|
+
const binArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isProgressFlag(a));
|
|
66
58
|
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
67
59
|
const spawnPromise = spawn.spawn(
|
|
68
60
|
// Lazily access constants.execPath.
|
|
@@ -71,17 +63,17 @@ async function shadowBin(binName, args = process.argv.slice(2)) {
|
|
|
71
63
|
...constants.nodeNoWarningsFlags,
|
|
72
64
|
// Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].
|
|
73
65
|
...(constants.ENV[SOCKET_CLI_SENTRY_BUILD] ? ['--require',
|
|
74
|
-
// Lazily access constants.
|
|
75
|
-
constants.
|
|
76
|
-
// Lazily access constants.
|
|
77
|
-
constants.
|
|
66
|
+
// Lazily access constants.distInstrumentWithSentryPath.
|
|
67
|
+
constants.distInstrumentWithSentryPath] : []), '--require',
|
|
68
|
+
// Lazily access constants.distShadowNpmInjectPath.
|
|
69
|
+
constants.distShadowNpmInjectPath,
|
|
78
70
|
// Lazily access constants.shadowBinPath.
|
|
79
71
|
await installLinks(constants.shadowBinPath, binName),
|
|
80
|
-
// Add `--no-progress` and `--
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
// Add the '--
|
|
84
|
-
...(binArgs.some(npm.isLoglevelFlag) ? [] :
|
|
72
|
+
// Add `--no-progress` and `--loglevel=error` flags to fix input being
|
|
73
|
+
// swallowed by the npm spinner.
|
|
74
|
+
'--no-progress',
|
|
75
|
+
// Add the '--loglevel=error' flag if a loglevel flag is not provided.
|
|
76
|
+
...(binArgs.some(npm.isLoglevelFlag) ? [] : ['--loglevel', 'error']), ...binArgs, ...otherArgs], {
|
|
85
77
|
// 'inherit' + 'ipc'
|
|
86
78
|
stdio: [0, 1, 2, 'ipc']
|
|
87
79
|
});
|
|
@@ -95,12 +87,12 @@ async function shadowBin(binName, args = process.argv.slice(2)) {
|
|
|
95
87
|
});
|
|
96
88
|
spawnPromise.process.send({
|
|
97
89
|
[SOCKET_IPC_HANDSHAKE]: {
|
|
98
|
-
[SOCKET_CLI_SAFE_WRAPPER]:
|
|
90
|
+
[SOCKET_CLI_SAFE_WRAPPER]: level
|
|
99
91
|
}
|
|
100
92
|
});
|
|
101
93
|
await spawnPromise;
|
|
102
94
|
}
|
|
103
95
|
|
|
104
96
|
module.exports = shadowBin;
|
|
105
|
-
//# debugId=
|
|
97
|
+
//# debugId=c58c4335-92d0-4ad1-86bf-6eb5428f654a
|
|
106
98
|
//# sourceMappingURL=shadow-bin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow-bin.js","sources":["../../src/shadow/link.ts","../../src/shadow/
|
|
1
|
+
{"version":3,"file":"shadow-bin.js","sources":["../../src/shadow/npm/link.ts","../../src/shadow/npm/bin.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\n\nimport cmdShim from 'cmd-shim'\n\nimport {\n getNpmBinPath,\n getNpxBinPath,\n isNpmBinPathShadowed,\n isNpxBinPathShadowed\n} from './paths'\nimport constants from '../../constants'\n\nconst { CLI, NPX } = constants\n\nexport async function installLinks(\n realBinPath: string,\n binName: 'npm' | 'npx'\n): Promise<string> {\n const isNpx = binName === NPX\n // Find package manager being shadowed by this process.\n const binPath = isNpx ? getNpxBinPath() : getNpmBinPath()\n // Lazily access constants.WIN32.\n const { WIN32 } = constants\n // TODO: Is this early exit needed?\n if (WIN32 && binPath) {\n return binPath\n }\n const shadowed = isNpx ? isNpxBinPathShadowed() : isNpmBinPathShadowed()\n // Move our bin directory to front of PATH so its found first.\n if (!shadowed) {\n if (WIN32) {\n await cmdShim(\n // Lazily access constants.rootDistPath.\n path.join(constants.rootDistPath, `${binName}-${CLI}.js`),\n path.join(realBinPath, binName)\n )\n }\n process.env['PATH'] =\n `${realBinPath}${path.delimiter}${process.env['PATH']}`\n }\n return binPath\n}\n","import process from 'node:process'\n\nimport {\n isLoglevelFlag,\n isProgressFlag\n} from '@socketsecurity/registry/lib/npm'\nimport { spawn } from '@socketsecurity/registry/lib/spawn'\n\nimport { installLinks } from './link'\nimport constants from '../../constants'\n\nconst {\n SOCKET_CLI_SAFE_WRAPPER,\n SOCKET_CLI_SENTRY_BUILD,\n SOCKET_IPC_HANDSHAKE\n} = constants\n\nexport default async function shadowBin(\n binName: 'npm' | 'npx',\n args = process.argv.slice(2),\n level = 1\n) {\n process.exitCode = 1\n const terminatorPos = args.indexOf('--')\n const binArgs = (\n terminatorPos === -1 ? args : args.slice(0, terminatorPos)\n ).filter(a => !isProgressFlag(a))\n const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)\n const spawnPromise = spawn(\n // Lazily access constants.execPath.\n constants.execPath,\n [\n // Lazily access constants.nodeNoWarningsFlags.\n ...constants.nodeNoWarningsFlags,\n // Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].\n ...(constants.ENV[SOCKET_CLI_SENTRY_BUILD]\n ? [\n '--require',\n // Lazily access constants.distInstrumentWithSentryPath.\n constants.distInstrumentWithSentryPath\n ]\n : []),\n '--require',\n // Lazily access constants.distShadowNpmInjectPath.\n constants.distShadowNpmInjectPath,\n // Lazily access constants.shadowBinPath.\n await installLinks(constants.shadowBinPath, binName),\n // Add `--no-progress` and `--loglevel=error` flags to fix input being\n // swallowed by the npm spinner.\n '--no-progress',\n // Add the '--loglevel=error' flag if a loglevel flag is not provided.\n ...(binArgs.some(isLoglevelFlag) ? [] : ['--loglevel', 'error']),\n ...binArgs,\n ...otherArgs\n ],\n {\n // 'inherit' + 'ipc'\n stdio: [0, 1, 2, 'ipc']\n }\n )\n // See https://nodejs.org/api/all.html#all_child_process_event-exit.\n spawnPromise.process.on('exit', (code, signalName) => {\n if (signalName) {\n process.kill(process.pid, signalName)\n } else if (code !== null) {\n process.exit(code)\n }\n })\n spawnPromise.process.send({\n [SOCKET_IPC_HANDSHAKE]: {\n [SOCKET_CLI_SAFE_WRAPPER]: level\n }\n })\n await spawnPromise\n}\n"],"names":["NPX","WIN32","process","SOCKET_IPC_HANDSHAKE","constants","spawnPromise"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA;;AAAaA;AAAI;AAEV;AAIL;AACA;;AAEA;;AACQC;AAAM;AACd;;AAEE;AACF;;AAEA;;AAEE;AACE;AACE;;AAIJ;AACAC;AAEF;AACA;AACF;;AC/BA;;;AAGEC;AACF;AAEe;;AAMb;AACA;AAGA;;AAEE;;AAGE;;AAEA;;AAIM;AACAC;AAIN;AACAA;AACA;AACA;AACA;AACA;;AAEA;;AAMA;;AAEF;AAEF;;AAEE;;AAEA;AACEF;AACF;AACF;AACAG;AACE;AACE;AACF;AACF;AACA;AACF;;","debugId":"c58c4335-92d0-4ad1-86bf-6eb5428f654a"}
|
|
@@ -38,7 +38,7 @@ var logger = require('@socketsecurity/registry/lib/logger');
|
|
|
38
38
|
var terminalLink = _socketInterop(require('terminal-link'));
|
|
39
39
|
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
40
40
|
var indentString = require('@socketregistry/indent-string/index.cjs');
|
|
41
|
-
var
|
|
41
|
+
var shadowNpmPaths = require('./shadow-npm-paths.js');
|
|
42
42
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
43
43
|
|
|
44
44
|
const {
|
|
@@ -387,8 +387,9 @@ async function* createBatchGenerator(chunk) {
|
|
|
387
387
|
method: 'POST',
|
|
388
388
|
headers: {
|
|
389
389
|
Authorization: `Basic ${btoa(`${getPublicToken()}:`)}`
|
|
390
|
-
}
|
|
391
|
-
|
|
390
|
+
}
|
|
391
|
+
// TODO: Fix to not abort process on network abort.
|
|
392
|
+
// signal: abortSignal
|
|
392
393
|
}).end(JSON.stringify({
|
|
393
394
|
components: chunk.map(id => ({
|
|
394
395
|
purl: `pkg:npm/${id}`
|
|
@@ -699,13 +700,6 @@ void (async () => {
|
|
|
699
700
|
_uxLookup = createAlertUXLookup(settings);
|
|
700
701
|
})();
|
|
701
702
|
|
|
702
|
-
const markdownLogSymbols = Object.freeze({
|
|
703
|
-
__proto__: null,
|
|
704
|
-
info: ':information_source:',
|
|
705
|
-
error: ':stop_sign:',
|
|
706
|
-
success: ':white_check_mark:',
|
|
707
|
-
warning: ':warning:'
|
|
708
|
-
});
|
|
709
703
|
class ColorOrMarkdown {
|
|
710
704
|
constructor(useMarkdown) {
|
|
711
705
|
this.useMarkdown = !!useMarkdown;
|
|
@@ -740,9 +734,6 @@ class ColorOrMarkdown {
|
|
|
740
734
|
const indentedContent = items.map(item => this.indent(item).trimStart());
|
|
741
735
|
return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
|
|
742
736
|
}
|
|
743
|
-
get logSymbols() {
|
|
744
|
-
return this.useMarkdown ? markdownLogSymbols : logger.Logger.LOG_SYMBOLS;
|
|
745
|
-
}
|
|
746
737
|
}
|
|
747
738
|
|
|
748
739
|
function getSocketDevAlertUrl(alertType) {
|
|
@@ -752,7 +743,7 @@ function getSocketDevPackageOverviewUrl(eco, name, version) {
|
|
|
752
743
|
return `https://socket.dev/${eco}/package/${name}${version ? `/overview/${version}` : ''}`;
|
|
753
744
|
}
|
|
754
745
|
|
|
755
|
-
const depValid = require(
|
|
746
|
+
const depValid = require(shadowNpmPaths.getArboristDepValidPath());
|
|
756
747
|
|
|
757
748
|
const {
|
|
758
749
|
UNDEFINED_TOKEN
|
|
@@ -782,7 +773,7 @@ function tryRequire(req, ...ids) {
|
|
|
782
773
|
let _log = UNDEFINED_TOKEN;
|
|
783
774
|
function getLogger() {
|
|
784
775
|
if (_log === UNDEFINED_TOKEN) {
|
|
785
|
-
_log = tryRequire(
|
|
776
|
+
_log = tryRequire(shadowNpmPaths.getNpmRequire(), ['proc-log/lib/index.js',
|
|
786
777
|
// The proc-log DefinitelyTyped definition is incorrect. The type definition
|
|
787
778
|
// is really that of its export log.
|
|
788
779
|
mod => mod.log], 'npmlog/lib/log.js');
|
|
@@ -790,7 +781,7 @@ function getLogger() {
|
|
|
790
781
|
return _log;
|
|
791
782
|
}
|
|
792
783
|
|
|
793
|
-
const OverrideSet = require(
|
|
784
|
+
const OverrideSet = require(shadowNpmPaths.getArboristOverrideSetClassPath());
|
|
794
785
|
|
|
795
786
|
// Implementation code not related to patch https://github.com/npm/cli/pull/8089
|
|
796
787
|
// is based on https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/override-set.js:
|
|
@@ -908,7 +899,7 @@ class SafeOverrideSet extends OverrideSet {
|
|
|
908
899
|
}
|
|
909
900
|
}
|
|
910
901
|
|
|
911
|
-
const Node = require(
|
|
902
|
+
const Node = require(shadowNpmPaths.getArboristNodeClassPath());
|
|
912
903
|
|
|
913
904
|
// Implementation code not related to patch https://github.com/npm/cli/pull/8089
|
|
914
905
|
// is based on https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/node.js:
|
|
@@ -1204,7 +1195,7 @@ class SafeNode extends Node {
|
|
|
1204
1195
|
}
|
|
1205
1196
|
}
|
|
1206
1197
|
|
|
1207
|
-
const Edge = require(
|
|
1198
|
+
const Edge = require(shadowNpmPaths.getArboristEdgeClassPath());
|
|
1208
1199
|
|
|
1209
1200
|
// The Edge class makes heavy use of private properties which subclasses do NOT
|
|
1210
1201
|
// have access to. So we have to recreate any functionality that relies on those
|
|
@@ -1577,6 +1568,7 @@ async function getPackagesAlerts(arb, options) {
|
|
|
1577
1568
|
consolidate = false,
|
|
1578
1569
|
includeExisting = false,
|
|
1579
1570
|
includeUnfixable = true,
|
|
1571
|
+
includeUpgrades = false,
|
|
1580
1572
|
output
|
|
1581
1573
|
} = {
|
|
1582
1574
|
__proto__: null,
|
|
@@ -1633,7 +1625,7 @@ async function getPackagesAlerts(arb, options) {
|
|
|
1633
1625
|
}
|
|
1634
1626
|
const fixableCve = isArtifactAlertCveFixable(alert);
|
|
1635
1627
|
const fixableUpgrade = isArtifactAlertUpgradeFixable(alert);
|
|
1636
|
-
if (
|
|
1628
|
+
if (includeUnfixable || fixableCve || includeUpgrades && fixableUpgrade && !hasOverride(pkgJson, name)) {
|
|
1637
1629
|
sockPkgAlerts.push({
|
|
1638
1630
|
name,
|
|
1639
1631
|
version,
|
|
@@ -1751,14 +1743,16 @@ function getCveInfoByPackage(alerts, options) {
|
|
|
1751
1743
|
}
|
|
1752
1744
|
return infoByPkg;
|
|
1753
1745
|
}
|
|
1746
|
+
const kCtorArgs = Symbol('ctorArgs');
|
|
1754
1747
|
const kRiskyReify = Symbol('riskyReify');
|
|
1755
|
-
async function reify(
|
|
1748
|
+
async function reify(arb, args, level = 1) {
|
|
1756
1749
|
const {
|
|
1757
1750
|
stderr: output,
|
|
1758
1751
|
stdin: input
|
|
1759
1752
|
} = process;
|
|
1760
|
-
const alerts = await getPackagesAlerts(
|
|
1761
|
-
output
|
|
1753
|
+
const alerts = await getPackagesAlerts(arb, {
|
|
1754
|
+
output,
|
|
1755
|
+
includeUnfixable: level < 2
|
|
1762
1756
|
});
|
|
1763
1757
|
if (alerts.length && !(await prompts.confirm({
|
|
1764
1758
|
message: 'Accept risks of installing these packages?',
|
|
@@ -1769,21 +1763,17 @@ async function reify(...args) {
|
|
|
1769
1763
|
}))) {
|
|
1770
1764
|
throw new Error('Socket npm exiting due to risks');
|
|
1771
1765
|
}
|
|
1772
|
-
return await
|
|
1766
|
+
return await arb[kRiskyReify](...args);
|
|
1773
1767
|
}
|
|
1774
1768
|
|
|
1775
1769
|
const {
|
|
1776
|
-
SOCKET_CLI_LEGACY_PACKAGE_NAME,
|
|
1777
|
-
SOCKET_CLI_PACKAGE_NAME,
|
|
1778
|
-
SOCKET_CLI_SENTRY_PACKAGE_NAME,
|
|
1779
1770
|
SOCKET_CLI_SAFE_WRAPPER,
|
|
1780
1771
|
kInternalsSymbol,
|
|
1781
1772
|
[kInternalsSymbol]: {
|
|
1782
1773
|
getIPC
|
|
1783
1774
|
}
|
|
1784
1775
|
} = constants;
|
|
1785
|
-
const Arborist = require(
|
|
1786
|
-
const kCtorArgs = Symbol('ctorArgs');
|
|
1776
|
+
const Arborist = require(shadowNpmPaths.getArboristClassPath());
|
|
1787
1777
|
const SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
|
|
1788
1778
|
__proto__: null,
|
|
1789
1779
|
audit: false,
|
|
@@ -1813,8 +1803,6 @@ class SafeArborist extends Arborist {
|
|
|
1813
1803
|
...(ctorArgs.length ? ctorArgs[0] : undefined),
|
|
1814
1804
|
progress: false
|
|
1815
1805
|
}, ...ctorArgs.slice(1));
|
|
1816
|
-
arb.actualTree = this.actualTree;
|
|
1817
|
-
arb.idealTree = this.idealTree;
|
|
1818
1806
|
const ret = await arb.reify({
|
|
1819
1807
|
...(args.length ? args[0] : undefined),
|
|
1820
1808
|
progress: false
|
|
@@ -1829,11 +1817,11 @@ class SafeArborist extends Arborist {
|
|
|
1829
1817
|
__proto__: null,
|
|
1830
1818
|
...(args.length ? args[0] : undefined)
|
|
1831
1819
|
};
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
}
|
|
1835
|
-
const
|
|
1836
|
-
if (
|
|
1820
|
+
if (options.dryRun) {
|
|
1821
|
+
return await this[kRiskyReify](...args);
|
|
1822
|
+
}
|
|
1823
|
+
const level = await getIPC(SOCKET_CLI_SAFE_WRAPPER);
|
|
1824
|
+
if (!level) {
|
|
1837
1825
|
return await this[kRiskyReify](...args);
|
|
1838
1826
|
}
|
|
1839
1827
|
const safeArgs = [{
|
|
@@ -1845,19 +1833,36 @@ class SafeArborist extends Arborist {
|
|
|
1845
1833
|
args[0] = options;
|
|
1846
1834
|
await super.reify(...safeArgs);
|
|
1847
1835
|
args[0] = old;
|
|
1848
|
-
return await
|
|
1836
|
+
return await reify(this, args, level);
|
|
1849
1837
|
}
|
|
1850
1838
|
}
|
|
1851
1839
|
|
|
1840
|
+
function installSafeArborist() {
|
|
1841
|
+
// Override '@npmcli/arborist' module exports with patched variants based on
|
|
1842
|
+
// https://github.com/npm/cli/pull/8089.
|
|
1843
|
+
const cache = require.cache;
|
|
1844
|
+
cache[shadowNpmPaths.getArboristClassPath()] = {
|
|
1845
|
+
exports: SafeArborist
|
|
1846
|
+
};
|
|
1847
|
+
cache[shadowNpmPaths.getArboristEdgeClassPath()] = {
|
|
1848
|
+
exports: SafeEdge
|
|
1849
|
+
};
|
|
1850
|
+
cache[shadowNpmPaths.getArboristNodeClassPath()] = {
|
|
1851
|
+
exports: SafeNode
|
|
1852
|
+
};
|
|
1853
|
+
cache[shadowNpmPaths.getArboristOverrideSetClassPath()] = {
|
|
1854
|
+
exports: SafeOverrideSet
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
installSafeArborist();
|
|
1859
|
+
|
|
1852
1860
|
exports.Arborist = Arborist;
|
|
1853
1861
|
exports.AuthError = AuthError;
|
|
1854
1862
|
exports.ColorOrMarkdown = ColorOrMarkdown;
|
|
1855
1863
|
exports.InputError = InputError;
|
|
1856
1864
|
exports.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES = SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES;
|
|
1857
1865
|
exports.SafeArborist = SafeArborist;
|
|
1858
|
-
exports.SafeEdge = SafeEdge;
|
|
1859
|
-
exports.SafeNode = SafeNode;
|
|
1860
|
-
exports.SafeOverrideSet = SafeOverrideSet;
|
|
1861
1866
|
exports.captureException = captureException;
|
|
1862
1867
|
exports.findPackageNodes = findPackageNodes;
|
|
1863
1868
|
exports.findUp = findUp;
|
|
@@ -1874,5 +1879,5 @@ exports.safeReadFile = safeReadFile;
|
|
|
1874
1879
|
exports.setupSdk = setupSdk;
|
|
1875
1880
|
exports.updateNode = updateNode;
|
|
1876
1881
|
exports.updateSetting = updateSetting;
|
|
1877
|
-
//# debugId=
|
|
1878
|
-
//# sourceMappingURL=
|
|
1882
|
+
//# debugId=a2461f74-6908-4fea-b499-5d8392a553ba
|
|
1883
|
+
//# sourceMappingURL=shadow-npm-inject.js.map
|