@socketsecurity/cli-with-sentry 1.0.69 → 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
  }
@@ -3775,11 +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
- const vulnVersions = new Set();
3781
3860
  const warningsForAfter = new Set();
3782
-
3861
+ let changed = false;
3783
3862
  // eslint-disable-next-line no-unused-labels
3784
3863
  for (let j = 0, {
3785
3864
  length: length_j
@@ -3852,7 +3931,6 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3852
3931
  });
3853
3932
  const newVersionPackument = newVersion ? packument.versions[newVersion] : undefined;
3854
3933
  if (!(newVersion && newVersionPackument)) {
3855
- vulnVersions.add(oldVersion);
3856
3934
  warningsForAfter.add(`${oldId} not updated: requires >=${firstPatchedVersionIdentifier}`);
3857
3935
  continue infosLoop;
3858
3936
  }
@@ -3920,7 +3998,6 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3920
3998
  hasAnnouncedWorkspace = true;
3921
3999
  workspaceLogCallCount = logger.logger.logCallCount;
3922
4000
  }
3923
- vulnVersions.add(oldVersion);
3924
4001
  const newId = `${name}@${utils.applyRange(refRange, newVersion, rangeStyle)}`;
3925
4002
  spinner?.start();
3926
4003
  spinner?.info(`Installing ${newId} in ${workspace}.`);
@@ -4084,6 +4161,8 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4084
4161
  message: 'Update failed',
4085
4162
  cause: `Update failed for ${oldId} in ${workspace}${error ? '; ' + error : ''}`
4086
4163
  };
4164
+ } else {
4165
+ changed = true;
4087
4166
  }
4088
4167
  debug.debugFn('notice', 'increment: count', count + 1);
