@socketsecurity/cli-with-sentry 1.0.68 → 1.0.70

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 CHANGED
@@ -3002,6 +3002,83 @@ const cmdConfig = {
3002
3002
  }
3003
3003
  };
3004
3004
 
3005
+ async function coanaFix(fixConfig) {
3006
+ const {
3007
+ ghsas
3008
+ } = fixConfig;
3009
+ if (!ghsas.length) {
3010
+ return {
3011
+ ok: true,
3012
+ data: {
3013
+ fixed: false
3014
+ }
3015
+ };
3016
+ }
3017
+ const {
3018
+ cwd,
3019
+ orgSlug,
3020
+ spinner
3021
+ } = fixConfig;
3022
+ spinner?.start();
3023
+ const sockSdkCResult = await utils.setupSdk();
3024
+ let lastCResult = sockSdkCResult;
3025
+ const sockSdk = sockSdkCResult.ok ? sockSdkCResult.data : undefined;
3026
+ const supportedFilesCResult = sockSdk ? await fetchSupportedScanFileNames() : undefined;
3027
+ if (supportedFilesCResult) {
3028
+ lastCResult = supportedFilesCResult;
3029
+ }
3030
+ const supportedFiles = supportedFilesCResult?.ok ? supportedFilesCResult.data : undefined;
3031
+ const packagePaths = supportedFiles ? await utils.getPackageFilesForScan(['.'], supportedFiles, {
3032
+ cwd
3033
+ }) : [];
3034
+ const uploadCResult = sockSdk ? await utils.handleApiCall(sockSdk?.uploadManifestFiles(orgSlug, packagePaths), {
3035
+ desc: 'upload manifests'
3036
+ }) : undefined;
3037
+ if (uploadCResult) {
3038
+ lastCResult = uploadCResult;
3039
+ }
3040
+ const tarHash = uploadCResult?.ok ? uploadCResult.data.tarHash : '';
3041
+ if (!tarHash) {
3042
+ spinner?.stop();
3043
+ return lastCResult;
3044
+ }
3045
+ const spawnOptions = {
3046
+ cwd,
3047
+ spinner,
3048
+ env: {
3049
+ SOCKET_ORG_SLUG: orgSlug
3050
+ }
3051
+ };
3052
+ let ids = ghsas;
3053
+ if (ids.length === 1 && ids[0] === 'auto') {
3054
+ debug.debugFn('notice', 'resolve: GitHub security alerts.');
3055
+ const foundIdsCResult = tarHash ? await utils.spawnCoana(['compute-fixes-and-upgrade-purls', cwd, '--manifests-tar-hash', tarHash], spawnOptions) : undefined;
3056
+ if (foundIdsCResult) {
3057
+ lastCResult = foundIdsCResult;
3058
+ }
3059
+ if (foundIdsCResult?.ok) {
3060
+ ids = utils.cmdFlagValueToArray(/(?<=Vulnerabilities found: )[^\n]+/.exec(foundIdsCResult.data)?.[0]);
3061
+ debug.debugDir('inspect', {
3062
+ GitHubSecurityAlerts: ids
3063
+ });
3064
+ }
3065
+ }
3066
+ const fixCResult = ids.length ? await utils.spawnCoana(['compute-fixes-and-upgrade-purls', cwd, '--manifests-tar-hash', tarHash, '--apply-fixes-to', ...ids, ...fixConfig.unknownFlags], spawnOptions) : undefined;
3067
+ if (fixCResult) {
3068
+ lastCResult = fixCResult;
3069
+ }
3070
+ spinner?.stop();
3071
+ debug.debugDir('inspect', {
3072
+ lastCResult
3073
+ });
3074
+ return lastCResult.ok ? {
3075
+ ok: true,
3076
+ data: {
3077
+ fixed: true
3078
+ }
3079
+ } : lastCResult;
3080
+ }
3081
+
3005
3082
  function formatBranchName(name) {
3006
3083
  return name.replace(/[^-a-zA-Z0-9/._-]+/g, '+');
3007
3084
  }
