@socketsecurity/cli-with-sentry 1.0.111 → 1.1.1
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/dist/cli.js +242 -1590
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +6 -5
- package/dist/constants.js.map +1 -1
- package/dist/shadow-npm-bin.js +12 -6
- package/dist/shadow-npm-bin.js.map +1 -1
- package/dist/shadow-npm-inject.js +24 -243
- package/dist/shadow-npm-inject.js.map +1 -1
- package/dist/socket-completion.bash +1 -1
- package/dist/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/coana-fix.d.mts +1 -1
- package/dist/types/commands/fix/coana-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/{fix-env-helpers.d.mts → env-helpers.d.mts} +1 -1
- package/dist/types/commands/fix/env-helpers.d.mts.map +1 -0
- package/dist/types/commands/fix/git.d.mts +13 -0
- package/dist/types/commands/fix/git.d.mts.map +1 -0
- package/dist/types/commands/fix/handle-fix.d.mts +1 -1
- package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/pull-request.d.mts +10 -53
- package/dist/types/commands/fix/pull-request.d.mts.map +1 -1
- package/dist/types/commands/fix/types.d.mts +18 -0
- package/dist/types/commands/fix/types.d.mts.map +1 -0
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts +2 -0
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts.map +1 -1
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/shadow/npm/arborist/lib/arborist/index.d.mts.map +1 -1
- package/dist/types/shadow/npm/arborist-helpers.d.mts +1 -1
- package/dist/types/shadow/npm/arborist-helpers.d.mts.map +1 -1
- package/dist/types/shadow/npm/bin.d.mts.map +1 -1
- package/dist/types/shadow/npm/paths.d.mts +0 -1
- package/dist/types/shadow/npm/paths.d.mts.map +1 -1
- package/dist/types/utils/alerts-map.d.mts.map +1 -1
- package/dist/types/utils/fs.d.mts +3 -2
- package/dist/types/utils/fs.d.mts.map +1 -1
- package/dist/types/utils/github.d.mts +38 -0
- package/dist/types/utils/github.d.mts.map +1 -0
- package/dist/types/utils/glob.d.mts +0 -1
- package/dist/types/utils/glob.d.mts.map +1 -1
- package/dist/utils.js +843 -888
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +112511 -119840
- package/external/@socketsecurity/registry/external/libnpmpack.js +96569 -41361
- package/external/@socketsecurity/registry/external/pacote.js +77357 -68133
- package/external/@socketsecurity/registry/lib/fs.js +13 -27
- package/external/@socketsecurity/registry/lib/json.js +42 -0
- package/external/@socketsecurity/registry/manifest.json +4 -4
- package/package.json +11 -11
- package/dist/types/commands/fix/agent-fix.d.mts +0 -42
- package/dist/types/commands/fix/agent-fix.d.mts.map +0 -1
- package/dist/types/commands/fix/fix-branch-helpers.d.mts +0 -4
- package/dist/types/commands/fix/fix-branch-helpers.d.mts.map +0 -1
- package/dist/types/commands/fix/fix-env-helpers.d.mts.map +0 -1
- package/dist/types/commands/fix/get-actual-tree.d.mts +0 -3
- package/dist/types/commands/fix/get-actual-tree.d.mts.map +0 -1
- package/dist/types/commands/fix/npm-fix.d.mts +0 -7
- package/dist/types/commands/fix/npm-fix.d.mts.map +0 -1
- package/dist/types/commands/fix/pnpm-fix.d.mts +0 -7
- package/dist/types/commands/fix/pnpm-fix.d.mts.map +0 -1
- package/dist/types/commands/fix/shared.d.mts +0 -10
- package/dist/types/commands/fix/shared.d.mts.map +0 -1
- package/dist/types/commands/fix/socket-git.d.mts +0 -32
- package/dist/types/commands/fix/socket-git.d.mts.map +0 -1
package/dist/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ var vendor = require('./vendor.js');
|
|
|
4
4
|
var logger = require('../external/@socketsecurity/registry/lib/logger');
|
|
5
5
|
var strings = require('../external/@socketsecurity/registry/lib/strings');
|
|
6
6
|
var require$$9 = require('../external/@socketsecurity/registry/lib/debug');
|
|
7
|
-
var require$$
|
|
7
|
+
var require$$11 = require('../external/@socketsecurity/registry/lib/objects');
|
|
8
8
|
var arrays = require('../external/@socketsecurity/registry/lib/arrays');
|
|
9
9
|
var path$1 = require('../external/@socketsecurity/registry/lib/path');
|
|
10
10
|
var sorts = require('../external/@socketsecurity/registry/lib/sorts');
|
|
@@ -19,12 +19,11 @@ var spawn = require('../external/@socketsecurity/registry/lib/spawn');
|
|
|
19
19
|
var fs = require('../external/@socketsecurity/registry/lib/fs');
|
|
20
20
|
var shadowNpmBin = require('./shadow-npm-bin.js');
|
|
21
21
|
var fs$1 = require('node:fs');
|
|
22
|
-
var
|
|
23
|
-
var packages = require('../external/@socketsecurity/registry/lib/packages');
|
|
22
|
+
var promises = require('node:timers/promises');
|
|
24
23
|
var npm = require('../external/@socketsecurity/registry/lib/npm');
|
|
25
|
-
var streams = require('../external/@socketsecurity/registry/lib/streams');
|
|
26
24
|
var globs = require('../external/@socketsecurity/registry/lib/globs');
|
|
27
|
-
var
|
|
25
|
+
var packages = require('../external/@socketsecurity/registry/lib/packages');
|
|
26
|
+
var streams = require('../external/@socketsecurity/registry/lib/streams');
|
|
28
27
|
|
|
29
28
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
30
29
|
const sensitiveConfigKeyLookup = new Set(['apiToken']);
|
|
@@ -761,7 +760,7 @@ cols) {
|
|
|
761
760
|
// Serialize the final result object before printing it
|
|
762
761
|
// All commands that support the --json flag should call this before printing
|
|
763
762
|
function serializeResultJson(data) {
|
|
764
|
-
if (!require$$
|
|
763
|
+
if (!require$$11.isObject(data)) {
|
|
765
764
|
process.exitCode = 1;
|
|
766
765
|
require$$9.debugFn('inspect', {
|
|
767
766
|
data
|
|
@@ -917,7 +916,7 @@ function getHelpListOutput(list, options) {
|
|
|
917
916
|
const names = Object.keys(list).sort(sorts.naturalCompare);
|
|
918
917
|
for (const name of names) {
|
|
919
918
|
const entry = list[name];
|
|
920
|
-
const entryIsObj = require$$
|
|
919
|
+
const entryIsObj = require$$11.isObject(entry);
|
|
921
920
|
if (entryIsObj && 'hidden' in entry && entry?.hidden) {
|
|
922
921
|
continue;
|
|
923
922
|
}
|
|
@@ -1184,10 +1183,10 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1184
1183
|
} else {
|
|
1185
1184
|
lines.push('Commands');
|
|
1186
1185
|
lines.push(` ${getHelpListOutput({
|
|
1187
|
-
...require$$
|
|
1186
|
+
...require$$11.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
|
|
1188
1187
|
1: subcommand
|
|
1189
1188
|
}) => !subcommand.hidden))),
|
|
1190
|
-
...require$$
|
|
1189
|
+
...require$$11.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(({
|
|
1191
1190
|
1: alias
|
|
1192
1191
|
}) => {
|
|
1193
1192
|
const {
|
|
@@ -1306,7 +1305,7 @@ function meowOrExit({
|
|
|
1306
1305
|
}
|
|
1307
1306
|
|
|
1308
1307
|
// meow doesn't detect 'version' as an unknown flag, so we do the leg work here.
|
|
1309
|
-
if (!require$$
|
|
1308
|
+
if (!require$$11.hasOwn(config.flags, 'version') && cli.flags['version']) {
|
|
1310
1309
|
// Use `console.error` here instead of `logger.error` to match meow behavior.
|
|
1311
1310
|
console.error('Unknown flag\n--version');
|
|
1312
1311
|
// eslint-disable-next-line n/no-process-exit
|
|
@@ -2266,13 +2265,6 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
2266
2265
|
}
|
|
2267
2266
|
return filtered;
|
|
2268
2267
|
}
|
|
2269
|
-
async function globStreamNodeModules(cwd = process.cwd()) {
|
|
2270
|
-
return vendor.outExports.globStream('**/node_modules', {
|
|
2271
|
-
absolute: true,
|
|
2272
|
-
cwd,
|
|
2273
|
-
onlyDirectories: true
|
|
2274
|
-
});
|
|
2275
|
-
}
|
|
2276
2268
|
async function globWorkspace(agent, cwd = process.cwd()) {
|
|
2277
2269
|
const workspaceGlobs = await getWorkspaceGlobs(agent, cwd);
|
|
2278
2270
|
return workspaceGlobs.length ? await vendor.outExports.glob(workspaceGlobs, {
|
|
@@ -2496,6 +2488,52 @@ function isHelpFlag(cmdArg) {
|
|
|
2496
2488
|
return helpFlags.has(cmdArg);
|
|
2497
2489
|
}
|
|
2498
2490
|
|
|
2491
|
+
async function findUp(name, options) {
|
|
2492
|
+
const opts = {
|
|
2493
|
+
__proto__: null,
|
|
2494
|
+
...options
|
|
2495
|
+
};
|
|
2496
|
+
const {
|
|
2497
|
+
cwd = process.cwd(),
|
|
2498
|
+
signal = constants.abortSignal
|
|
2499
|
+
} = opts;
|
|
2500
|
+
let {
|
|
2501
|
+
onlyDirectories = false,
|
|
2502
|
+
onlyFiles = true
|
|
2503
|
+
} = opts;
|
|
2504
|
+
if (onlyDirectories) {
|
|
2505
|
+
onlyFiles = false;
|
|
2506
|
+
}
|
|
2507
|
+
if (onlyFiles) {
|
|
2508
|
+
onlyDirectories = false;
|
|
2509
|
+
}
|
|
2510
|
+
let dir = path.resolve(cwd);
|
|
2511
|
+
const {
|
|
2512
|
+
root
|
|
2513
|
+
} = path.parse(dir);
|
|
2514
|
+
const names = [name].flat();
|
|
2515
|
+
while (dir && dir !== root) {
|
|
2516
|
+
for (const name of names) {
|
|
2517
|
+
if (signal?.aborted) {
|
|
2518
|
+
return undefined;
|
|
2519
|
+
}
|
|
2520
|
+
const thePath = path.join(dir, name);
|
|
2521
|
+
try {
|
|
2522
|
+
// eslint-disable-next-line no-await-in-loop
|
|
2523
|
+
const stats = await fs$1.promises.stat(thePath);
|
|
2524
|
+
if (!onlyDirectories && stats.isFile()) {
|
|
2525
|
+
return thePath;
|
|
2526
|
+
}
|
|
2527
|
+
if (!onlyFiles && stats.isDirectory()) {
|
|
2528
|
+
return thePath;
|
|
2529
|
+
}
|
|
2530
|
+
} catch {}
|
|
2531
|
+
}
|
|
2532
|
+
dir = path.dirname(dir);
|
|
2533
|
+
}
|
|
2534
|
+
return undefined;
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2499
2537
|
function extractTier1ReachabilityScanId(socketFactsFile) {
|
|
2500
2538
|
const json = fs.readJsonSync(socketFactsFile, {
|
|
2501
2539
|
throws: false
|
|
@@ -2678,126 +2716,189 @@ async function writeSocketJson(cwd, sockJson) {
|
|
|
2678
2716
|
};
|
|
2679
2717
|
}
|
|
2680
2718
|
|
|
2681
|
-
function
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2719
|
+
async function readCache(key,
|
|
2720
|
+
// 5 minute in milliseconds time to live (TTL).
|
|
2721
|
+
ttlMs = 5 * 60 * 1000) {
|
|
2722
|
+
const cacheJsonPath = path.join(constants.githubCachePath, `${key}.json`);
|
|
2723
|
+
const stat = fs.safeStatsSync(cacheJsonPath);
|
|
2724
|
+
if (stat) {
|
|
2725
|
+
const isExpired = Date.now() - stat.mtimeMs > ttlMs;
|
|
2726
|
+
if (!isExpired) {
|
|
2727
|
+
return await fs.readJson(cacheJsonPath);
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
return null;
|
|
2686
2731
|
}
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2732
|
+
async function writeCache(key, data) {
|
|
2733
|
+
const {
|
|
2734
|
+
githubCachePath
|
|
2735
|
+
} = constants;
|
|
2736
|
+
const cacheJsonPath = path.join(githubCachePath, `${key}.json`);
|
|
2737
|
+
if (!fs$1.existsSync(githubCachePath)) {
|
|
2738
|
+
await fs$1.promises.mkdir(githubCachePath, {
|
|
2739
|
+
recursive: true
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
await fs.writeJson(cacheJsonPath, data);
|
|
2693
2743
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
upgrade: 'upgrade'
|
|
2699
|
-
});
|
|
2700
|
-
|
|
2701
|
-
const ALERT_SEVERITY = createEnum({
|
|
2702
|
-
critical: 'critical',
|
|
2703
|
-
high: 'high',
|
|
2704
|
-
middle: 'middle',
|
|
2705
|
-
low: 'low'
|
|
2706
|
-
});
|
|
2707
|
-
|
|
2708
|
-
class ColorOrMarkdown {
|
|
2709
|
-
constructor(useMarkdown) {
|
|
2710
|
-
this.useMarkdown = !!useMarkdown;
|
|
2744
|
+
async function cacheFetch(key, fetcher, ttlMs) {
|
|
2745
|
+
// Optionally disable cache.
|
|
2746
|
+
if (constants.ENV.DISABLE_GITHUB_CACHE) {
|
|
2747
|
+
return await fetcher();
|
|
2711
2748
|
}
|
|
2712
|
-
|
|
2713
|
-
|
|
2749
|
+
let data = await readCache(key, ttlMs);
|
|
2750
|
+
if (!data) {
|
|
2751
|
+
data = await fetcher();
|
|
2752
|
+
await writeCache(key, data);
|
|
2714
2753
|
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2754
|
+
return data;
|
|
2755
|
+
}
|
|
2756
|
+
async function fetchGhsaDetails(ids) {
|
|
2757
|
+
const results = new Map();
|
|
2758
|
+
if (!ids.length) {
|
|
2759
|
+
return results;
|
|
2717
2760
|
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2761
|
+
const octokitGraphql = getOctokitGraphql();
|
|
2762
|
+
try {
|
|
2763
|
+
const gqlCacheKey = `${ids.join('-')}-graphql-snapshot`;
|
|
2764
|
+
const aliases = ids.map((id, index) => `advisory${index}: securityAdvisory(ghsaId: "${id}") {
|
|
2765
|
+
ghsaId
|
|
2766
|
+
summary
|
|
2767
|
+
severity
|
|
2768
|
+
publishedAt
|
|
2769
|
+
withdrawnAt
|
|
2770
|
+
vulnerabilities(first: 10) {
|
|
2771
|
+
nodes {
|
|
2772
|
+
package {
|
|
2773
|
+
ecosystem
|
|
2774
|
+
name
|
|
2775
|
+
}
|
|
2776
|
+
vulnerableVersionRange
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
}`).join('\n');
|
|
2780
|
+
const gqlResp = await cacheFetch(gqlCacheKey, () => octokitGraphql(`
|
|
2781
|
+
query {
|
|
2782
|
+
${aliases}
|
|
2783
|
+
}
|
|
2784
|
+
`));
|
|
2785
|
+
for (let i = 0, {
|
|
2786
|
+
length
|
|
2787
|
+
} = ids; i < length; i += 1) {
|
|
2788
|
+
const id = ids[i];
|
|
2789
|
+
const advisoryKey = `advisory${i}`;
|
|
2790
|
+
const advisory = gqlResp?.[advisoryKey];
|
|
2791
|
+
if (advisory && advisory.ghsaId) {
|
|
2792
|
+
results.set(id, advisory);
|
|
2793
|
+
} else {
|
|
2794
|
+
require$$9.debugFn('notice', `miss: no advisory found for ${id}`);
|
|
2795
|
+
}
|
|
2726
2796
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
indent(...args) {
|
|
2730
|
-
return vendor.indentStringExports(...args);
|
|
2731
|
-
}
|
|
2732
|
-
italic(text) {
|
|
2733
|
-
return this.useMarkdown ? `_${text}_` : vendor.yoctocolorsCjsExports.italic(`${text}`);
|
|
2734
|
-
}
|
|
2735
|
-
json(value) {
|
|
2736
|
-
return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
|
|
2797
|
+
} catch (e) {
|
|
2798
|
+
require$$9.debugFn('error', `Failed to fetch GHSA details: ${e?.message || 'Unknown error'}`);
|
|
2737
2799
|
}
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2800
|
+
return results;
|
|
2801
|
+
}
|
|
2802
|
+
let _octokit;
|
|
2803
|
+
function getOctokit() {
|
|
2804
|
+
if (_octokit === undefined) {
|
|
2805
|
+
const {
|
|
2806
|
+
SOCKET_CLI_GITHUB_TOKEN
|
|
2807
|
+
} = constants.ENV;
|
|
2808
|
+
if (!SOCKET_CLI_GITHUB_TOKEN) {
|
|
2809
|
+
require$$9.debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
|
|
2810
|
+
}
|
|
2811
|
+
const octokitOptions = {
|
|
2812
|
+
auth: SOCKET_CLI_GITHUB_TOKEN,
|
|
2813
|
+
baseUrl: constants.ENV.GITHUB_API_URL
|
|
2814
|
+
};
|
|
2815
|
+
require$$9.debugDir('inspect', {
|
|
2816
|
+
octokitOptions
|
|
2817
|
+
});
|
|
2818
|
+
_octokit = new vendor.Octokit(octokitOptions);
|
|
2741
2819
|
}
|
|
2820
|
+
return _octokit;
|
|
2742
2821
|
}
|
|
2743
|
-
|
|
2744
|
-
function
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
if (typeof value === 'boolean' || Array.isArray(value)) {
|
|
2752
|
-
normalized[key] = value;
|
|
2822
|
+
let _octokitGraphql;
|
|
2823
|
+
function getOctokitGraphql() {
|
|
2824
|
+
if (!_octokitGraphql) {
|
|
2825
|
+
const {
|
|
2826
|
+
SOCKET_CLI_GITHUB_TOKEN
|
|
2827
|
+
} = constants.ENV;
|
|
2828
|
+
if (!SOCKET_CLI_GITHUB_TOKEN) {
|
|
2829
|
+
require$$9.debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
|
|
2753
2830
|
}
|
|
2831
|
+
_octokitGraphql = vendor.graphql2.defaults({
|
|
2832
|
+
headers: {
|
|
2833
|
+
authorization: `token ${SOCKET_CLI_GITHUB_TOKEN}`
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2754
2836
|
}
|
|
2755
|
-
return
|
|
2837
|
+
return _octokitGraphql;
|
|
2756
2838
|
}
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
return `<=${version}`;
|
|
2771
|
-
case 'preserve':
|
|
2772
|
-
{
|
|
2773
|
-
const range = new vendor.semverExports.Range(refRange);
|
|
2774
|
-
const {
|
|
2775
|
-
raw
|
|
2776
|
-
} = range;
|
|
2777
|
-
const comparators = range.set.flat();
|
|
2778
|
-
const {
|
|
2779
|
-
length
|
|
2780
|
-
} = comparators;
|
|
2781
|
-
if (length === 1) {
|
|
2782
|
-
const char = /^[<>]=?/.exec(raw)?.[0];
|
|
2783
|
-
if (char) {
|
|
2784
|
-
return `${char}${version}`;
|
|
2785
|
-
}
|
|
2786
|
-
} else if (length === 2) {
|
|
2787
|
-
const char = /^[~^]/.exec(raw)?.[0];
|
|
2788
|
-
if (char) {
|
|
2789
|
-
return `${char}${version}`;
|
|
2839
|
+
async function enablePrAutoMerge({
|
|
2840
|
+
node_id: prId
|
|
2841
|
+
}) {
|
|
2842
|
+
const octokitGraphql = getOctokitGraphql();
|
|
2843
|
+
try {
|
|
2844
|
+
const gqlResp = await octokitGraphql(`
|
|
2845
|
+
mutation EnableAutoMerge($pullRequestId: ID!) {
|
|
2846
|
+
enablePullRequestAutoMerge(input: {
|
|
2847
|
+
pullRequestId: $pullRequestId,
|
|
2848
|
+
mergeMethod: SQUASH
|
|
2849
|
+
}) {
|
|
2850
|
+
pullRequest {
|
|
2851
|
+
number
|
|
2790
2852
|
}
|
|
2791
2853
|
}
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2854
|
+
}`, {
|
|
2855
|
+
pullRequestId: prId
|
|
2856
|
+
});
|
|
2857
|
+
const respPrNumber = gqlResp?.enablePullRequestAutoMerge?.pullRequest?.number;
|
|
2858
|
+
if (respPrNumber) {
|
|
2859
|
+
return {
|
|
2860
|
+
enabled: true
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2863
|
+
} catch (e) {
|
|
2864
|
+
if (e instanceof vendor.GraphqlResponseError && Array.isArray(e.errors) && e.errors.length) {
|
|
2865
|
+
const details = e.errors.map(({
|
|
2866
|
+
message: m
|
|
2867
|
+
}) => m.trim());
|
|
2868
|
+
return {
|
|
2869
|
+
enabled: false,
|
|
2870
|
+
details
|
|
2871
|
+
};
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
return {
|
|
2875
|
+
enabled: false
|
|
2876
|
+
};
|
|
2877
|
+
}
|
|
2878
|
+
async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()) {
|
|
2879
|
+
const {
|
|
2880
|
+
host
|
|
2881
|
+
} = new URL(constants.ENV.GITHUB_SERVER_URL);
|
|
2882
|
+
const url = `https://x-access-token:${token}@${host}/${owner}/${repo}`;
|
|
2883
|
+
const stdioIgnoreOptions = {
|
|
2884
|
+
cwd,
|
|
2885
|
+
stdio: require$$9.isDebug('stdio') ? 'inherit' : 'ignore'
|
|
2886
|
+
};
|
|
2887
|
+
const quotedCmd = `\`git remote set-url origin ${url}\``;
|
|
2888
|
+
require$$9.debugFn('stdio', `spawn: ${quotedCmd}`);
|
|
2889
|
+
try {
|
|
2890
|
+
await spawn.spawn('git', ['remote', 'set-url', 'origin', url], stdioIgnoreOptions);
|
|
2891
|
+
return true;
|
|
2892
|
+
} catch (e) {
|
|
2893
|
+
require$$9.debugFn('error', `caught: ${quotedCmd} failed`);
|
|
2894
|
+
require$$9.debugDir('inspect', {
|
|
2895
|
+
error: e
|
|
2896
|
+
});
|
|
2799
2897
|
}
|
|
2898
|
+
return false;
|
|
2800
2899
|
}
|
|
2900
|
+
|
|
2901
|
+
const RangeStyles = ['caret', 'gt', 'gte', 'lt', 'lte', 'pin', 'preserve', 'tilde'];
|
|
2801
2902
|
function getMajor(version) {
|
|
2802
2903
|
try {
|
|
2803
2904
|
const coerced = vendor.semverExports.coerce(version);
|
|
@@ -2805,657 +2906,124 @@ function getMajor(version) {
|
|
|
2805
2906
|
} catch {}
|
|
2806
2907
|
return null;
|
|
2807
2908
|
}
|
|
2808
|
-
function getMinVersion(range) {
|
|
2809
|
-
try {
|
|
2810
|
-
return vendor.semverExports.minVersion(range);
|
|
2811
|
-
} catch {}
|
|
2812
|
-
return null;
|
|
2813
|
-
}
|
|
2814
2909
|
|
|
2815
|
-
const
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2910
|
+
const COMPLETION_CMD_PREFIX = 'complete -F _socket_completion';
|
|
2911
|
+
function getCompletionSourcingCommand() {
|
|
2912
|
+
// Note: this is exported to distPath in .config/rollup.dist.config.mjs
|
|
2913
|
+
const completionScriptExportPath = path.join(constants.distPath, 'socket-completion.bash');
|
|
2914
|
+
if (!fs$1.existsSync(completionScriptExportPath)) {
|
|
2915
|
+
return {
|
|
2916
|
+
ok: false,
|
|
2917
|
+
message: 'Tab Completion script not found',
|
|
2918
|
+
cause: `Expected to find completion script at \`${completionScriptExportPath}\` but it was not there`
|
|
2919
|
+
};
|
|
2820
2920
|
}
|
|
2821
|
-
return
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
const ALERT_SEVERITY_COLOR = createEnum({
|
|
2825
|
-
critical: 'magenta',
|
|
2826
|
-
high: 'red',
|
|
2827
|
-
middle: 'yellow',
|
|
2828
|
-
low: 'white'
|
|
2829
|
-
});
|
|
2830
|
-
const ALERT_SEVERITY_ORDER = createEnum({
|
|
2831
|
-
critical: 0,
|
|
2832
|
-
high: 1,
|
|
2833
|
-
middle: 2,
|
|
2834
|
-
low: 3,
|
|
2835
|
-
none: 4
|
|
2836
|
-
});
|
|
2837
|
-
const MIN_ABOVE_THE_FOLD_COUNT = 3;
|
|
2838
|
-
const MIN_ABOVE_THE_FOLD_ALERT_COUNT = 1;
|
|
2839
|
-
const format = new ColorOrMarkdown(false);
|
|
2840
|
-
function getHiddenRiskCounts(hiddenAlerts) {
|
|
2841
|
-
const riskCounts = {
|
|
2842
|
-
critical: 0,
|
|
2843
|
-
high: 0,
|
|
2844
|
-
middle: 0,
|
|
2845
|
-
low: 0
|
|
2921
|
+
return {
|
|
2922
|
+
ok: true,
|
|
2923
|
+
data: `source ${completionScriptExportPath}`
|
|
2846
2924
|
};
|
|
2847
|
-
for (const alert of hiddenAlerts) {
|
|
2848
|
-
switch (getAlertSeverityOrder(alert)) {
|
|
2849
|
-
case ALERT_SEVERITY_ORDER.critical:
|
|
2850
|
-
riskCounts.critical += 1;
|
|
2851
|
-
break;
|
|
2852
|
-
case ALERT_SEVERITY_ORDER.high:
|
|
2853
|
-
riskCounts.high += 1;
|
|
2854
|
-
break;
|
|
2855
|
-
case ALERT_SEVERITY_ORDER.middle:
|
|
2856
|
-
riskCounts.middle += 1;
|
|
2857
|
-
break;
|
|
2858
|
-
case ALERT_SEVERITY_ORDER.low:
|
|
2859
|
-
riskCounts.low += 1;
|
|
2860
|
-
break;
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
return riskCounts;
|
|
2864
|
-
}
|
|
2865
|
-
function getHiddenRisksDescription(riskCounts) {
|
|
2866
|
-
const descriptions = [];
|
|
2867
|
-
if (riskCounts.critical) {
|
|
2868
|
-
descriptions.push(`${riskCounts.critical} ${getSeverityLabel('critical')}`);
|
|
2869
|
-
}
|
|
2870
|
-
if (riskCounts.high) {
|
|
2871
|
-
descriptions.push(`${riskCounts.high} ${getSeverityLabel('high')}`);
|
|
2872
|
-
}
|
|
2873
|
-
if (riskCounts.middle) {
|
|
2874
|
-
descriptions.push(`${riskCounts.middle} ${getSeverityLabel('middle')}`);
|
|
2875
|
-
}
|
|
2876
|
-
if (riskCounts.low) {
|
|
2877
|
-
descriptions.push(`${riskCounts.low} ${getSeverityLabel('low')}`);
|
|
2878
|
-
}
|
|
2879
|
-
return `(${descriptions.join('; ')})`;
|
|
2880
2925
|
}
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
if (!
|
|
2884
|
-
return
|
|
2926
|
+
function getBashrcDetails(targetCommandName) {
|
|
2927
|
+
const sourcingCommand = getCompletionSourcingCommand();
|
|
2928
|
+
if (!sourcingCommand.ok) {
|
|
2929
|
+
return sourcingCommand;
|
|
2885
2930
|
}
|
|
2886
2931
|
const {
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
__proto__: null,
|
|
2896
|
-
...options
|
|
2897
|
-
};
|
|
2898
|
-
const name = packages.resolvePackageName(artifact);
|
|
2899
|
-
const filterConfig = toFilterConfig({
|
|
2900
|
-
blocked: true,
|
|
2901
|
-
critical: true,
|
|
2902
|
-
cve: true,
|
|
2903
|
-
...require$$10.getOwn(options, 'filter')
|
|
2904
|
-
});
|
|
2905
|
-
const enabledState = {
|
|
2906
|
-
__proto__: null,
|
|
2907
|
-
...socketYml?.issueRules
|
|
2908
|
-
};
|
|
2909
|
-
let sockPkgAlerts = [];
|
|
2910
|
-
for (const alert of artifact.alerts) {
|
|
2911
|
-
const action = alert.action ?? '';
|
|
2912
|
-
const enabledFlag = enabledState[alert.type];
|
|
2913
|
-
if (action === 'ignore' && enabledFlag !== true || enabledFlag === false) {
|
|
2914
|
-
continue;
|
|
2915
|
-
}
|
|
2916
|
-
const blocked = action === 'error';
|
|
2917
|
-
const critical = alert.severity === ALERT_SEVERITY.critical;
|
|
2918
|
-
const cve = isArtifactAlertCve(alert);
|
|
2919
|
-
const fixType = alert.fix?.type ?? '';
|
|
2920
|
-
const fixableCve = fixType === ALERT_FIX_TYPE.cve;
|
|
2921
|
-
const fixableUpgrade = fixType === ALERT_FIX_TYPE.upgrade;
|
|
2922
|
-
const fixable = fixableCve || fixableUpgrade;
|
|
2923
|
-
const upgradable = fixableUpgrade && !require$$10.hasOwn(overrides, name);
|
|
2924
|
-
if (filterConfig.blocked && blocked || filterConfig.critical && critical || filterConfig.cve && cve || filterConfig.fixable && fixable || filterConfig.upgradable && upgradable) {
|
|
2925
|
-
sockPkgAlerts.push({
|
|
2926
|
-
name,
|
|
2927
|
-
version,
|
|
2928
|
-
key: alert.key,
|
|
2929
|
-
type: alert.type,
|
|
2930
|
-
blocked,
|
|
2931
|
-
critical,
|
|
2932
|
-
ecosystem,
|
|
2933
|
-
fixable,
|
|
2934
|
-
raw: alert,
|
|
2935
|
-
upgradable
|
|
2936
|
-
});
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
if (!sockPkgAlerts.length) {
|
|
2940
|
-
return alertsByPurl;
|
|
2932
|
+
socketAppDataPath
|
|
2933
|
+
} = constants;
|
|
2934
|
+
if (!socketAppDataPath) {
|
|
2935
|
+
return {
|
|
2936
|
+
ok: false,
|
|
2937
|
+
message: 'Could not determine config directory',
|
|
2938
|
+
cause: 'Failed to get config path'
|
|
2939
|
+
};
|
|
2941
2940
|
}
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
version: firstPatchedVersionIdentifier
|
|
2965
|
-
});
|
|
2966
|
-
}
|
|
2967
|
-
} else {
|
|
2968
|
-
unfixableAlerts.push(sockPkgAlert);
|
|
2969
|
-
}
|
|
2970
|
-
} else if (fixType === ALERT_FIX_TYPE.upgrade) {
|
|
2971
|
-
// For Socket Optimize upgrades we assume the highest version available
|
|
2972
|
-
// is compatible. This may change in the future.
|
|
2973
|
-
const highest = highestForUpgrade.get(major)?.version ?? '0.0.0';
|
|
2974
|
-
if (vendor.semverExports.gt(version, highest)) {
|
|
2975
|
-
highestForUpgrade.set(major, {
|
|
2976
|
-
alert: sockPkgAlert,
|
|
2977
|
-
version
|
|
2978
|
-
});
|
|
2979
|
-
}
|
|
2980
|
-
} else {
|
|
2981
|
-
unfixableAlerts.push(sockPkgAlert);
|
|
2982
|
-
}
|
|
2941
|
+
|
|
2942
|
+
// _socket_completion is the function defined in our completion bash script
|
|
2943
|
+
const completionCommand = `${COMPLETION_CMD_PREFIX} ${targetCommandName}`;
|
|
2944
|
+
|
|
2945
|
+
// Location of completion script in config after installing
|
|
2946
|
+
const completionScriptPath = path.join(path.dirname(socketAppDataPath), 'completion', 'socket-completion.bash');
|
|
2947
|
+
const bashrcContent = `# Socket CLI completion for "${targetCommandName}"
|
|
2948
|
+
if [ -f "${completionScriptPath}" ]; then
|
|
2949
|
+
# Load the tab completion script
|
|
2950
|
+
source "${completionScriptPath}"
|
|
2951
|
+
# Tell bash to use this function for tab completion of this function
|
|
2952
|
+
${completionCommand}
|
|
2953
|
+
fi
|
|
2954
|
+
`;
|
|
2955
|
+
return {
|
|
2956
|
+
ok: true,
|
|
2957
|
+
data: {
|
|
2958
|
+
sourcingCommand: sourcingCommand.data,
|
|
2959
|
+
completionCommand,
|
|
2960
|
+
toAddToBashrc: bashrcContent,
|
|
2961
|
+
targetName: targetCommandName,
|
|
2962
|
+
targetPath: completionScriptPath
|
|
2983
2963
|
}
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2966
|
+
|
|
2967
|
+
const {
|
|
2968
|
+
kInternalsSymbol,
|
|
2969
|
+
[kInternalsSymbol]: {
|
|
2970
|
+
getSentry
|
|
2989
2971
|
}
|
|
2990
|
-
|
|
2991
|
-
|
|
2972
|
+
} = constants;
|
|
2973
|
+
class AuthError extends Error {}
|
|
2974
|
+
class InputError extends Error {
|
|
2975
|
+
constructor(message, body) {
|
|
2976
|
+
super(message);
|
|
2977
|
+
this.body = body;
|
|
2992
2978
|
}
|
|
2993
|
-
return alertsByPurl;
|
|
2994
|
-
}
|
|
2995
|
-
function alertsHaveBlocked(alerts) {
|
|
2996
|
-
return alerts.find(a => a.blocked) !== undefined;
|
|
2997
|
-
}
|
|
2998
|
-
function alertsHaveSeverity(alerts, severity) {
|
|
2999
|
-
return alerts.find(a => a.raw.severity === severity) !== undefined;
|
|
3000
|
-
}
|
|
3001
|
-
function alertSeverityComparator(a, b) {
|
|
3002
|
-
// Put the most severe first.
|
|
3003
|
-
return getAlertSeverityOrder(a) - getAlertSeverityOrder(b);
|
|
3004
|
-
}
|
|
3005
|
-
function getAlertSeverityOrder(alert) {
|
|
3006
|
-
// The more severe, the lower the sort number.
|
|
3007
|
-
const {
|
|
3008
|
-
severity
|
|
3009
|
-
} = alert.raw;
|
|
3010
|
-
return severity === ALERT_SEVERITY.critical ? 0 : severity === ALERT_SEVERITY.high ? 1 : severity === ALERT_SEVERITY.middle ? 2 : severity === ALERT_SEVERITY.low ? 3 : 4;
|
|
3011
2979
|
}
|
|
3012
|
-
function
|
|
3013
|
-
|
|
2980
|
+
async function captureException(exception, hint) {
|
|
2981
|
+
const result = captureExceptionSync(exception, hint);
|
|
2982
|
+
// "Sleep" for a second, just in case, hopefully enough time to initiate fetch.
|
|
2983
|
+
await promises.setTimeout(1000);
|
|
2984
|
+
return result;
|
|
3014
2985
|
}
|
|
3015
|
-
function
|
|
3016
|
-
const
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
for (const {
|
|
3020
|
-
0: purl,
|
|
3021
|
-
1: sockPkgAlerts
|
|
3022
|
-
} of alertsMap) {
|
|
3023
|
-
const purlObj = getPurlObject(purl);
|
|
3024
|
-
const partialPurl = new vendor.packageurlJsExports.PackageURL(purlObj.type, purlObj.namespace, purlObj.name).toString();
|
|
3025
|
-
const name = packages.resolvePackageName(purlObj);
|
|
3026
|
-
sockPkgAlertsLoop: for (const sockPkgAlert of sockPkgAlerts) {
|
|
3027
|
-
const alert = sockPkgAlert.raw;
|
|
3028
|
-
if (alert.fix?.type !== ALERT_FIX_TYPE.cve || filterConfig.upgradable === false && registry.getManifestData(sockPkgAlert.ecosystem, name)) {
|
|
3029
|
-
continue sockPkgAlertsLoop;
|
|
3030
|
-
}
|
|
3031
|
-
if (!infoByPartialPurl) {
|
|
3032
|
-
infoByPartialPurl = new Map();
|
|
3033
|
-
}
|
|
3034
|
-
let infos = infoByPartialPurl.get(partialPurl);
|
|
3035
|
-
if (!infos) {
|
|
3036
|
-
infos = new Map();
|
|
3037
|
-
infoByPartialPurl.set(partialPurl, infos);
|
|
3038
|
-
}
|
|
3039
|
-
const {
|
|
3040
|
-
key
|
|
3041
|
-
} = alert;
|
|
3042
|
-
if (!infos.has(key)) {
|
|
3043
|
-
// An alert with alert.fix.type of 'cve' should have a
|
|
3044
|
-
// alert.props.firstPatchedVersionIdentifier property value.
|
|
3045
|
-
// We're just being cautious.
|
|
3046
|
-
const firstPatchedVersionIdentifier = alert.props?.firstPatchedVersionIdentifier;
|
|
3047
|
-
const vulnerableVersionRange = alert.props?.vulnerableVersionRange;
|
|
3048
|
-
let error;
|
|
3049
|
-
if (firstPatchedVersionIdentifier && vulnerableVersionRange) {
|
|
3050
|
-
try {
|
|
3051
|
-
infos.set(key, {
|
|
3052
|
-
firstPatchedVersionIdentifier,
|
|
3053
|
-
vulnerableVersionRange: new vendor.semverExports.Range(
|
|
3054
|
-
// Replace ', ' in a range like '>= 1.0.0, < 1.8.2' with ' ' so that
|
|
3055
|
-
// semver.Range will parse it without erroring.
|
|
3056
|
-
vulnerableVersionRange.replace(/, +/g, ' ').replace(/; +/g, ' || ')).format()
|
|
3057
|
-
});
|
|
3058
|
-
continue sockPkgAlertsLoop;
|
|
3059
|
-
} catch (e) {
|
|
3060
|
-
error = e;
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
require$$9.debugFn('error', 'fail: invalid SocketPackageAlert');
|
|
3064
|
-
require$$9.debugDir('inspect', {
|
|
3065
|
-
alert,
|
|
3066
|
-
error
|
|
3067
|
-
});
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
2986
|
+
function captureExceptionSync(exception, hint) {
|
|
2987
|
+
const Sentry = getSentry();
|
|
2988
|
+
if (!Sentry) {
|
|
2989
|
+
return '';
|
|
3070
2990
|
}
|
|
3071
|
-
|
|
2991
|
+
require$$9.debugFn('notice', 'send: exception to Sentry');
|
|
2992
|
+
return Sentry.captureException(exception, hint);
|
|
3072
2993
|
}
|
|
3073
|
-
|
|
3074
|
-
|
|
2994
|
+
|
|
2995
|
+
function npa(...args) {
|
|
2996
|
+
try {
|
|
2997
|
+
return Reflect.apply(vendor.npaExports, undefined, args);
|
|
2998
|
+
} catch {}
|
|
2999
|
+
return null;
|
|
3075
3000
|
}
|
|
3076
|
-
|
|
3001
|
+
|
|
3002
|
+
function shadowNpmInstall(options) {
|
|
3077
3003
|
const {
|
|
3078
|
-
|
|
3079
|
-
|
|
3004
|
+
agentExecPath = getNpmBinPath(),
|
|
3005
|
+
args = [],
|
|
3006
|
+
ipc,
|
|
3007
|
+
spinner,
|
|
3008
|
+
...spawnOpts
|
|
3080
3009
|
} = {
|
|
3081
3010
|
__proto__: null,
|
|
3082
3011
|
...options
|
|
3083
3012
|
};
|
|
3084
|
-
const
|
|
3085
|
-
const
|
|
3086
|
-
const
|
|
3087
|
-
const
|
|
3088
|
-
const
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
0: purl,
|
|
3094
|
-
1: alerts
|
|
3095
|
-
} = sortedEntries[i];
|
|
3096
|
-
const hiddenAlerts = [];
|
|
3097
|
-
const viewableAlerts = alerts.filter(a => {
|
|
3098
|
-
const keep = a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER[hideAt];
|
|
3099
|
-
if (!keep) {
|
|
3100
|
-
hiddenAlerts.push(a);
|
|
3101
|
-
}
|
|
3102
|
-
return keep;
|
|
3103
|
-
});
|
|
3104
|
-
if (hiddenAlerts.length) {
|
|
3105
|
-
hiddenAlertsByPurl.set(purl, hiddenAlerts.sort(alertSeverityComparator));
|
|
3106
|
-
}
|
|
3107
|
-
if (!viewableAlerts.length) {
|
|
3108
|
-
continue;
|
|
3109
|
-
}
|
|
3110
|
-
viewableAlerts.sort(alertSeverityComparator);
|
|
3111
|
-
viewableAlertsByPurl.set(purl, viewableAlerts);
|
|
3112
|
-
if (viewableAlerts.find(a => a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER.middle)) {
|
|
3113
|
-
aboveTheFoldPurls.add(purl);
|
|
3114
|
-
}
|
|
3115
|
-
}
|
|
3116
|
-
|
|
3117
|
-
// If MIN_ABOVE_THE_FOLD_COUNT is NOT met add more from viewable pkg ids.
|
|
3118
|
-
for (const {
|
|
3119
|
-
0: purl
|
|
3120
|
-
} of viewableAlertsByPurl.entries()) {
|
|
3121
|
-
if (aboveTheFoldPurls.size >= MIN_ABOVE_THE_FOLD_COUNT) {
|
|
3122
|
-
break;
|
|
3123
|
-
}
|
|
3124
|
-
aboveTheFoldPurls.add(purl);
|
|
3125
|
-
}
|
|
3126
|
-
// If MIN_ABOVE_THE_FOLD_COUNT is STILL NOT met add more from hidden pkg ids.
|
|
3127
|
-
for (const {
|
|
3128
|
-
0: purl,
|
|
3129
|
-
1: hiddenAlerts
|
|
3130
|
-
} of hiddenAlertsByPurl.entries()) {
|
|
3131
|
-
if (aboveTheFoldPurls.size >= MIN_ABOVE_THE_FOLD_COUNT) {
|
|
3132
|
-
break;
|
|
3133
|
-
}
|
|
3134
|
-
aboveTheFoldPurls.add(purl);
|
|
3135
|
-
const viewableAlerts = viewableAlertsByPurl.get(purl) ?? [];
|
|
3136
|
-
if (viewableAlerts.length < MIN_ABOVE_THE_FOLD_ALERT_COUNT) {
|
|
3137
|
-
const neededCount = MIN_ABOVE_THE_FOLD_ALERT_COUNT - viewableAlerts.length;
|
|
3138
|
-
let removedHiddenAlerts;
|
|
3139
|
-
if (hiddenAlerts.length - neededCount > 0) {
|
|
3140
|
-
removedHiddenAlerts = hiddenAlerts.splice(0, MIN_ABOVE_THE_FOLD_ALERT_COUNT);
|
|
3141
|
-
} else {
|
|
3142
|
-
removedHiddenAlerts = hiddenAlerts;
|
|
3143
|
-
hiddenAlertsByPurl.delete(purl);
|
|
3144
|
-
}
|
|
3145
|
-
viewableAlertsByPurl.set(purl, [...viewableAlerts, ...removedHiddenAlerts]);
|
|
3146
|
-
}
|
|
3147
|
-
}
|
|
3148
|
-
const mentionedPurlsWithHiddenAlerts = new Set();
|
|
3149
|
-
for (let i = 0, prevAboveTheFold = true, entries = Array.from(viewableAlertsByPurl.entries()), {
|
|
3150
|
-
length
|
|
3151
|
-
} = entries; i < length; i += 1) {
|
|
3152
|
-
const {
|
|
3153
|
-
0: purl,
|
|
3154
|
-
1: alerts
|
|
3155
|
-
} = entries[i];
|
|
3156
|
-
const lines = new Set();
|
|
3157
|
-
for (const alert of alerts) {
|
|
3158
|
-
const {
|
|
3159
|
-
type
|
|
3160
|
-
} = alert;
|
|
3161
|
-
const severity = alert.raw.severity ?? '';
|
|
3162
|
-
const attributes = [...(severity ? [vendor.yoctocolorsCjsExports[ALERT_SEVERITY_COLOR[severity]](getSeverityLabel(severity))] : []), ...(alert.blocked ? [vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.red('blocked'))] : []), ...(alert.fixable ? ['fixable'] : [])];
|
|
3163
|
-
const maybeAttributes = attributes.length ? ` ${vendor.yoctocolorsCjsExports.italic(`(${attributes.join('; ')})`)}` : '';
|
|
3164
|
-
// Based data from { pageProps: { alertTypes } } of:
|
|
3165
|
-
// https://socket.dev/_next/data/9a6db8224b68b6da0eb9f7dbb17aff7e51568ac2/en-US.json
|
|
3166
|
-
const info = translations.alerts[type];
|
|
3167
|
-
const title = info?.title ?? type;
|
|
3168
|
-
const maybeDesc = info?.description ? ` - ${info.description}` : '';
|
|
3169
|
-
const content = `${title}${maybeAttributes}${maybeDesc}`;
|
|
3170
|
-
// TODO: An added emoji seems to mis-align terminals sometimes.
|
|
3171
|
-
lines.add(` ${content}`);
|
|
3172
|
-
}
|
|
3173
|
-
const purlObj = getPurlObject(purl);
|
|
3174
|
-
const pkgName = packages.resolvePackageName(purlObj);
|
|
3175
|
-
const hyperlink = format.hyperlink(pkgName, getSocketDevPackageOverviewUrl(purlObj.type, pkgName, purlObj.version));
|
|
3176
|
-
const isAboveTheFold = aboveTheFoldPurls.has(purl);
|
|
3177
|
-
if (isAboveTheFold) {
|
|
3178
|
-
aboveTheFoldPurls.add(purl);
|
|
3179
|
-
output.write(`${i ? '\n' : ''}${hyperlink}:\n`);
|
|
3180
|
-
} else {
|
|
3181
|
-
output.write(`${prevAboveTheFold ? '\n' : ''}${hyperlink}:\n`);
|
|
3182
|
-
}
|
|
3183
|
-
for (const line of lines) {
|
|
3184
|
-
output.write(`${line}\n`);
|
|
3185
|
-
}
|
|
3186
|
-
const hiddenAlerts = hiddenAlertsByPurl.get(purl) ?? [];
|
|
3187
|
-
const {
|
|
3188
|
-
length: hiddenAlertsCount
|
|
3189
|
-
} = hiddenAlerts;
|
|
3190
|
-
if (hiddenAlertsCount) {
|
|
3191
|
-
mentionedPurlsWithHiddenAlerts.add(purl);
|
|
3192
|
-
if (hiddenAlertsCount === 1) {
|
|
3193
|
-
output.write(` ${vendor.yoctocolorsCjsExports.dim(`+1 Hidden ${getSeverityLabel(hiddenAlerts[0].raw.severity ?? 'low')} risk alert`)}\n`);
|
|
3194
|
-
} else {
|
|
3195
|
-
output.write(` ${vendor.yoctocolorsCjsExports.dim(`+${hiddenAlertsCount} Hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(getHiddenRiskCounts(hiddenAlerts)))}`)}\n`);
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
prevAboveTheFold = isAboveTheFold;
|
|
3199
|
-
}
|
|
3200
|
-
const additionalHiddenCount = hiddenAlertsByPurl.size - mentionedPurlsWithHiddenAlerts.size;
|
|
3201
|
-
if (additionalHiddenCount) {
|
|
3202
|
-
const totalRiskCounts = {
|
|
3203
|
-
critical: 0,
|
|
3204
|
-
high: 0,
|
|
3205
|
-
middle: 0,
|
|
3206
|
-
low: 0
|
|
3207
|
-
};
|
|
3208
|
-
for (const {
|
|
3209
|
-
0: purl,
|
|
3210
|
-
1: alerts
|
|
3211
|
-
} of hiddenAlertsByPurl.entries()) {
|
|
3212
|
-
if (mentionedPurlsWithHiddenAlerts.has(purl)) {
|
|
3213
|
-
continue;
|
|
3214
|
-
}
|
|
3215
|
-
const riskCounts = getHiddenRiskCounts(alerts);
|
|
3216
|
-
totalRiskCounts.critical += riskCounts.critical;
|
|
3217
|
-
totalRiskCounts.high += riskCounts.high;
|
|
3218
|
-
totalRiskCounts.middle += riskCounts.middle;
|
|
3219
|
-
totalRiskCounts.low += riskCounts.low;
|
|
3220
|
-
}
|
|
3221
|
-
output.write(`${aboveTheFoldPurls.size ? '\n' : ''}${vendor.yoctocolorsCjsExports.dim(`${aboveTheFoldPurls.size ? '+' : ''}${additionalHiddenCount} Packages with hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`);
|
|
3222
|
-
}
|
|
3223
|
-
output.write('\n');
|
|
3224
|
-
}
|
|
3225
|
-
|
|
3226
|
-
function idToNpmPurl(id) {
|
|
3227
|
-
return `pkg:npm/${id}`;
|
|
3228
|
-
}
|
|
3229
|
-
function idToPurl(id, type) {
|
|
3230
|
-
return `pkg:${type}/${id}`;
|
|
3231
|
-
}
|
|
3232
|
-
|
|
3233
|
-
function extractOverridesFromPnpmLockSrc(lockfileContent) {
|
|
3234
|
-
let match;
|
|
3235
|
-
if (typeof lockfileContent === 'string') {
|
|
3236
|
-
match = /^overrides:(?:\r?\n {2}.+)+(?:\r?\n)*/m.exec(lockfileContent)?.[0];
|
|
3237
|
-
}
|
|
3238
|
-
return match ?? '';
|
|
3239
|
-
}
|
|
3240
|
-
async function extractPurlsFromPnpmLockfile(lockfile) {
|
|
3241
|
-
const packages = lockfile?.packages ?? {};
|
|
3242
|
-
const seen = new Set();
|
|
3243
|
-
const visit = pkgPath => {
|
|
3244
|
-
if (seen.has(pkgPath)) {
|
|
3245
|
-
return;
|
|
3246
|
-
}
|
|
3247
|
-
const pkg = packages[pkgPath];
|
|
3248
|
-
if (!pkg) {
|
|
3249
|
-
return;
|
|
3250
|
-
}
|
|
3251
|
-
seen.add(pkgPath);
|
|
3252
|
-
const deps = {
|
|
3253
|
-
__proto__: null,
|
|
3254
|
-
...pkg.dependencies,
|
|
3255
|
-
...pkg.optionalDependencies,
|
|
3256
|
-
...pkg.devDependencies
|
|
3257
|
-
};
|
|
3258
|
-
for (const depName in deps) {
|
|
3259
|
-
const ref = deps[depName];
|
|
3260
|
-
const subKey = isPnpmDepPath(ref) ? ref : `/${depName}@${ref}`;
|
|
3261
|
-
visit(subKey);
|
|
3262
|
-
}
|
|
3263
|
-
};
|
|
3264
|
-
for (const pkgPath of Object.keys(packages)) {
|
|
3265
|
-
visit(pkgPath);
|
|
3266
|
-
}
|
|
3267
|
-
return Array.from(seen).map(p => idToNpmPurl(stripPnpmPeerSuffix(stripLeadingPnpmDepPathSlash(p))));
|
|
3268
|
-
}
|
|
3269
|
-
function isPnpmDepPath(maybeDepPath) {
|
|
3270
|
-
return maybeDepPath.length > 0 && maybeDepPath.charCodeAt(0) === 47; /*'/'*/
|
|
3271
|
-
}
|
|
3272
|
-
function parsePnpmLockfile(lockfileContent) {
|
|
3273
|
-
let result;
|
|
3274
|
-
if (typeof lockfileContent === 'string') {
|
|
3275
|
-
try {
|
|
3276
|
-
result = vendor.jsYaml.load(strings.stripBom(lockfileContent));
|
|
3277
|
-
} catch {}
|
|
3278
|
-
}
|
|
3279
|
-
return require$$10.isObjectObject(result) ? result : null;
|
|
3280
|
-
}
|
|
3281
|
-
function parsePnpmLockfileVersion(version) {
|
|
3282
|
-
try {
|
|
3283
|
-
return vendor.semverExports.coerce(version);
|
|
3284
|
-
} catch {}
|
|
3285
|
-
return null;
|
|
3286
|
-
}
|
|
3287
|
-
function stripLeadingPnpmDepPathSlash(depPath) {
|
|
3288
|
-
return isPnpmDepPath(depPath) ? depPath.slice(1) : depPath;
|
|
3289
|
-
}
|
|
3290
|
-
function stripPnpmPeerSuffix(depPath) {
|
|
3291
|
-
const parenIndex = depPath.indexOf('(');
|
|
3292
|
-
const index = parenIndex === -1 ? depPath.indexOf('_') : parenIndex;
|
|
3293
|
-
return index === -1 ? depPath : depPath.slice(0, index);
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
async function getAlertsMapFromPnpmLockfile(lockfile, options) {
|
|
3297
|
-
const purls = await extractPurlsFromPnpmLockfile(lockfile);
|
|
3298
|
-
return await getAlertsMapFromPurls(purls, {
|
|
3299
|
-
overrides: lockfile.overrides,
|
|
3300
|
-
...options
|
|
3301
|
-
});
|
|
3302
|
-
}
|
|
3303
|
-
async function getAlertsMapFromPurls(purls, options) {
|
|
3304
|
-
const uniqPurls = arrays.arrayUnique(purls);
|
|
3305
|
-
require$$9.debugDir('silly', {
|
|
3306
|
-
purls: uniqPurls
|
|
3307
|
-
});
|
|
3308
|
-
let {
|
|
3309
|
-
length: remaining
|
|
3310
|
-
} = uniqPurls;
|
|
3311
|
-
const alertsByPurl = new Map();
|
|
3312
|
-
if (!remaining) {
|
|
3313
|
-
return alertsByPurl;
|
|
3314
|
-
}
|
|
3315
|
-
const opts = {
|
|
3316
|
-
__proto__: null,
|
|
3317
|
-
consolidate: false,
|
|
3318
|
-
nothrow: false,
|
|
3319
|
-
...options,
|
|
3320
|
-
filter: toFilterConfig(require$$10.getOwn(options, 'filter'))
|
|
3321
|
-
};
|
|
3322
|
-
if (opts.onlyFixable) {
|
|
3323
|
-
opts.filter.fixable = true;
|
|
3324
|
-
}
|
|
3325
|
-
const {
|
|
3326
|
-
apiToken = getPublicApiToken(),
|
|
3327
|
-
spinner
|
|
3328
|
-
} = opts;
|
|
3329
|
-
const getText = () => `Looking up data for ${remaining} packages`;
|
|
3330
|
-
spinner?.start(getText());
|
|
3331
|
-
const sockSdkCResult = await setupSdk({
|
|
3332
|
-
apiToken
|
|
3333
|
-
});
|
|
3334
|
-
if (!sockSdkCResult.ok) {
|
|
3335
|
-
spinner?.stop();
|
|
3336
|
-
throw new Error('Auth error: Run `socket login` first');
|
|
3337
|
-
}
|
|
3338
|
-
const sockSdk = sockSdkCResult.data;
|
|
3339
|
-
const socketYml = findSocketYmlSync()?.parsed;
|
|
3340
|
-
const alertsMapOptions = {
|
|
3341
|
-
overrides: opts.overrides,
|
|
3342
|
-
consolidate: opts.consolidate,
|
|
3343
|
-
filter: opts.filter,
|
|
3344
|
-
socketYml,
|
|
3345
|
-
spinner
|
|
3346
|
-
};
|
|
3347
|
-
for await (const batchResult of sockSdk.batchPackageStream({
|
|
3348
|
-
components: uniqPurls.map(purl => ({
|
|
3349
|
-
purl
|
|
3350
|
-
}))
|
|
3351
|
-
}, {
|
|
3352
|
-
queryParams: {
|
|
3353
|
-
alerts: 'true',
|
|
3354
|
-
compact: 'true',
|
|
3355
|
-
...(opts.onlyFixable ? {
|
|
3356
|
-
fixable: 'true '
|
|
3357
|
-
} : {}),
|
|
3358
|
-
...(Array.isArray(opts.filter.actions) ? {
|
|
3359
|
-
actions: opts.filter.actions.join(',')
|
|
3360
|
-
} : {})
|
|
3361
|
-
}
|
|
3362
|
-
})) {
|
|
3363
|
-
if (batchResult.success) {
|
|
3364
|
-
const artifact = batchResult.data;
|
|
3365
|
-
await addArtifactToAlertsMap(artifact, alertsByPurl, alertsMapOptions);
|
|
3366
|
-
} else if (!opts.nothrow) {
|
|
3367
|
-
spinner?.stop();
|
|
3368
|
-
if (strings.isNonEmptyString(batchResult.error)) {
|
|
3369
|
-
throw new Error(batchResult.error);
|
|
3370
|
-
}
|
|
3371
|
-
const statusCode = batchResult.status ?? 'unknown';
|
|
3372
|
-
throw new Error(`Socket API server error (${statusCode}): No status message`);
|
|
3373
|
-
} else {
|
|
3374
|
-
spinner?.stop();
|
|
3375
|
-
logger.logger.fail(`Received a ${batchResult.status} response from Socket API which we consider a permanent failure:`, batchResult.error, batchResult.cause ? `( ${batchResult.cause} )` : '');
|
|
3376
|
-
require$$9.debugDir('inspect', {
|
|
3377
|
-
batchResult
|
|
3378
|
-
});
|
|
3379
|
-
break;
|
|
3380
|
-
}
|
|
3381
|
-
remaining -= 1;
|
|
3382
|
-
if (remaining > 0) {
|
|
3383
|
-
spinner?.start(getText());
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
spinner?.stop();
|
|
3387
|
-
return alertsByPurl;
|
|
3388
|
-
}
|
|
3389
|
-
|
|
3390
|
-
function npa(...args) {
|
|
3391
|
-
try {
|
|
3392
|
-
return Reflect.apply(vendor.npaExports, undefined, args);
|
|
3393
|
-
} catch {}
|
|
3394
|
-
return null;
|
|
3395
|
-
}
|
|
3396
|
-
|
|
3397
|
-
async function removeNodeModules(cwd = process.cwd()) {
|
|
3398
|
-
const stream = await globStreamNodeModules(cwd);
|
|
3399
|
-
await streams.parallelEach(stream, p => fs.remove(p, {
|
|
3400
|
-
force: true,
|
|
3401
|
-
recursive: true
|
|
3402
|
-
}), {
|
|
3403
|
-
concurrency: 8
|
|
3404
|
-
});
|
|
3405
|
-
}
|
|
3406
|
-
async function findUp(name, {
|
|
3407
|
-
cwd = process.cwd(),
|
|
3408
|
-
signal = constants.abortSignal
|
|
3409
|
-
}) {
|
|
3410
|
-
let dir = path.resolve(cwd);
|
|
3411
|
-
const {
|
|
3412
|
-
root
|
|
3413
|
-
} = path.parse(dir);
|
|
3414
|
-
const names = [name].flat();
|
|
3415
|
-
while (dir && dir !== root) {
|
|
3416
|
-
for (const name of names) {
|
|
3417
|
-
if (signal?.aborted) {
|
|
3418
|
-
return undefined;
|
|
3419
|
-
}
|
|
3420
|
-
const filePath = path.join(dir, name);
|
|
3421
|
-
try {
|
|
3422
|
-
// eslint-disable-next-line no-await-in-loop
|
|
3423
|
-
const stats = await fs$1.promises.stat(filePath);
|
|
3424
|
-
if (stats.isFile()) {
|
|
3425
|
-
return filePath;
|
|
3426
|
-
}
|
|
3427
|
-
} catch {}
|
|
3428
|
-
}
|
|
3429
|
-
dir = path.dirname(dir);
|
|
3430
|
-
}
|
|
3431
|
-
return undefined;
|
|
3432
|
-
}
|
|
3433
|
-
|
|
3434
|
-
function shadowNpmInstall(options) {
|
|
3435
|
-
const {
|
|
3436
|
-
agentExecPath = getNpmBinPath(),
|
|
3437
|
-
args = [],
|
|
3438
|
-
ipc,
|
|
3439
|
-
spinner,
|
|
3440
|
-
...spawnOpts
|
|
3441
|
-
} = {
|
|
3442
|
-
__proto__: null,
|
|
3443
|
-
...options
|
|
3444
|
-
};
|
|
3445
|
-
const useDebug = require$$9.isDebug('stdio');
|
|
3446
|
-
const terminatorPos = args.indexOf('--');
|
|
3447
|
-
const rawBinArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos);
|
|
3448
|
-
const binArgs = rawBinArgs.filter(a => !npm.isNpmAuditFlag(a) && !npm.isNpmFundFlag(a) && !npm.isNpmProgressFlag(a));
|
|
3449
|
-
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
3450
|
-
const progressArg = rawBinArgs.findLast(npm.isNpmProgressFlag) !== '--no-progress';
|
|
3451
|
-
const isSilent = !useDebug && !binArgs.some(npm.isNpmLoglevelFlag);
|
|
3452
|
-
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
|
|
3453
|
-
const useIpc = require$$10.isObject(ipc);
|
|
3013
|
+
const useDebug = require$$9.isDebug('stdio');
|
|
3014
|
+
const terminatorPos = args.indexOf('--');
|
|
3015
|
+
const rawBinArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos);
|
|
3016
|
+
const binArgs = rawBinArgs.filter(a => !npm.isNpmAuditFlag(a) && !npm.isNpmFundFlag(a) && !npm.isNpmProgressFlag(a));
|
|
3017
|
+
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
3018
|
+
const progressArg = rawBinArgs.findLast(npm.isNpmProgressFlag) !== '--no-progress';
|
|
3019
|
+
const isSilent = !useDebug && !binArgs.some(npm.isNpmLoglevelFlag);
|
|
3020
|
+
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
|
|
3021
|
+
const useIpc = require$$11.isObject(ipc);
|
|
3454
3022
|
|
|
3455
3023
|
// Include 'ipc' in the spawnOpts.stdio when an options.ipc object is provided.
|
|
3456
3024
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
3457
3025
|
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
3458
|
-
let stdio = require$$
|
|
3026
|
+
let stdio = require$$11.getOwn(spawnOpts, 'stdio');
|
|
3459
3027
|
if (typeof stdio === 'string') {
|
|
3460
3028
|
stdio = useIpc ? [stdio, stdio, stdio, 'ipc'] : [stdio, stdio, stdio];
|
|
3461
3029
|
} else if (Array.isArray(stdio)) {
|
|
@@ -3477,7 +3045,7 @@ function shadowNpmInstall(options) {
|
|
|
3477
3045
|
env: {
|
|
3478
3046
|
...process.env,
|
|
3479
3047
|
...constants.processEnv,
|
|
3480
|
-
...require$$
|
|
3048
|
+
...require$$11.getOwn(spawnOpts, 'env')
|
|
3481
3049
|
},
|
|
3482
3050
|
spinner,
|
|
3483
3051
|
stdio
|
|
@@ -3526,59 +3094,11 @@ function runAgentInstall(pkgEnvDetails, options) {
|
|
|
3526
3094
|
...process.env,
|
|
3527
3095
|
...constants.processEnv,
|
|
3528
3096
|
NODE_OPTIONS: cmdFlagsToString([...(skipNodeHardenFlags ? [] : constants.nodeHardenFlags), ...constants.nodeNoWarningsFlags]),
|
|
3529
|
-
...require$$
|
|
3097
|
+
...require$$11.getOwn(spawnOpts, 'env')
|
|
3530
3098
|
}
|
|
3531
3099
|
});
|
|
3532
3100
|
}
|
|
3533
3101
|
|
|
3534
|
-
async function getNpmConfig(options) {
|
|
3535
|
-
const {
|
|
3536
|
-
cwd = process.cwd(),
|
|
3537
|
-
env = process.env,
|
|
3538
|
-
execPath = process.execPath,
|
|
3539
|
-
nodeVersion = process.version,
|
|
3540
|
-
npmCommand = 'install',
|
|
3541
|
-
npmPath = getNpmDirPath(),
|
|
3542
|
-
npmVersion,
|
|
3543
|
-
platform = process.platform
|
|
3544
|
-
} = {
|
|
3545
|
-
__proto__: null,
|
|
3546
|
-
...options
|
|
3547
|
-
};
|
|
3548
|
-
const config = new vendor.libExports$2({
|
|
3549
|
-
argv: [],
|
|
3550
|
-
cwd,
|
|
3551
|
-
definitions: vendor.definitionsExports.definitions,
|
|
3552
|
-
execPath,
|
|
3553
|
-
env: {
|
|
3554
|
-
...env
|
|
3555
|
-
},
|
|
3556
|
-
flatten: vendor.definitionsExports.flatten,
|
|
3557
|
-
npmPath,
|
|
3558
|
-
platform,
|
|
3559
|
-
shorthands: vendor.definitionsExports.shorthands
|
|
3560
|
-
});
|
|
3561
|
-
await config.load();
|
|
3562
|
-
const flatConfig = {
|
|
3563
|
-
__proto__: null,
|
|
3564
|
-
...config.flat
|
|
3565
|
-
};
|
|
3566
|
-
if (nodeVersion) {
|
|
3567
|
-
flatConfig.nodeVersion = nodeVersion;
|
|
3568
|
-
}
|
|
3569
|
-
if (npmCommand) {
|
|
3570
|
-
flatConfig.npmCommand = npmCommand;
|
|
3571
|
-
}
|
|
3572
|
-
if (npmVersion) {
|
|
3573
|
-
flatConfig.npmVersion = npmVersion.toString();
|
|
3574
|
-
}
|
|
3575
|
-
return flatConfig;
|
|
3576
|
-
}
|
|
3577
|
-
|
|
3578
|
-
async function readLockfile(lockfilePath) {
|
|
3579
|
-
return fs$1.existsSync(lockfilePath) ? await fs.readFileUtf8(lockfilePath) : null;
|
|
3580
|
-
}
|
|
3581
|
-
|
|
3582
3102
|
const {
|
|
3583
3103
|
BINARY_LOCK_EXT,
|
|
3584
3104
|
BUN,
|
|
@@ -3908,102 +3428,543 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3908
3428
|
};
|
|
3909
3429
|
}
|
|
3910
3430
|
|
|
3911
|
-
const
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
if (!fs$1.existsSync(completionScriptExportPath)) {
|
|
3916
|
-
return {
|
|
3917
|
-
ok: false,
|
|
3918
|
-
message: 'Tab Completion script not found',
|
|
3919
|
-
cause: `Expected to find completion script at \`${completionScriptExportPath}\` but it was not there`
|
|
3920
|
-
};
|
|
3921
|
-
}
|
|
3922
|
-
return {
|
|
3923
|
-
ok: true,
|
|
3924
|
-
data: `source ${completionScriptExportPath}`
|
|
3925
|
-
};
|
|
3431
|
+
const ALL_ECOSYSTEMS = ['apk', 'bitbucket', 'cargo', 'chrome', 'cocoapods', 'composer', 'conan', 'conda', 'cran', 'deb', 'docker', 'gem', 'generic', 'github', 'golang', 'hackage', 'hex', 'huggingface', 'maven', 'mlflow', 'npm', 'nuget', 'oci', 'pub', 'pypi', 'qpkg', 'rpm', 'swift', 'swid', 'unknown'];
|
|
3432
|
+
new Set(ALL_ECOSYSTEMS);
|
|
3433
|
+
function getEcosystemChoicesForMeow() {
|
|
3434
|
+
return [...ALL_ECOSYSTEMS];
|
|
3926
3435
|
}
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
if (!sourcingCommand.ok) {
|
|
3930
|
-
return sourcingCommand;
|
|
3931
|
-
}
|
|
3436
|
+
|
|
3437
|
+
function isArtifactAlertCve(alert) {
|
|
3932
3438
|
const {
|
|
3933
|
-
|
|
3934
|
-
} =
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
ok: false,
|
|
3938
|
-
message: 'Could not determine config directory',
|
|
3939
|
-
cause: 'Failed to get config path'
|
|
3940
|
-
};
|
|
3941
|
-
}
|
|
3439
|
+
type
|
|
3440
|
+
} = alert;
|
|
3441
|
+
return type === constants.ALERT_TYPE_CVE || type === constants.ALERT_TYPE_MEDIUM_CVE || type === constants.ALERT_TYPE_MILD_CVE || type === constants.ALERT_TYPE_CRITICAL_CVE;
|
|
3442
|
+
}
|
|
3942
3443
|
|
|
3943
|
-
|
|
3944
|
-
|
|
3444
|
+
function createEnum(obj) {
|
|
3445
|
+
return Object.freeze({
|
|
3446
|
+
__proto__: null,
|
|
3447
|
+
...obj
|
|
3448
|
+
});
|
|
3449
|
+
}
|
|
3945
3450
|
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3451
|
+
const ALERT_FIX_TYPE = createEnum({
|
|
3452
|
+
cve: 'cve',
|
|
3453
|
+
remove: 'remove',
|
|
3454
|
+
upgrade: 'upgrade'
|
|
3455
|
+
});
|
|
3456
|
+
|
|
3457
|
+
const ALERT_SEVERITY = createEnum({
|
|
3458
|
+
critical: 'critical',
|
|
3459
|
+
high: 'high',
|
|
3460
|
+
middle: 'middle',
|
|
3461
|
+
low: 'low'
|
|
3462
|
+
});
|
|
3463
|
+
|
|
3464
|
+
class ColorOrMarkdown {
|
|
3465
|
+
constructor(useMarkdown) {
|
|
3466
|
+
this.useMarkdown = !!useMarkdown;
|
|
3467
|
+
}
|
|
3468
|
+
bold(text) {
|
|
3469
|
+
return this.useMarkdown ? `**${text}**` : vendor.yoctocolorsCjsExports.bold(`${text}`);
|
|
3470
|
+
}
|
|
3471
|
+
header(text, level = 1) {
|
|
3472
|
+
return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : vendor.yoctocolorsCjsExports.underline(`\n${level === 1 ? vendor.yoctocolorsCjsExports.bold(text) : text}\n`);
|
|
3473
|
+
}
|
|
3474
|
+
hyperlink(text, url, {
|
|
3475
|
+
fallback = true,
|
|
3476
|
+
fallbackToUrl
|
|
3477
|
+
} = {}) {
|
|
3478
|
+
if (url) {
|
|
3479
|
+
return this.useMarkdown ? `[${text}](${url})` : vendor.terminalLinkExports(text, url, {
|
|
3480
|
+
fallback: fallbackToUrl ? (_text, url) => url : fallback
|
|
3481
|
+
});
|
|
3964
3482
|
}
|
|
3965
|
-
|
|
3483
|
+
return text;
|
|
3484
|
+
}
|
|
3485
|
+
indent(...args) {
|
|
3486
|
+
return vendor.indentStringExports(...args);
|
|
3487
|
+
}
|
|
3488
|
+
italic(text) {
|
|
3489
|
+
return this.useMarkdown ? `_${text}_` : vendor.yoctocolorsCjsExports.italic(`${text}`);
|
|
3490
|
+
}
|
|
3491
|
+
json(value) {
|
|
3492
|
+
return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
|
|
3493
|
+
}
|
|
3494
|
+
list(items) {
|
|
3495
|
+
const indentedContent = items.map(item => this.indent(item).trimStart());
|
|
3496
|
+
return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
|
|
3497
|
+
}
|
|
3966
3498
|
}
|
|
3967
3499
|
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3500
|
+
function toFilterConfig(obj) {
|
|
3501
|
+
const normalized = {
|
|
3502
|
+
__proto__: null
|
|
3503
|
+
};
|
|
3504
|
+
const keys = require$$11.isObject(obj) ? Object.keys(obj) : [];
|
|
3505
|
+
for (const key of keys) {
|
|
3506
|
+
const value = obj[key];
|
|
3507
|
+
if (typeof value === 'boolean' || Array.isArray(value)) {
|
|
3508
|
+
normalized[key] = value;
|
|
3509
|
+
}
|
|
3972
3510
|
}
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3511
|
+
return normalized;
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
const require$1 = Module.createRequire(require('node:url').pathToFileURL(__filename).href);
|
|
3515
|
+
let _translations;
|
|
3516
|
+
function getTranslations() {
|
|
3517
|
+
if (_translations === undefined) {
|
|
3518
|
+
_translations = /*@__PURE__*/require$1(path.join(constants.rootPath, 'translations.json'));
|
|
3979
3519
|
}
|
|
3520
|
+
return _translations;
|
|
3980
3521
|
}
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3522
|
+
|
|
3523
|
+
const ALERT_SEVERITY_COLOR = createEnum({
|
|
3524
|
+
critical: 'magenta',
|
|
3525
|
+
high: 'red',
|
|
3526
|
+
middle: 'yellow',
|
|
3527
|
+
low: 'white'
|
|
3528
|
+
});
|
|
3529
|
+
const ALERT_SEVERITY_ORDER = createEnum({
|
|
3530
|
+
critical: 0,
|
|
3531
|
+
high: 1,
|
|
3532
|
+
middle: 2,
|
|
3533
|
+
low: 3,
|
|
3534
|
+
none: 4
|
|
3535
|
+
});
|
|
3536
|
+
const MIN_ABOVE_THE_FOLD_COUNT = 3;
|
|
3537
|
+
const MIN_ABOVE_THE_FOLD_ALERT_COUNT = 1;
|
|
3538
|
+
const format = new ColorOrMarkdown(false);
|
|
3539
|
+
function getHiddenRiskCounts(hiddenAlerts) {
|
|
3540
|
+
const riskCounts = {
|
|
3541
|
+
critical: 0,
|
|
3542
|
+
high: 0,
|
|
3543
|
+
middle: 0,
|
|
3544
|
+
low: 0
|
|
3545
|
+
};
|
|
3546
|
+
for (const alert of hiddenAlerts) {
|
|
3547
|
+
switch (getAlertSeverityOrder(alert)) {
|
|
3548
|
+
case ALERT_SEVERITY_ORDER.critical:
|
|
3549
|
+
riskCounts.critical += 1;
|
|
3550
|
+
break;
|
|
3551
|
+
case ALERT_SEVERITY_ORDER.high:
|
|
3552
|
+
riskCounts.high += 1;
|
|
3553
|
+
break;
|
|
3554
|
+
case ALERT_SEVERITY_ORDER.middle:
|
|
3555
|
+
riskCounts.middle += 1;
|
|
3556
|
+
break;
|
|
3557
|
+
case ALERT_SEVERITY_ORDER.low:
|
|
3558
|
+
riskCounts.low += 1;
|
|
3559
|
+
break;
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
return riskCounts;
|
|
3986
3563
|
}
|
|
3987
|
-
function
|
|
3988
|
-
const
|
|
3989
|
-
if (
|
|
3990
|
-
|
|
3564
|
+
function getHiddenRisksDescription(riskCounts) {
|
|
3565
|
+
const descriptions = [];
|
|
3566
|
+
if (riskCounts.critical) {
|
|
3567
|
+
descriptions.push(`${riskCounts.critical} ${getSeverityLabel('critical')}`);
|
|
3991
3568
|
}
|
|
3992
|
-
|
|
3993
|
-
|
|
3569
|
+
if (riskCounts.high) {
|
|
3570
|
+
descriptions.push(`${riskCounts.high} ${getSeverityLabel('high')}`);
|
|
3571
|
+
}
|
|
3572
|
+
if (riskCounts.middle) {
|
|
3573
|
+
descriptions.push(`${riskCounts.middle} ${getSeverityLabel('middle')}`);
|
|
3574
|
+
}
|
|
3575
|
+
if (riskCounts.low) {
|
|
3576
|
+
descriptions.push(`${riskCounts.low} ${getSeverityLabel('low')}`);
|
|
3577
|
+
}
|
|
3578
|
+
return `(${descriptions.join('; ')})`;
|
|
3994
3579
|
}
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
3580
|
+
async function addArtifactToAlertsMap(artifact, alertsByPurl, options) {
|
|
3581
|
+
// Make TypeScript happy.
|
|
3582
|
+
if (!artifact.name || !artifact.version || !artifact.alerts?.length) {
|
|
3583
|
+
return alertsByPurl;
|
|
3584
|
+
}
|
|
3585
|
+
const {
|
|
3586
|
+
type: ecosystem,
|
|
3587
|
+
version
|
|
3588
|
+
} = artifact;
|
|
3589
|
+
const {
|
|
3590
|
+
consolidate = false,
|
|
3591
|
+
overrides,
|
|
3592
|
+
socketYml
|
|
3593
|
+
} = {
|
|
3594
|
+
__proto__: null,
|
|
3595
|
+
...options
|
|
3596
|
+
};
|
|
3597
|
+
const name = packages.resolvePackageName(artifact);
|
|
3598
|
+
const filterConfig = toFilterConfig({
|
|
3599
|
+
blocked: true,
|
|
3600
|
+
critical: true,
|
|
3601
|
+
cve: true,
|
|
3602
|
+
...require$$11.getOwn(options, 'filter')
|
|
3603
|
+
});
|
|
3604
|
+
const enabledState = {
|
|
3605
|
+
__proto__: null,
|
|
3606
|
+
...socketYml?.issueRules
|
|
3607
|
+
};
|
|
3608
|
+
let sockPkgAlerts = [];
|
|
3609
|
+
for (const alert of artifact.alerts) {
|
|
3610
|
+
const action = alert.action ?? '';
|
|
3611
|
+
const enabledFlag = enabledState[alert.type];
|
|
3612
|
+
if (action === 'ignore' && enabledFlag !== true || enabledFlag === false) {
|
|
3613
|
+
continue;
|
|
3614
|
+
}
|
|
3615
|
+
const blocked = action === 'error';
|
|
3616
|
+
const critical = alert.severity === ALERT_SEVERITY.critical;
|
|
3617
|
+
const cve = isArtifactAlertCve(alert);
|
|
3618
|
+
const fixType = alert.fix?.type ?? '';
|
|
3619
|
+
const fixableCve = fixType === ALERT_FIX_TYPE.cve;
|
|
3620
|
+
const fixableUpgrade = fixType === ALERT_FIX_TYPE.upgrade;
|
|
3621
|
+
const fixable = fixableCve || fixableUpgrade;
|
|
3622
|
+
const upgradable = fixableUpgrade && !require$$11.hasOwn(overrides, name);
|
|
3623
|
+
if (filterConfig.blocked && blocked || filterConfig.critical && critical || filterConfig.cve && cve || filterConfig.fixable && fixable || filterConfig.upgradable && upgradable) {
|
|
3624
|
+
sockPkgAlerts.push({
|
|
3625
|
+
name,
|
|
3626
|
+
version,
|
|
3627
|
+
key: alert.key,
|
|
3628
|
+
type: alert.type,
|
|
3629
|
+
blocked,
|
|
3630
|
+
critical,
|
|
3631
|
+
ecosystem,
|
|
3632
|
+
fixable,
|
|
3633
|
+
raw: alert,
|
|
3634
|
+
upgradable
|
|
3635
|
+
});
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
if (!sockPkgAlerts.length) {
|
|
3639
|
+
return alertsByPurl;
|
|
3640
|
+
}
|
|
3641
|
+
const purl = `pkg:${ecosystem}/${name}@${version}`;
|
|
3642
|
+
const major = getMajor(version);
|
|
3643
|
+
if (consolidate) {
|
|
3644
|
+
const highestForCve = new Map();
|
|
3645
|
+
const highestForUpgrade = new Map();
|
|
3646
|
+
const unfixableAlerts = [];
|
|
3647
|
+
for (const sockPkgAlert of sockPkgAlerts) {
|
|
3648
|
+
const alert = sockPkgAlert.raw;
|
|
3649
|
+
const fixType = alert.fix?.type ?? '';
|
|
3650
|
+
if (fixType === ALERT_FIX_TYPE.cve) {
|
|
3651
|
+
// An alert with alert.fix.type of 'cve' should have a
|
|
3652
|
+
// alert.props.firstPatchedVersionIdentifier property value.
|
|
3653
|
+
// We're just being cautious.
|
|
3654
|
+
const firstPatchedVersionIdentifier = alert.props?.firstPatchedVersionIdentifier;
|
|
3655
|
+
const patchedMajor = firstPatchedVersionIdentifier ? getMajor(firstPatchedVersionIdentifier) : null;
|
|
3656
|
+
if (typeof patchedMajor === 'number') {
|
|
3657
|
+
// Consolidate to the highest "first patched version" by each major
|
|
3658
|
+
// version number.
|
|
3659
|
+
const highest = highestForCve.get(patchedMajor)?.version ?? '0.0.0';
|
|
3660
|
+
if (vendor.semverExports.gt(firstPatchedVersionIdentifier, highest)) {
|
|
3661
|
+
highestForCve.set(patchedMajor, {
|
|
3662
|
+
alert: sockPkgAlert,
|
|
3663
|
+
version: firstPatchedVersionIdentifier
|
|
3664
|
+
});
|
|
3665
|
+
}
|
|
3666
|
+
} else {
|
|
3667
|
+
unfixableAlerts.push(sockPkgAlert);
|
|
3668
|
+
}
|
|
3669
|
+
} else if (fixType === ALERT_FIX_TYPE.upgrade) {
|
|
3670
|
+
// For Socket Optimize upgrades we assume the highest version available
|
|
3671
|
+
// is compatible. This may change in the future.
|
|
3672
|
+
const highest = highestForUpgrade.get(major)?.version ?? '0.0.0';
|
|
3673
|
+
if (vendor.semverExports.gt(version, highest)) {
|
|
3674
|
+
highestForUpgrade.set(major, {
|
|
3675
|
+
alert: sockPkgAlert,
|
|
3676
|
+
version
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3679
|
+
} else {
|
|
3680
|
+
unfixableAlerts.push(sockPkgAlert);
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
sockPkgAlerts = [
|
|
3684
|
+
// Sort CVE alerts by severity: critical, high, middle, then low.
|
|
3685
|
+
...Array.from(highestForCve.values()).map(d => d.alert).sort(alertSeverityComparator), ...Array.from(highestForUpgrade.values()).map(d => d.alert), ...unfixableAlerts];
|
|
3686
|
+
} else {
|
|
3687
|
+
sockPkgAlerts.sort((a, b) => sorts.naturalCompare(a.type, b.type));
|
|
3688
|
+
}
|
|
3689
|
+
if (sockPkgAlerts.length) {
|
|
3690
|
+
alertsByPurl.set(purl, sockPkgAlerts);
|
|
3691
|
+
}
|
|
3692
|
+
return alertsByPurl;
|
|
3693
|
+
}
|
|
3694
|
+
function alertsHaveBlocked(alerts) {
|
|
3695
|
+
return alerts.find(a => a.blocked) !== undefined;
|
|
3696
|
+
}
|
|
3697
|
+
function alertsHaveSeverity(alerts, severity) {
|
|
3698
|
+
return alerts.find(a => a.raw.severity === severity) !== undefined;
|
|
3699
|
+
}
|
|
3700
|
+
function alertSeverityComparator(a, b) {
|
|
3701
|
+
// Put the most severe first.
|
|
3702
|
+
return getAlertSeverityOrder(a) - getAlertSeverityOrder(b);
|
|
3703
|
+
}
|
|
3704
|
+
function getAlertSeverityOrder(alert) {
|
|
3705
|
+
// The more severe, the lower the sort number.
|
|
3706
|
+
const {
|
|
3707
|
+
severity
|
|
3708
|
+
} = alert.raw;
|
|
3709
|
+
return severity === ALERT_SEVERITY.critical ? 0 : severity === ALERT_SEVERITY.high ? 1 : severity === ALERT_SEVERITY.middle ? 2 : severity === ALERT_SEVERITY.low ? 3 : 4;
|
|
3710
|
+
}
|
|
3711
|
+
function getAlertsSeverityOrder(alerts) {
|
|
3712
|
+
return alertsHaveBlocked(alerts) || alertsHaveSeverity(alerts, ALERT_SEVERITY.critical) ? 0 : alertsHaveSeverity(alerts, ALERT_SEVERITY.high) ? 1 : alertsHaveSeverity(alerts, ALERT_SEVERITY.middle) ? 2 : alertsHaveSeverity(alerts, ALERT_SEVERITY.low) ? 3 : 4;
|
|
3713
|
+
}
|
|
3714
|
+
function getSeverityLabel(severity) {
|
|
3715
|
+
return severity === 'middle' ? 'moderate' : severity;
|
|
3716
|
+
}
|
|
3717
|
+
function logAlertsMap(alertsMap, options) {
|
|
3718
|
+
const {
|
|
3719
|
+
hideAt = 'middle',
|
|
3720
|
+
output = process.stderr
|
|
3721
|
+
} = {
|
|
3722
|
+
__proto__: null,
|
|
3723
|
+
...options
|
|
3724
|
+
};
|
|
3725
|
+
const translations = getTranslations();
|
|
3726
|
+
const sortedEntries = Array.from(alertsMap.entries()).sort((a, b) => getAlertsSeverityOrder(a[1]) - getAlertsSeverityOrder(b[1]));
|
|
3727
|
+
const aboveTheFoldPurls = new Set();
|
|
3728
|
+
const viewableAlertsByPurl = new Map();
|
|
3729
|
+
const hiddenAlertsByPurl = new Map();
|
|
3730
|
+
for (let i = 0, {
|
|
3731
|
+
length
|
|
3732
|
+
} = sortedEntries; i < length; i += 1) {
|
|
3733
|
+
const {
|
|
3734
|
+
0: purl,
|
|
3735
|
+
1: alerts
|
|
3736
|
+
} = sortedEntries[i];
|
|
3737
|
+
const hiddenAlerts = [];
|
|
3738
|
+
const viewableAlerts = alerts.filter(a => {
|
|
3739
|
+
const keep = a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER[hideAt];
|
|
3740
|
+
if (!keep) {
|
|
3741
|
+
hiddenAlerts.push(a);
|
|
3742
|
+
}
|
|
3743
|
+
return keep;
|
|
3744
|
+
});
|
|
3745
|
+
if (hiddenAlerts.length) {
|
|
3746
|
+
hiddenAlertsByPurl.set(purl, hiddenAlerts.sort(alertSeverityComparator));
|
|
3747
|
+
}
|
|
3748
|
+
if (!viewableAlerts.length) {
|
|
3749
|
+
continue;
|
|
3750
|
+
}
|
|
3751
|
+
viewableAlerts.sort(alertSeverityComparator);
|
|
3752
|
+
viewableAlertsByPurl.set(purl, viewableAlerts);
|
|
3753
|
+
if (viewableAlerts.find(a => a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER.middle)) {
|
|
3754
|
+
aboveTheFoldPurls.add(purl);
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3758
|
+
// If MIN_ABOVE_THE_FOLD_COUNT is NOT met add more from viewable pkg ids.
|
|
3759
|
+
for (const {
|
|
3760
|
+
0: purl
|
|
3761
|
+
} of viewableAlertsByPurl.entries()) {
|
|
3762
|
+
if (aboveTheFoldPurls.size >= MIN_ABOVE_THE_FOLD_COUNT) {
|
|
3763
|
+
break;
|
|
3764
|
+
}
|
|
3765
|
+
aboveTheFoldPurls.add(purl);
|
|
3766
|
+
}
|
|
3767
|
+
// If MIN_ABOVE_THE_FOLD_COUNT is STILL NOT met add more from hidden pkg ids.
|
|
3768
|
+
for (const {
|
|
3769
|
+
0: purl,
|
|
3770
|
+
1: hiddenAlerts
|
|
3771
|
+
} of hiddenAlertsByPurl.entries()) {
|
|
3772
|
+
if (aboveTheFoldPurls.size >= MIN_ABOVE_THE_FOLD_COUNT) {
|
|
3773
|
+
break;
|
|
3774
|
+
}
|
|
3775
|
+
aboveTheFoldPurls.add(purl);
|
|
3776
|
+
const viewableAlerts = viewableAlertsByPurl.get(purl) ?? [];
|
|
3777
|
+
if (viewableAlerts.length < MIN_ABOVE_THE_FOLD_ALERT_COUNT) {
|
|
3778
|
+
const neededCount = MIN_ABOVE_THE_FOLD_ALERT_COUNT - viewableAlerts.length;
|
|
3779
|
+
let removedHiddenAlerts;
|
|
3780
|
+
if (hiddenAlerts.length - neededCount > 0) {
|
|
3781
|
+
removedHiddenAlerts = hiddenAlerts.splice(0, MIN_ABOVE_THE_FOLD_ALERT_COUNT);
|
|
3782
|
+
} else {
|
|
3783
|
+
removedHiddenAlerts = hiddenAlerts;
|
|
3784
|
+
hiddenAlertsByPurl.delete(purl);
|
|
3785
|
+
}
|
|
3786
|
+
viewableAlertsByPurl.set(purl, [...viewableAlerts, ...removedHiddenAlerts]);
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
const mentionedPurlsWithHiddenAlerts = new Set();
|
|
3790
|
+
for (let i = 0, prevAboveTheFold = true, entries = Array.from(viewableAlertsByPurl.entries()), {
|
|
3791
|
+
length
|
|
3792
|
+
} = entries; i < length; i += 1) {
|
|
3793
|
+
const {
|
|
3794
|
+
0: purl,
|
|
3795
|
+
1: alerts
|
|
3796
|
+
} = entries[i];
|
|
3797
|
+
const lines = new Set();
|
|
3798
|
+
for (const alert of alerts) {
|
|
3799
|
+
const {
|
|
3800
|
+
type
|
|
3801
|
+
} = alert;
|
|
3802
|
+
const severity = alert.raw.severity ?? '';
|
|
3803
|
+
const attributes = [...(severity ? [vendor.yoctocolorsCjsExports[ALERT_SEVERITY_COLOR[severity]](getSeverityLabel(severity))] : []), ...(alert.blocked ? [vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.red('blocked'))] : []), ...(alert.fixable ? ['fixable'] : [])];
|
|
3804
|
+
const maybeAttributes = attributes.length ? ` ${vendor.yoctocolorsCjsExports.italic(`(${attributes.join('; ')})`)}` : '';
|
|
3805
|
+
// Based data from { pageProps: { alertTypes } } of:
|
|
3806
|
+
// https://socket.dev/_next/data/9a6db8224b68b6da0eb9f7dbb17aff7e51568ac2/en-US.json
|
|
3807
|
+
const info = translations.alerts[type];
|
|
3808
|
+
const title = info?.title ?? type;
|
|
3809
|
+
const maybeDesc = info?.description ? ` - ${info.description}` : '';
|
|
3810
|
+
const content = `${title}${maybeAttributes}${maybeDesc}`;
|
|
3811
|
+
// TODO: An added emoji seems to mis-align terminals sometimes.
|
|
3812
|
+
lines.add(` ${content}`);
|
|
3813
|
+
}
|
|
3814
|
+
const purlObj = getPurlObject(purl);
|
|
3815
|
+
const pkgName = packages.resolvePackageName(purlObj);
|
|
3816
|
+
const hyperlink = format.hyperlink(`${pkgName}@${purlObj.version}`, getSocketDevPackageOverviewUrl(purlObj.type, pkgName, purlObj.version));
|
|
3817
|
+
const isAboveTheFold = aboveTheFoldPurls.has(purl);
|
|
3818
|
+
if (isAboveTheFold) {
|
|
3819
|
+
aboveTheFoldPurls.add(purl);
|
|
3820
|
+
output.write(`${i ? '\n' : ''}${hyperlink}:\n`);
|
|
3821
|
+
} else {
|
|
3822
|
+
output.write(`${prevAboveTheFold ? '\n' : ''}${hyperlink}:\n`);
|
|
3823
|
+
}
|
|
3824
|
+
for (const line of lines) {
|
|
3825
|
+
output.write(`${line}\n`);
|
|
3826
|
+
}
|
|
3827
|
+
const hiddenAlerts = hiddenAlertsByPurl.get(purl) ?? [];
|
|
3828
|
+
const {
|
|
3829
|
+
length: hiddenAlertsCount
|
|
3830
|
+
} = hiddenAlerts;
|
|
3831
|
+
if (hiddenAlertsCount) {
|
|
3832
|
+
mentionedPurlsWithHiddenAlerts.add(purl);
|
|
3833
|
+
if (hiddenAlertsCount === 1) {
|
|
3834
|
+
output.write(` ${vendor.yoctocolorsCjsExports.dim(`+1 Hidden ${getSeverityLabel(hiddenAlerts[0].raw.severity ?? 'low')} risk alert`)}\n`);
|
|
3835
|
+
} else {
|
|
3836
|
+
output.write(` ${vendor.yoctocolorsCjsExports.dim(`+${hiddenAlertsCount} Hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(getHiddenRiskCounts(hiddenAlerts)))}`)}\n`);
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
prevAboveTheFold = isAboveTheFold;
|
|
3840
|
+
}
|
|
3841
|
+
const additionalHiddenCount = hiddenAlertsByPurl.size - mentionedPurlsWithHiddenAlerts.size;
|
|
3842
|
+
if (additionalHiddenCount) {
|
|
3843
|
+
const totalRiskCounts = {
|
|
3844
|
+
critical: 0,
|
|
3845
|
+
high: 0,
|
|
3846
|
+
middle: 0,
|
|
3847
|
+
low: 0
|
|
3848
|
+
};
|
|
3849
|
+
for (const {
|
|
3850
|
+
0: purl,
|
|
3851
|
+
1: alerts
|
|
3852
|
+
} of hiddenAlertsByPurl.entries()) {
|
|
3853
|
+
if (mentionedPurlsWithHiddenAlerts.has(purl)) {
|
|
3854
|
+
continue;
|
|
3855
|
+
}
|
|
3856
|
+
const riskCounts = getHiddenRiskCounts(alerts);
|
|
3857
|
+
totalRiskCounts.critical += riskCounts.critical;
|
|
3858
|
+
totalRiskCounts.high += riskCounts.high;
|
|
3859
|
+
totalRiskCounts.middle += riskCounts.middle;
|
|
3860
|
+
totalRiskCounts.low += riskCounts.low;
|
|
3861
|
+
}
|
|
3862
|
+
output.write(`${aboveTheFoldPurls.size ? '\n' : ''}${vendor.yoctocolorsCjsExports.dim(`${aboveTheFoldPurls.size ? '+' : ''}${additionalHiddenCount} Packages with hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`);
|
|
3863
|
+
}
|
|
3864
|
+
output.write('\n');
|
|
3865
|
+
}
|
|
3866
|
+
|
|
3867
|
+
function idToNpmPurl(id) {
|
|
3868
|
+
return `pkg:npm/${id}`;
|
|
3869
|
+
}
|
|
3870
|
+
|
|
3871
|
+
async function getAlertsMapFromPurls(purls, options) {
|
|
3872
|
+
const uniqPurls = arrays.arrayUnique(purls);
|
|
3873
|
+
require$$9.debugDir('silly', {
|
|
3874
|
+
purls: uniqPurls
|
|
3875
|
+
});
|
|
3876
|
+
let {
|
|
3877
|
+
length: remaining
|
|
3878
|
+
} = uniqPurls;
|
|
3879
|
+
const alertsByPurl = new Map();
|
|
3880
|
+
if (!remaining) {
|
|
3881
|
+
return alertsByPurl;
|
|
3882
|
+
}
|
|
3883
|
+
const opts = {
|
|
3884
|
+
__proto__: null,
|
|
3885
|
+
consolidate: false,
|
|
3886
|
+
nothrow: false,
|
|
3887
|
+
...options,
|
|
3888
|
+
filter: toFilterConfig(require$$11.getOwn(options, 'filter'))
|
|
3889
|
+
};
|
|
3890
|
+
if (opts.onlyFixable) {
|
|
3891
|
+
opts.filter.fixable = true;
|
|
3892
|
+
}
|
|
3893
|
+
const {
|
|
3894
|
+
apiToken = getPublicApiToken(),
|
|
3895
|
+
spinner
|
|
3896
|
+
} = opts;
|
|
3897
|
+
const getText = () => `Looking up data for ${remaining} packages`;
|
|
3898
|
+
spinner?.start(getText());
|
|
3899
|
+
const sockSdkCResult = await setupSdk({
|
|
3900
|
+
apiToken
|
|
3901
|
+
});
|
|
3902
|
+
if (!sockSdkCResult.ok) {
|
|
3903
|
+
spinner?.stop();
|
|
3904
|
+
throw new Error('Auth error: Run `socket login` first');
|
|
3905
|
+
}
|
|
3906
|
+
const sockSdk = sockSdkCResult.data;
|
|
3907
|
+
const socketYml = findSocketYmlSync()?.parsed;
|
|
3908
|
+
const alertsMapOptions = {
|
|
3909
|
+
consolidate: opts.consolidate,
|
|
3910
|
+
filter: opts.filter,
|
|
3911
|
+
overrides: opts.overrides,
|
|
3912
|
+
socketYml,
|
|
3913
|
+
spinner
|
|
3914
|
+
};
|
|
3915
|
+
try {
|
|
3916
|
+
for await (const batchResult of sockSdk.batchPackageStream({
|
|
3917
|
+
components: uniqPurls.map(purl => ({
|
|
3918
|
+
purl
|
|
3919
|
+
}))
|
|
3920
|
+
}, {
|
|
3921
|
+
queryParams: {
|
|
3922
|
+
alerts: 'true',
|
|
3923
|
+
compact: 'true',
|
|
3924
|
+
...(opts.onlyFixable ? {
|
|
3925
|
+
fixable: 'true '
|
|
3926
|
+
} : {}),
|
|
3927
|
+
...(Array.isArray(opts.filter.actions) ? {
|
|
3928
|
+
actions: opts.filter.actions.join(',')
|
|
3929
|
+
} : {})
|
|
3930
|
+
}
|
|
3931
|
+
})) {
|
|
3932
|
+
if (batchResult.success) {
|
|
3933
|
+
const artifact = batchResult.data;
|
|
3934
|
+
await addArtifactToAlertsMap(artifact, alertsByPurl, alertsMapOptions);
|
|
3935
|
+
} else if (!opts.nothrow) {
|
|
3936
|
+
spinner?.stop();
|
|
3937
|
+
if (strings.isNonEmptyString(batchResult.error)) {
|
|
3938
|
+
throw new Error(batchResult.error);
|
|
3939
|
+
}
|
|
3940
|
+
const statusCode = batchResult.status ?? 'unknown';
|
|
3941
|
+
throw new Error(`Socket API server error (${statusCode}): No status message`);
|
|
3942
|
+
} else {
|
|
3943
|
+
spinner?.stop();
|
|
3944
|
+
logger.logger.fail(`Received a ${batchResult.status} response from Socket API which we consider a permanent failure:`, batchResult.error, batchResult.cause ? `( ${batchResult.cause} )` : '');
|
|
3945
|
+
require$$9.debugDir('inspect', {
|
|
3946
|
+
batchResult
|
|
3947
|
+
});
|
|
3948
|
+
break;
|
|
3949
|
+
}
|
|
3950
|
+
remaining -= 1;
|
|
3951
|
+
if (remaining > 0) {
|
|
3952
|
+
spinner?.start(getText());
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
} catch (e) {
|
|
3956
|
+
spinner?.stop();
|
|
3957
|
+
throw e;
|
|
3958
|
+
}
|
|
3959
|
+
spinner?.stop();
|
|
3960
|
+
return alertsByPurl;
|
|
4000
3961
|
}
|
|
4001
3962
|
|
|
4002
3963
|
exports.AuthError = AuthError;
|
|
4003
3964
|
exports.COMPLETION_CMD_PREFIX = COMPLETION_CMD_PREFIX;
|
|
4004
3965
|
exports.InputError = InputError;
|
|
4005
3966
|
exports.RangeStyles = RangeStyles;
|
|
4006
|
-
exports.
|
|
3967
|
+
exports.cacheFetch = cacheFetch;
|
|
4007
3968
|
exports.captureException = captureException;
|
|
4008
3969
|
exports.checkCommandInput = checkCommandInput;
|
|
4009
3970
|
exports.cmdFlagValueToArray = cmdFlagValueToArray;
|
|
@@ -4013,34 +3974,32 @@ exports.createEnum = createEnum;
|
|
|
4013
3974
|
exports.detectAndValidatePackageEnvironment = detectAndValidatePackageEnvironment;
|
|
4014
3975
|
exports.detectDefaultBranch = detectDefaultBranch;
|
|
4015
3976
|
exports.determineOrgSlug = determineOrgSlug;
|
|
4016
|
-
exports.
|
|
3977
|
+
exports.enablePrAutoMerge = enablePrAutoMerge;
|
|
4017
3978
|
exports.extractTier1ReachabilityScanId = extractTier1ReachabilityScanId;
|
|
4018
3979
|
exports.failMsgWithBadge = failMsgWithBadge;
|
|
3980
|
+
exports.fetchGhsaDetails = fetchGhsaDetails;
|
|
4019
3981
|
exports.fetchOrganization = fetchOrganization;
|
|
4020
|
-
exports.
|
|
3982
|
+
exports.findUp = findUp;
|
|
4021
3983
|
exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
|
|
4022
3984
|
exports.getBaseBranch = getBaseBranch;
|
|
4023
3985
|
exports.getBashrcDetails = getBashrcDetails;
|
|
4024
3986
|
exports.getConfigValue = getConfigValue;
|
|
4025
3987
|
exports.getConfigValueOrUndef = getConfigValueOrUndef;
|
|
4026
|
-
exports.getCveInfoFromAlertsMap = getCveInfoFromAlertsMap;
|
|
4027
3988
|
exports.getDefaultOrgSlug = getDefaultOrgSlug;
|
|
4028
3989
|
exports.getEcosystemChoicesForMeow = getEcosystemChoicesForMeow;
|
|
4029
3990
|
exports.getEnterpriseOrgs = getEnterpriseOrgs;
|
|
4030
3991
|
exports.getFlagApiRequirementsOutput = getFlagApiRequirementsOutput;
|
|
4031
3992
|
exports.getFlagListOutput = getFlagListOutput;
|
|
4032
3993
|
exports.getMajor = getMajor;
|
|
4033
|
-
exports.getMinVersion = getMinVersion;
|
|
4034
3994
|
exports.getNpmBinPath = getNpmBinPath;
|
|
4035
|
-
exports.getNpmConfig = getNpmConfig;
|
|
4036
3995
|
exports.getNpmRequire = getNpmRequire;
|
|
4037
3996
|
exports.getNpxBinPath = getNpxBinPath;
|
|
3997
|
+
exports.getOctokit = getOctokit;
|
|
3998
|
+
exports.getOctokitGraphql = getOctokitGraphql;
|
|
4038
3999
|
exports.getOrgSlugs = getOrgSlugs;
|
|
4039
4000
|
exports.getOutputKind = getOutputKind;
|
|
4040
4001
|
exports.getPackageFilesForScan = getPackageFilesForScan;
|
|
4041
|
-
exports.getPkgFullNameFromPurl = getPkgFullNameFromPurl;
|
|
4042
4002
|
exports.getPublicApiToken = getPublicApiToken;
|
|
4043
|
-
exports.getPurlObject = getPurlObject;
|
|
4044
4003
|
exports.getRepoInfo = getRepoInfo;
|
|
4045
4004
|
exports.getRepoName = getRepoName;
|
|
4046
4005
|
exports.getSocketDevPackageOverviewUrlFromPurl = getSocketDevPackageOverviewUrlFromPurl;
|
|
@@ -4062,7 +4021,6 @@ exports.handleApiCallNoSpinner = handleApiCallNoSpinner;
|
|
|
4062
4021
|
exports.hasDefaultApiToken = hasDefaultApiToken;
|
|
4063
4022
|
exports.hasEnterpriseOrgPlan = hasEnterpriseOrgPlan;
|
|
4064
4023
|
exports.idToNpmPurl = idToNpmPurl;
|
|
4065
|
-
exports.idToPurl = idToPurl;
|
|
4066
4024
|
exports.isHelpFlag = isHelpFlag;
|
|
4067
4025
|
exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
|
|
4068
4026
|
exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
|
|
@@ -4079,17 +4037,14 @@ exports.meowOrExit = meowOrExit;
|
|
|
4079
4037
|
exports.meowWithSubcommands = meowWithSubcommands;
|
|
4080
4038
|
exports.msAtHome = msAtHome;
|
|
4081
4039
|
exports.npa = npa;
|
|
4082
|
-
exports.parsePnpmLockfile = parsePnpmLockfile;
|
|
4083
|
-
exports.parsePnpmLockfileVersion = parsePnpmLockfileVersion;
|
|
4084
4040
|
exports.queryApiSafeJson = queryApiSafeJson;
|
|
4085
4041
|
exports.queryApiSafeText = queryApiSafeText;
|
|
4086
|
-
exports.readLockfile = readLockfile;
|
|
4087
4042
|
exports.readOrDefaultSocketJson = readOrDefaultSocketJson;
|
|
4088
4043
|
exports.readSocketJsonSync = readSocketJsonSync;
|
|
4089
|
-
exports.removeNodeModules = removeNodeModules;
|
|
4090
4044
|
exports.runAgentInstall = runAgentInstall;
|
|
4091
4045
|
exports.sendApiRequest = sendApiRequest;
|
|
4092
4046
|
exports.serializeResultJson = serializeResultJson;
|
|
4047
|
+
exports.setGitRemoteGithubRepoUrl = setGitRemoteGithubRepoUrl;
|
|
4093
4048
|
exports.setupSdk = setupSdk;
|
|
4094
4049
|
exports.spawnCoana = spawnCoana;
|
|
4095
4050
|
exports.suggestOrgSlug = suggestOrgSlug;
|
|
@@ -4098,5 +4053,5 @@ exports.toFilterConfig = toFilterConfig;
|
|
|
4098
4053
|
exports.updateConfigValue = updateConfigValue;
|
|
4099
4054
|
exports.walkNestedMap = walkNestedMap;
|
|
4100
4055
|
exports.writeSocketJson = writeSocketJson;
|
|
4101
|
-
//# debugId=
|
|
4056
|
+
//# debugId=c9a337ab-9c3d-4d21-a5a6-ef5d89be0e38
|
|
4102
4057
|
//# sourceMappingURL=utils.js.map
|