4089
4168
  if (++count >= limit) {
@@ -4100,7 +4179,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4100
4179
  for (const warningText of warningsForAfter) {
4101
4180
  logger.logger.warn(warningText);
4102
4181
  }
4103
- if (!warningsForAfter.size && !vulnVersions.size) {
4182
+ if (!changed && !warningsForAfter.size) {
4104
4183
  logger.logger.info('No vulnerable versions found.');
4105
4184
  }
4106
4185
  if (!isLastInfoEntry) {
@@ -4146,7 +4225,33 @@ async function install$1(pkgEnvDetails, options) {
4146
4225
  ...options
4147
4226
  };
4148
4227
  const useDebug = debug.isDebug('stdio');
4149
- 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 ?? [])];
4150
4255
  const quotedCmd = `\`${pkgEnvDetails.agent} install ${args.join(' ')}\``;
4151
4256
  debug.debugFn('stdio', `spawn: ${quotedCmd}`);
4152
4257
  const isSpinning = spinner?.isSpinning;
@@ -4293,6 +4398,9 @@ async function install(pkgEnvDetails, options) {
4293
4398
  ...options
4294
4399
  };
4295
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',
4296
4404
  // Enable pnpm updates to pnpm-lock.yaml in CI environments.
4297
4405
  // https://pnpm.io/cli/install#--frozen-lockfile
4298
4406
  '--no-frozen-lockfile',
@@ -4393,7 +4501,7 @@ async function pnpmFix(pkgEnvDetails, fixConfig) {
4393
4501
  let revertOverridesSrc;
4394
4502
  return await agentFix(pkgEnvDetails, actualTree, alertsMap, install, {
4395
4503
  async beforeInstall(editablePkgJson, packument, oldVersion, newVersion, vulnerableVersionRange, options) {
4396
- const isWorkspaceRoot = editablePkgJson.path === pkgEnvDetails.editablePkgJson.filename;
4504
+ const isWorkspaceRoot = editablePkgJson.filename === pkgEnvDetails.editablePkgJson.filename;
4397
4505
  // Get current overrides for revert logic.
4398
4506
  const {
4399
4507
  overrides: oldOverrides
@@ -4482,70 +4590,14 @@ async function handleFix({
4482
4590
  testScript,
4483
4591
  unknownFlags
4484
4592
  }) {
4485
- if (ghsas.length === 1 && ghsas[0] === 'auto') {
4486
- let lastCResult;
4487
- const sockSdkCResult = await utils.setupSdk();
4488
- lastCResult = sockSdkCResult;
4489
- const sockSdk = sockSdkCResult.ok ? sockSdkCResult.data : undefined;
4490
- const supportedFilesCResult = sockSdk ? await fetchSupportedScanFileNames() : undefined;
4491
- if (supportedFilesCResult) {
4492
- lastCResult = supportedFilesCResult;
4493
- }
4494
- const supportedFiles = supportedFilesCResult?.ok ? supportedFilesCResult.data : undefined;
4495
- const packagePaths = supportedFiles ? await utils.getPackageFilesForScan(['.'], supportedFiles, {
4496
- cwd
4497
- }) : [];
4498
- const uploadCResult = sockSdk ? await utils.handleApiCall(sockSdk?.uploadManifestFiles(orgSlug, packagePaths), {
4499
- desc: 'upload manifests'
4500
- }) : undefined;
4501
- if (uploadCResult) {
4502
- lastCResult = uploadCResult;
4503
- }
4504
- const tarHash = uploadCResult?.ok ? uploadCResult.data.tarHash : '';
4505
- const idsOutputCResult = tarHash ? await utils.spawnCoana(['compute-fixes-and-upgrade-purls', cwd, '--manifests-tar-hash', tarHash], {
4506
- cwd,
4507
- spinner,
4508
- env: {
4509
- SOCKET_ORG_SLUG: orgSlug
4510
- }
4511
- }) : undefined;
4512
- if (idsOutputCResult) {
4513
- lastCResult = idsOutputCResult;
4514
- }
4515
- const idsOutput = idsOutputCResult?.ok ? idsOutputCResult.data : '';
4516
- const ids = utils.cmdFlagValueToArray(/(?<=Vulnerabilities found: )[^\n]+/.exec(idsOutput)?.[0]);
4517
- 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({
4518
4595
  cwd,
4596
+ ghsas,
4597
+ orgSlug,
4519
4598
  spinner,
4520
- env: {
4521
- SOCKET_ORG_SLUG: orgSlug
4522
- }
4523
- }) : undefined;
4524
- if (fixCResult) {
4525
- lastCResult = fixCResult;
4526
- }
4527
- // const fixCResult = await spawnCoana(
4528
- // [
4529
- // cwd,
4530
- // '--socket-mode',
4531
- // DOT_SOCKET_DOT_FACTS_JSON,
4532
- // '--manifests-tar-hash',
4533
- // tarHash,
4534
- // ...unknownFlags,
4535
- // ],
4536
- // { cwd, spinner, env: { SOCKET_ORG_SLUG: orgSlug } },
4537
- // )
4538
- debug.debugDir('inspect', {
4539
- lastCResult
4540
- });
4541
- if (!lastCResult.ok) {
4542
- await outputFixResult(lastCResult, outputKind);
4543
- return;
4544
- }
4545
- await outputFixResult({
4546
- ok: true,
4547
- data: ''
4548
- }, outputKind);
4599
+ unknownFlags
4600
+ }), outputKind);
4549
4601
  return;
4550
4602
  }
4551
4603
  const pkgEnvCResult = await utils.detectAndValidatePackageEnvironment(cwd, {
@@ -4590,14 +4642,17 @@ async function handleFix({
4590
4642
  await outputFixResult(await fixer(pkgEnvDetails, {
4591
4643
  autoMerge,
4592
4644
  cwd,
4645
+ ghsas,
4593
4646
  limit,
4594
4647
  minSatisfying,
4648
+ orgSlug,
4595
4649
  prCheck,
4596
4650
  purls,
4597
4651
  rangeStyle,
4598
4652
  spinner,
4599
4653
  test,
4600
- testScript
4654
+ testScript,
4655
+ unknownFlags
4601
4656
  }), outputKind);
4602
4657
  }
4603
4658
 
@@ -4709,16 +4764,29 @@ async function run$H(argv, importMeta, {
4709
4764
  importMeta,
4710
4765
  parentName
4711
4766
  });
4712
- const {
4713
- autopilot,
4714
- json,
4715
- markdown
4716
- } = cli.flags;
4717
- const outputKind = utils.getOutputKind(json, markdown);
4767
+ const outputKind = utils.getOutputKind(cli.flags['json'], cli.flags['markdown']);
4718
4768
  let rangeStyle = cli.flags['rangeStyle'];
4719
4769
  if (!rangeStyle) {
4720
4770
  rangeStyle = 'preserve';
4721
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
+ }
4722
4790
  const wasValidInput = utils.checkCommandInput(outputKind, {
4723
4791
  test: utils.RangeStyles.includes(rangeStyle),
4724
4792
  message: `Expecting range style of ${arrays.joinOr(utils.RangeStyles)}`,
@@ -4732,49 +4800,31 @@ async function run$H(argv, importMeta, {
4732
4800
  logger.logger.log(DRY_RUN_NOT_SAVING);
4733
4801
  return;
4734
4802
  }
4735
-
4736
- // Lazily access constants.spinner.
4737
- const {
4738
- spinner
4739
- } = constants;
4740
- const {
4741
- unknownFlags
4742
- } = 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;
4743
4810
  let [cwd = '.'] = cli.input;
4744
4811
  // Note: path.resolve vs .join:
4745
4812
  // If given path is absolute then cwd should not affect it.
4746
4813
  cwd = path.resolve(process.cwd(), cwd);
4747
4814
  let autoMerge = Boolean(cli.flags['autoMerge']);
4748
4815
  let test = Boolean(cli.flags['test']);
4749
- if (autopilot) {
4816
+ if (cli.flags['autopilot']) {
4750
4817
  autoMerge = true;
4751
4818
  test = true;
4752
4819
  }
4753
- const orgSlugCResult = await utils.getDefaultOrgSlug();
4754
- if (!orgSlugCResult.ok) {
4755
- process.exitCode = orgSlugCResult.code ?? 1;
4756
- 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.');
4757
- return;
4758
- }
4759
- const orgSlug = orgSlugCResult.data;
4760
- const rawPurls = utils.cmdFlagValueToArray(cli.flags['purl']);
4761
- const purls = [];
4762
- for (const purl of rawPurls) {
4763
- let version;
4764
- try {
4765
- version = vendor.packageurlJsExports$1.PackageURL.fromString(purl)?.version;
4766
- } catch {}
4767
- if (version) {
4768
- purls.push(purl);
4769
- } else {
4770
- logger.logger.warn(`--purl ${purl} is missing a version and will be ignored.`);
4771
- }
4772
- }
4773
- if (rawPurls.length !== purls.length && !purls.length) {
4774
- process.exitCode = 1;
4775
- logger.logger.fail('No valid --purl values provided.');
4776
- return;
4777
- }
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 ?? [];
4778
4828
  const ghsas = utils.cmdFlagValueToArray(cli.flags['ghsa']);
4779
4829
  const limit = (cli.flags['limit'] ? parseInt(String(cli.flags['limit'] || ''), 10) : Infinity) || Infinity;
4780
4830
  const maxSatisfying = Boolean(cli.flags['maxSatisfying']);
@@ -14545,5 +14595,5 @@ void (async () => {
14545
14595
  await utils.captureException(e);
14546
14596
  }
14547
14597
  })();
14548
- //# debugId=515ed3c2-cd4e-41ad-a7f6-57b0b6683173
14598
+ //# debugId=c419b9c7-a1f4-4307-8197-19068fed4cd4
14549
14599
  //# sourceMappingURL=cli.js.map