@@ -3761,7 +3838,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3761
3838
  debug.debugFn('notice', `miss: CVEs expected, but not found, for ${name}`);
3762
3839
  continue infoEntriesLoop;
3763
3840
  }
3764
- logger.logger.log(`Processing vulns for ${name}`);
3841
+ logger.logger.log(`Processing '${name}'`);
3765
3842
  logger.logger.indent();
3766
3843
  spinner?.indent();
3767
3844
  if (registry.getManifestData(partialPurlObj.type, name)) {
@@ -3775,10 +3852,13 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3775
3852
  // Skip to next package.
3776
3853
  continue infoEntriesLoop;
3777
3854
  }
3855
+ debug.debugDir('inspect', {
3856
+ infos
3857
+ });
3778
3858
  const availableVersions = Object.keys(packument.versions);
3779
3859
  const prs = getPrsForPurl(fixEnv, infoEntry[0]);
3780
3860
  const warningsForAfter = new Set();
3781
-
3861
+ let changed = false;
3782
3862
  // eslint-disable-next-line no-unused-labels
3783
3863
  for (let j = 0, {
3784
3864
  length: length_j
@@ -4081,6 +4161,8 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4081
4161
  message: 'Update failed',
4082
4162
  cause: `Update failed for ${oldId} in ${workspace}${error ? '; ' + error : ''}`
4083
4163
  };
4164
+ } else {
4165
+ changed = true;
4084
4166
  }
4085
4167
  debug.debugFn('notice', 'increment: count', count + 1);
4086
4168
  if (++count >= limit) {
@@ -4097,6 +4179,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4097
4179
  for (const warningText of warningsForAfter) {
4098
4180
  logger.logger.warn(warningText);
4099
4181
  }
4182
+ if (!changed && !warningsForAfter.size) {
4183
+ logger.logger.info('No vulnerable versions found.');
4184
+ }
4100
4185
  if (!isLastInfoEntry) {
4101
4186
  logger.logger.logNewline();
4102
4187
  }
@@ -4140,7 +4225,33 @@ async function install$1(pkgEnvDetails, options) {
4140
4225
  ...options
4141
4226
  };
4142
4227
  const useDebug = debug.isDebug('stdio');
4143
- const args = ['--ignore-scripts', '--no-audit', '--no-fund', '--no-progress', ...(useDebug ? [] : ['--silent']), ...(extraArgs ?? [])];
4228
+ const args = [
4229
+ // If "true", npm does not run scripts specified in package.json files.
4230
+ // Note that commands explicitly intended to run a particular script, such
4231
+ // as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run` will
4232
+ // still run their intended script if `ignore-scripts` is set, but they will
4233
+ // not run any pre- or post-scripts.
4234
+ // https://docs.npmjs.com/cli/v11/commands/npm-install#ignore-scripts
4235
+ '--ignore-scripts',
4236
+ // When "true" submit audit reports alongside the current npm command to the
4237
+ // default registry and all registries configured for scopes. See the
4238
+ // documentation for `npm audit` for details on what is submitted.
4239
+ // https://docs.npmjs.com/cli/v11/commands/npm-install#audit
4240
+ '--no-audit',
4241
+ // When "true" displays the message at the end of each `npm install` acknowledging
4242
+ // the number of dependencies looking for funding. See `npm fund` for details.
4243
+ // https://docs.npmjs.com/cli/v11/commands/npm-install#fund
4244
+ '--no-fund',
4245
+ // When set to "true", npm will display a progress bar during time intensive
4246
+ // operations, if `process.stderr` is a TTY. Set to "false" to suppress the
4247
+ // progress bar.
4248
+ // https://docs.npmjs.com/cli/v8/using-npm/config#progress
4249
+ '--no-progress',
4250
+ // What level of logs to report. All logs are written to a debug log, with
4251
+ // the path to that file printed if the execution of a command fails. The
4252
+ // default is "notice".
4253
+ // https://docs.npmjs.com/cli/v8/using-npm/config#loglevel
4254
+ ...(useDebug ? [] : ['--silent']), ...(extraArgs ?? [])];
4144
4255
  const quotedCmd = `\`${pkgEnvDetails.agent} install ${args.join(' ')}\``;
4145
4256
  debug.debugFn('stdio', `spawn: ${quotedCmd}`);
4146
4257
  const isSpinning = spinner?.isSpinning;
@@ -4287,6 +4398,9 @@ async function install(pkgEnvDetails, options) {
4287
4398
  ...options
4288
4399
  };
4289
4400
  const args = [
4401
+ // Do not execute any scripts defined in the project package.json and its dependencies.
4402
+ // https://pnpm.io/9.x/cli/install#--ignore-scripts
4403
+ '--ignore-scripts',
4290
4404
  // Enable pnpm updates to pnpm-lock.yaml in CI environments.
4291
4405
  // https://pnpm.io/cli/install#--frozen-lockfile
4292
4406
  '--no-frozen-lockfile',
@@ -4387,7 +4501,7 @@ async function pnpmFix(pkgEnvDetails, fixConfig) {
4387
4501
  let revertOverridesSrc;
4388
4502
  return await agentFix(pkgEnvDetails, actualTree, alertsMap, install, {
4389
4503
  async beforeInstall(editablePkgJson, packument, oldVersion, newVersion, vulnerableVersionRange, options) {
4390
- const isWorkspaceRoot = editablePkgJson.path === pkgEnvDetails.editablePkgJson.filename;
4504
+ const isWorkspaceRoot = editablePkgJson.filename === pkgEnvDetails.editablePkgJson.filename;
4391
4505
  // Get current overrides for revert logic.
4392
4506
  const {
4393
4507
  overrides: oldOverrides
@@ -4476,70 +4590,14 @@ async function handleFix({
4476
4590
  testScript,
4477
4591
  unknownFlags
4478
4592
  }) {
4479
- if (ghsas.length === 1 && ghsas[0] === 'auto') {
4480
- let lastCResult;
4481
- const sockSdkCResult = await utils.setupSdk();
4482
- lastCResult = sockSdkCResult;
4483
- const sockSdk = sockSdkCResult.ok ? sockSdkCResult.data : undefined;
4484
- const supportedFilesCResult = sockSdk ? await fetchSupportedScanFileNames() : undefined;
4485
- if (supportedFilesCResult) {
4486
- lastCResult = supportedFilesCResult;
4487
- }
4488
- const supportedFiles = supportedFilesCResult?.ok ? supportedFilesCResult.data : undefined;
4489
- const packagePaths = supportedFiles ? await utils.getPackageFilesForScan(['.'], supportedFiles, {
4490
- cwd
4491
- }) : [];
4492
- const uploadCResult = sockSdk ? await utils.handleApiCall(sockSdk?.uploadManifestFiles(orgSlug, packagePaths), {
4493
- desc: 'upload manifests'
4494
- }) : undefined;
4495
- if (uploadCResult) {
4496
- lastCResult = uploadCResult;
4497
- }
4498
- const tarHash = uploadCResult?.ok ? uploadCResult.data.tarHash : '';
4499
- const idsOutputCResult = tarHash ? await utils.spawnCoana(['compute-fixes-and-upgrade-purls', cwd, '--manifests-tar-hash', tarHash], {
4500
- cwd,
4501
- spinner,
4502
- env: {
4503
- SOCKET_ORG_SLUG: orgSlug
4504
- }
4505
- }) : undefined;
4506
- if (idsOutputCResult) {
4507
- lastCResult = idsOutputCResult;
4508
- }
4509
- const idsOutput = idsOutputCResult?.ok ? idsOutputCResult.data : '';
4510
- const ids = utils.cmdFlagValueToArray(/(?<=Vulnerabilities found: )[^\n]+/.exec(idsOutput)?.[0]);
4511
- const fixCResult = ids.length ? await utils.spawnCoana(['compute-fixes-and-upgrade-purls', cwd, '--manifests-tar-hash', tarHash, '--apply-fixes-to', ...ids, ...unknownFlags], {
4593
+ if (ghsas.length) {
4594
+ await outputFixResult(await coanaFix({
4512
4595
  cwd,
4596
+ ghsas,
4597
+ orgSlug,
4513
4598
  spinner,
4514
- env: {
4515
- SOCKET_ORG_SLUG: orgSlug
4516
- }
4517
- }) : undefined;
4518
- if (fixCResult) {
4519
- lastCResult = fixCResult;
4520
- }
4521
- // const fixCResult = await spawnCoana(
4522
- // [
4523
- // cwd,
4524
- // '--socket-mode',
4525
- // DOT_SOCKET_DOT_FACTS_JSON,
4526
- // '--manifests-tar-hash',
4527
- // tarHash,
4528
- // ...unknownFlags,
4529
- // ],
4530
- // { cwd, spinner, env: { SOCKET_ORG_SLUG: orgSlug } },
4531
- // )
4532
- debug.debugDir('inspect', {
4533
- lastCResult
4534
- });
4535
- if (!lastCResult.ok) {
4536
- await outputFixResult(lastCResult, outputKind);
4537
- return;
4538
- }
4539
- await outputFixResult({
4540
- ok: true,
4541
- data: ''
4542
- }, outputKind);
4599
+ unknownFlags
4600
+ }), outputKind);
4543
4601
  return;
4544
4602
  }
4545
4603
  const pkgEnvCResult = await utils.detectAndValidatePackageEnvironment(cwd, {
@@ -4584,14 +4642,17 @@ async function handleFix({
4584
4642
  await outputFixResult(await fixer(pkgEnvDetails, {
4585
4643
  autoMerge,
4586
4644
  cwd,
4645
+ ghsas,
4587
4646
  limit,
4588
4647
  minSatisfying,
4648
+ orgSlug,
4589
4649
  prCheck,
4590
4650
  purls,
4591
4651
  rangeStyle,
4592
4652
  spinner,
4593
4653
  test,
4594
- testScript
4654
+ testScript,
4655
+ unknownFlags
4595
4656
  }), outputKind);
4596
4657
  }
4597
4658
 
@@ -4703,16 +4764,29 @@ async function run$H(argv, importMeta, {
4703
4764
  importMeta,
4704
4765
  parentName
4705
4766
  });
4706
- const {
4707
- autopilot,
4708
- json,
4709
- markdown
4710
- } = cli.flags;
4711
- const outputKind = utils.getOutputKind(json, markdown);
4767
+ const outputKind = utils.getOutputKind(cli.flags['json'], cli.flags['markdown']);
4712
4768
  let rangeStyle = cli.flags['rangeStyle'];
4713
4769
  if (!rangeStyle) {
4714
4770
  rangeStyle = 'preserve';
4715
4771
  }
4772
+ const rawPurls = utils.cmdFlagValueToArray(cli.flags['purl']);
4773
+ const purls = [];
4774
+ for (const purl of rawPurls) {
4775
+ let version;
4776
+ try {
4777
+ version = vendor.packageurlJsExports$1.PackageURL.fromString(purl)?.version;
4778
+ } catch {}
4779
+ if (version) {
4780
+ purls.push(purl);
4781
+ } else {
4782
+ logger.logger.warn(`--purl ${purl} is missing a version and will be ignored.`);
4783
+ }
4784
+ }
4785
+ if (rawPurls.length !== purls.length && !purls.length) {
4786
+ process.exitCode = 1;
4787
+ logger.logger.fail('No valid --purl values provided.');
4788
+ return;
4789
+ }
4716
4790
  const wasValidInput = utils.checkCommandInput(outputKind, {
4717
4791
  test: utils.RangeStyles.includes(rangeStyle),
4718
4792
  message: `Expecting range style of ${arrays.joinOr(utils.RangeStyles)}`,
@@ -4726,37 +4800,36 @@ async function run$H(argv, importMeta, {
4726
4800
  logger.logger.log(DRY_RUN_NOT_SAVING);
4727
4801
  return;
4728
4802
  }
4729
-
4730
- // Lazily access constants.spinner.
4731
- const {
4732
- spinner
4733
- } = constants;
4734
- const {
4735
- unknownFlags
4736
- } = cli;
4803
+ const orgSlugCResult = await utils.getDefaultOrgSlug();
4804
+ if (!orgSlugCResult.ok) {
4805
+ process.exitCode = orgSlugCResult.code ?? 1;
4806
+ logger.logger.fail('Unable to resolve a Socket account organization.\nEnsure a Socket API token is specified for the organization using the SOCKET_CLI_API_TOKEN environment variable.');
4807
+ return;
4808
+ }
4809
+ const orgSlug = orgSlugCResult.data;
4737
4810
  let [cwd = '.'] = cli.input;
4738
4811
  // Note: path.resolve vs .join:
4739
4812
  // If given path is absolute then cwd should not affect it.
4740
4813
  cwd = path.resolve(process.cwd(), cwd);
4741
4814
  let autoMerge = Boolean(cli.flags['autoMerge']);
4742
4815
  let test = Boolean(cli.flags['test']);
4743
- if (autopilot) {
4816
+ if (cli.flags['autopilot']) {
4744
4817
  autoMerge = true;
4745
4818
  test = true;
4746
4819
  }
4747
- const orgSlugCResult = await utils.getDefaultOrgSlug();
4748
- if (!orgSlugCResult.ok) {
4749
- process.exitCode = orgSlugCResult.code ?? 1;
4750
- logger.logger.fail('Unable to resolve a Socket account organization.\nEnsure a Socket API token is specified for the organization using the SOCKET_CLI_API_TOKEN environment variable.');
4751
- return;
4752
- }
4753
- const orgSlug = orgSlugCResult.data;
4820
+
4821
+ // Lazily access constants.spinner.
4822
+ const {
4823
+ spinner
4824
+ } = constants;
4825
+ // We patched in this feature with `npx custompatch meow` at
4826
+ // socket-cli/patches/meow#13.2.0.patch.
4827
+ const unknownFlags = cli.unknownFlags ?? [];
4754
4828
  const ghsas = utils.cmdFlagValueToArray(cli.flags['ghsa']);
4755
4829
  const limit = (cli.flags['limit'] ? parseInt(String(cli.flags['limit'] || ''), 10) : Infinity) || Infinity;
4756
4830
  const maxSatisfying = Boolean(cli.flags['maxSatisfying']);
4757
4831
  const minSatisfying = Boolean(cli.flags['minSatisfying']) || !maxSatisfying;
4758
4832
  const prCheck = Boolean(cli.flags['prCheck']);
4759
- const purls = utils.cmdFlagValueToArray(cli.flags['purl']);
4760
4833
  const testScript = String(cli.flags['testScript'] || 'test');
4761
4834
  await handleFix({
4762
4835
  autoMerge,
@@ -14522,5 +14595,5 @@ void (async () => {
14522
14595
  await utils.captureException(e);
14523
14596
  }
14524
14597
  })();
14525
- //# debugId=7d509d3a-cd9a-4499-b6b6-88b32a2ff18
14598
+ //# debugId=c419b9c7-a1f4-4307-8197-19068fed4cd4
14526
14599
  //# sourceMappingURL=cli.js.map