snyk 1.928.0 → 1.929.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/917.index.js
CHANGED
|
@@ -229,6 +229,175 @@ function shouldFail(vulnerableResults, failOn) {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
|
|
232
|
+
/***/ }),
|
|
233
|
+
|
|
234
|
+
/***/ 79304:
|
|
235
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
239
|
+
exports.getPackageJsonPathsContainingSnykDependency = exports.checkPackageJsonForSnykDependency = exports.packageJsonFileExistsInDirectory = exports.getProtectUpgradeWarningForPaths = void 0;
|
|
240
|
+
const os_1 = __webpack_require__(12087);
|
|
241
|
+
const theme = __webpack_require__(86988);
|
|
242
|
+
const fs = __webpack_require__(35747);
|
|
243
|
+
const path = __webpack_require__(85622);
|
|
244
|
+
const createDebug = __webpack_require__(15158);
|
|
245
|
+
const debug = createDebug('snyk-protect-update-notification');
|
|
246
|
+
function getProtectUpgradeWarningForPaths(packageJsonPaths) {
|
|
247
|
+
try {
|
|
248
|
+
if ((packageJsonPaths === null || packageJsonPaths === void 0 ? void 0 : packageJsonPaths.length) > 0) {
|
|
249
|
+
let message = theme.color.status.warn(`${theme.icon.WARNING} WARNING: It looks like you have the \`snyk\` dependency in the \`package.json\` file(s) at the following path(s):` +
|
|
250
|
+
os_1.EOL);
|
|
251
|
+
packageJsonPaths.forEach((p) => {
|
|
252
|
+
message += theme.color.status.warn(` - ${p}` + os_1.EOL);
|
|
253
|
+
});
|
|
254
|
+
const githubReadmeUrlShort = 'https://snyk.co/ud1cR'; // https://github.com/snyk/snyk/tree/master/packages/snyk-protect#migrating-from-snyk-protect-to-snykprotect
|
|
255
|
+
message += theme.color.status.warn(`For more information and migration instructions, see ${githubReadmeUrlShort}` +
|
|
256
|
+
os_1.EOL);
|
|
257
|
+
return message;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
return '';
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
debug('Error in getProtectUpgradeWarningForPaths()', e);
|
|
265
|
+
return '';
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.getProtectUpgradeWarningForPaths = getProtectUpgradeWarningForPaths;
|
|
269
|
+
function packageJsonFileExistsInDirectory(directoryPath) {
|
|
270
|
+
try {
|
|
271
|
+
const packageJsonPath = path.resolve(directoryPath, 'package.json');
|
|
272
|
+
const fileExists = fs.existsSync(packageJsonPath);
|
|
273
|
+
return fileExists;
|
|
274
|
+
}
|
|
275
|
+
catch (e) {
|
|
276
|
+
debug('Error in packageJsonFileExistsInDirectory()', e);
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.packageJsonFileExistsInDirectory = packageJsonFileExistsInDirectory;
|
|
281
|
+
function checkPackageJsonForSnykDependency(packageJsonPath) {
|
|
282
|
+
try {
|
|
283
|
+
const fileExists = fs.existsSync(packageJsonPath);
|
|
284
|
+
if (fileExists) {
|
|
285
|
+
const packageJson = fs.readFileSync(packageJsonPath, 'utf8');
|
|
286
|
+
const packageJsonObject = JSON.parse(packageJson);
|
|
287
|
+
const snykDependency = packageJsonObject.dependencies['snyk'];
|
|
288
|
+
if (snykDependency) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
catch (e) {
|
|
294
|
+
debug('Error in checkPackageJsonForSnykDependency()', e);
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
exports.checkPackageJsonForSnykDependency = checkPackageJsonForSnykDependency;
|
|
299
|
+
function getPackageJsonPathsContainingSnykDependency(fileOption, paths) {
|
|
300
|
+
const packageJsonPathsWithSnykDepForProtect = [];
|
|
301
|
+
try {
|
|
302
|
+
if (fileOption) {
|
|
303
|
+
if (fileOption.endsWith('package.json') ||
|
|
304
|
+
fileOption.endsWith('package-lock.json')) {
|
|
305
|
+
const directoryWithPackageJson = path.dirname(fileOption);
|
|
306
|
+
if (packageJsonFileExistsInDirectory(directoryWithPackageJson)) {
|
|
307
|
+
const packageJsonPath = path.resolve(directoryWithPackageJson, 'package.json');
|
|
308
|
+
const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(packageJsonPath);
|
|
309
|
+
if (packageJsonContainsSnykDep) {
|
|
310
|
+
packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
paths.forEach((testPath) => {
|
|
317
|
+
if (packageJsonFileExistsInDirectory(testPath)) {
|
|
318
|
+
const packageJsonPath = path.resolve(testPath, 'package.json');
|
|
319
|
+
const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(packageJsonPath);
|
|
320
|
+
if (packageJsonContainsSnykDep) {
|
|
321
|
+
packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
debug('Error in getPackageJsonPathsContainingSnykDependency()', e);
|
|
329
|
+
}
|
|
330
|
+
return packageJsonPathsWithSnykDepForProtect;
|
|
331
|
+
}
|
|
332
|
+
exports.getPackageJsonPathsContainingSnykDependency = getPackageJsonPathsContainingSnykDependency;
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
/***/ }),
|
|
336
|
+
|
|
337
|
+
/***/ 24083:
|
|
338
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
342
|
+
exports.notificationForSpotlightVulns = exports.containsSpotlightVulnIds = void 0;
|
|
343
|
+
const theme = __webpack_require__(86988);
|
|
344
|
+
const createDebug = __webpack_require__(15158);
|
|
345
|
+
const os_1 = __webpack_require__(12087);
|
|
346
|
+
const debug = createDebug('snyk-spotlight-vuln-notification');
|
|
347
|
+
const spotlightVulnIds = ['SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720'];
|
|
348
|
+
function containsSpotlightVulnIds(results) {
|
|
349
|
+
try {
|
|
350
|
+
const spotlightVulnsFound = new Set();
|
|
351
|
+
for (const r of results) {
|
|
352
|
+
if (r.vulnerabilities) {
|
|
353
|
+
for (const v of r.vulnerabilities) {
|
|
354
|
+
if (spotlightVulnIds.includes(v.id)) {
|
|
355
|
+
spotlightVulnsFound.add(v.id);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return [...spotlightVulnsFound];
|
|
361
|
+
}
|
|
362
|
+
catch (err) {
|
|
363
|
+
debug('Error in containsSpotlightVulnIds()', err);
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
exports.containsSpotlightVulnIds = containsSpotlightVulnIds;
|
|
368
|
+
function notificationForSpotlightVulns(foundSpotlightVulnsIds) {
|
|
369
|
+
try {
|
|
370
|
+
if (foundSpotlightVulnsIds.length > 0) {
|
|
371
|
+
let message = '';
|
|
372
|
+
for (const vulnId of spotlightVulnIds) {
|
|
373
|
+
if (vulnId === 'SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720') {
|
|
374
|
+
message += theme.color.severity.critical(`${theme.icon.WARNING} WARNING: Critical severity vulnerabilities were found with Log4j!` +
|
|
375
|
+
os_1.EOL);
|
|
376
|
+
for (const vulnId of foundSpotlightVulnsIds) {
|
|
377
|
+
message += ` - ${vulnId} (See https://snyk.io/vuln/${vulnId})`;
|
|
378
|
+
}
|
|
379
|
+
message += os_1.EOL + os_1.EOL;
|
|
380
|
+
message +=
|
|
381
|
+
theme.color.severity.critical(`We highly recommend fixing this vulnerability. If it cannot be fixed by upgrading, see mitigation information here:`) +
|
|
382
|
+
os_1.EOL +
|
|
383
|
+
' - https://security.snyk.io/vuln/SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720' +
|
|
384
|
+
os_1.EOL +
|
|
385
|
+
' - https://snyk.io/blog/log4shell-remediation-cheat-sheet/' +
|
|
386
|
+
os_1.EOL;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return message;
|
|
390
|
+
}
|
|
391
|
+
return '';
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
debug('Error in notificationForSpotlightVulns()', err);
|
|
395
|
+
return '';
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
exports.notificationForSpotlightVulns = notificationForSpotlightVulns;
|
|
399
|
+
|
|
400
|
+
|
|
232
401
|
/***/ })
|
|
233
402
|
|
|
234
403
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"917.index.js","mappings":";;;;;;;;;;AAAA,yCAA+B;AAC/B,wCAAyB;AACzB,MAAM,SAAS,GAAG,mBAAO,CAAC,KAAkB,CAAC,CAAC;AAC9C,MAAM,MAAM,GAAG,mBAAO,CAAC,KAAe,CAAC,CAAC;AACxC,2CAA0B;AAC1B,4CAAsD;AAEtD,uCAAqC;AAGrC,2CAAyD;AAGzD,gDAGiC;AACjC,yCAAiC;AACjC,+CAA6E;AAC7E,kDAA8E;AAE9E,yDAG0D;AAE1D,yDAA6D;AAC7D,2DAA8D;AAC9D,8DAAmE;AACnE,0DAA6D;AAC7D,uDAAsD;AACtD,oDAA4E;AAC5E,6CAAoD;AAEpD,iEAGkD;AAClD,iEAGkD;AAClD,yCAAmC;AAEnC,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AACjC,MAAM,SAAS,GAAG,6DAA6D,CAAC;AAEhF,oDAAoD;AAErC,KAAK,UAAU,IAAI,CAChC,GAAG,IAAgB;IAEnB,MAAM,EAAE,OAAO,EAAE,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iB,CAAC,CAAC;KACvC;IACD,IAAI,MAAM,KAAK,WAAW,EAAE;QAC1B,OAAO,yBAAU,CAAC,iBAAiB,CAAC,CAAC;KACtC;IACD,2DAA2D;IAC3D,OAAO,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;AACtC,CAAC","sources":["webpack://snyk/./src/cli/commands/test/index.ts"],"sourcesContent":["import * as Debug from 'debug';\nimport { EOL } from 'os';\nconst cloneDeep = require('lodash.clonedeep');\nconst assign = require('lodash.assign');\nimport chalk from 'chalk';\nimport { MissingArgError } from '../../../lib/errors';\n\nimport * as snyk from '../../../lib';\nimport { Options, TestOptions } from '../../../lib/types';\nimport { MethodArgs } from '../../args';\nimport { TestCommandResult } from '../../commands/types';\nimport { LegacyVulnApiResult, TestResult } from '../../../lib/snyk-test/legacy';\n\nimport {\n summariseErrorResults,\n summariseVulnerableResults,\n} from '../../../lib/formatters';\nimport * as utils from './utils';\nimport { getEcosystemForTest, testEcosystem } from '../../../lib/ecosystems';\nimport { hasFixes, hasPatches, hasUpgrades } from '../../../lib/vuln-helpers';\nimport { FailOn } from '../../../lib/snyk-test/common';\nimport {\n createErrorMappedResultsForJsonOutput,\n extractDataToSendFromResults,\n} from '../../../lib/formatters/test/format-test-results';\n\nimport { validateCredentials } from './validate-credentials';\nimport { validateTestOptions } from './validate-test-options';\nimport { setDefaultTestOptions } from './set-default-test-options';\nimport { processCommandArgs } from '../process-command-args';\nimport { formatTestError } from './format-test-error';\nimport { displayResult } from '../../../lib/formatters/test/display-result';\nimport * as analytics from '../../../lib/analytics';\n\nimport {\n getPackageJsonPathsContainingSnykDependency,\n getProtectUpgradeWarningForPaths,\n} from '../../../lib/protect-update-notification';\nimport {\n containsSpotlightVulnIds,\n notificationForSpotlightVulns,\n} from '../../../lib/spotlight-vuln-notification';\nimport iacTestCommand from './iac';\n\nconst debug = Debug('snyk-test');\nconst SEPARATOR = '\\n-------------------------------------------------------\\n';\n\n// TODO: avoid using `as any` whenever it's possible\n\nexport default async function test(\n ...args: MethodArgs\n): Promise<TestCommandResult> {\n const { options: originalOptions, paths } = processCommandArgs(...args);\n\n if (originalOptions.iac) {\n return await iacTestCommand(false, ...args);\n }\n\n const options = setDefaultTestOptions(originalOptions);\n validateTestOptions(options);\n validateCredentials(options);\n\n const packageJsonPathsWithSnykDepForProtect: string[] = getPackageJsonPathsContainingSnykDependency(\n options.file,\n paths,\n );\n\n analytics.add(\n 'upgradable-snyk-protect-paths',\n packageJsonPathsWithSnykDepForProtect.length,\n );\n\n // Handles no image arg provided to the container command until\n // a validation interface is implemented in the docker plugin.\n if (options.docker && paths.length === 0) {\n throw new MissingArgError();\n }\n\n const ecosystem = getEcosystemForTest(options);\n if (ecosystem) {\n try {\n const commandResult = await testEcosystem(ecosystem, paths, options);\n return commandResult;\n } catch (error) {\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }\n }\n\n const resultOptions: Array<Options & TestOptions> = [];\n const results = [] as any[];\n\n // Promise waterfall to test all other paths sequentially\n for (const path of paths) {\n // Create a copy of the options so a specific test can\n // modify them i.e. add `options.file` etc. We'll need\n // these options later.\n const testOpts = cloneDeep(options);\n testOpts.path = path;\n testOpts.projectName = testOpts['project-name'];\n\n let res: (TestResult | TestResult[]) | Error;\n try {\n res = await snyk.test(path, testOpts);\n } catch (error) {\n // not throwing here but instead returning error response\n // for legacy flow reasons.\n res = formatTestError(error);\n }\n\n // Not all test results are arrays in order to be backwards compatible\n // with scripts that use a callback with test. Coerce results/errors to be arrays\n // and add the result options to each to be displayed\n const resArray: any[] = Array.isArray(res) ? res : [res];\n\n for (let i = 0; i < resArray.length; i++) {\n const pathWithOptionalProjectName = utils.getPathWithOptionalProjectName(\n path,\n resArray[i],\n );\n results.push(assign(resArray[i], { path: pathWithOptionalProjectName }));\n // currently testOpts are identical for each test result returned even if it's for multiple projects.\n // we want to return the project names, so will need to be crafty in a way that makes sense.\n if (!testOpts.projectNames) {\n resultOptions.push(testOpts);\n } else {\n resultOptions.push(\n assign(cloneDeep(testOpts), {\n projectName: testOpts.projectNames[i],\n }),\n );\n }\n }\n }\n\n const vulnerableResults = results.filter(\n (res) =>\n (res.vulnerabilities && res.vulnerabilities.length) ||\n (res.result &&\n res.result.cloudConfigResults &&\n res.result.cloudConfigResults.length),\n );\n const errorResults = results.filter((res) => res instanceof Error);\n const notSuccess = errorResults.length > 0;\n const foundVulnerabilities = vulnerableResults.length > 0;\n\n // resultOptions is now an array of 1 or more options used for\n // the tests results is now an array of 1 or more test results\n // values depend on `options.json` value - string or object\n const mappedResults = createErrorMappedResultsForJsonOutput(results);\n\n const {\n stdout: dataToSend,\n stringifiedData,\n stringifiedJsonData,\n stringifiedSarifData,\n } = extractDataToSendFromResults(results, mappedResults, options);\n\n if (options.json || options.sarif) {\n // if all results are ok (.ok == true)\n if (mappedResults.every((res) => res.ok)) {\n return TestCommandResult.createJsonTestCommandResult(\n stringifiedData,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n }\n\n const err = new Error(stringifiedData) as any;\n\n if (foundVulnerabilities) {\n if (options.failOn) {\n const fail = shouldFail(vulnerableResults, options.failOn);\n if (!fail) {\n // return here to prevent failure\n return TestCommandResult.createJsonTestCommandResult(\n stringifiedData,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n }\n }\n err.code = 'VULNS';\n const dataToSendNoVulns = dataToSend;\n delete dataToSendNoVulns.vulnerabilities;\n err.jsonNoVulns = dataToSendNoVulns;\n }\n\n if (notSuccess) {\n // Take the code of the first problem to go through error\n // translation.\n // Note: this is done based on the logic done below\n // for non-json/sarif outputs, where we take the code of\n // the first error.\n err.code = errorResults[0].code;\n }\n err.json = stringifiedData;\n err.jsonStringifiedResults = stringifiedJsonData;\n err.sarifStringifiedResults = stringifiedSarifData;\n throw err;\n }\n\n let response = results\n .map((result, i) => {\n return displayResult(\n results[i] as LegacyVulnApiResult,\n resultOptions[i],\n result.foundProjectCount,\n );\n })\n .join(`\\n${SEPARATOR}`);\n\n if (notSuccess) {\n debug(`Failed to test ${errorResults.length} projects, errors:`);\n errorResults.forEach((err) => {\n const errString = err.stack ? err.stack.toString() : err.toString();\n debug('error: %s', errString);\n });\n }\n\n let summaryMessage = '';\n const errorResultsLength = errorResults.length;\n\n if (results.length > 1) {\n const projects = results.length === 1 ? 'project' : 'projects';\n summaryMessage =\n `\\n\\n\\nTested ${results.length} ${projects}` +\n summariseVulnerableResults(vulnerableResults, options) +\n summariseErrorResults(errorResultsLength) +\n '\\n';\n }\n\n if (notSuccess) {\n response += chalk.bold.red(summaryMessage);\n const error = new Error(response) as any;\n // take the code of the first problem to go through error\n // translation\n // HACK as there can be different errors, and we pass only the\n // first one\n error.code = errorResults[0].code;\n error.userMessage = errorResults[0].userMessage;\n error.strCode = errorResults[0].strCode;\n throw error;\n }\n\n if (foundVulnerabilities) {\n if (options.failOn) {\n const fail = shouldFail(vulnerableResults, options.failOn);\n if (!fail) {\n // return here to prevent throwing failure\n response += chalk.bold.green(summaryMessage);\n response += EOL + EOL;\n response += getProtectUpgradeWarningForPaths(\n packageJsonPathsWithSnykDepForProtect,\n );\n\n return TestCommandResult.createHumanReadableTestCommandResult(\n response,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n }\n }\n\n response += chalk.bold.red(summaryMessage);\n\n response += EOL + EOL;\n const foundSpotlightVulnIds = containsSpotlightVulnIds(results);\n const spotlightVulnsMsg = notificationForSpotlightVulns(\n foundSpotlightVulnIds,\n );\n response += spotlightVulnsMsg;\n\n const error = new Error(response) as any;\n // take the code of the first problem to go through error\n // translation\n // HACK as there can be different errors, and we pass only the\n // first one\n error.code = vulnerableResults[0].code || 'VULNS';\n error.userMessage = vulnerableResults[0].userMessage;\n error.jsonStringifiedResults = stringifiedJsonData;\n error.sarifStringifiedResults = stringifiedSarifData;\n throw error;\n }\n\n response += chalk.bold.green(summaryMessage);\n response += EOL + EOL;\n response += getProtectUpgradeWarningForPaths(\n packageJsonPathsWithSnykDepForProtect,\n );\n\n return TestCommandResult.createHumanReadableTestCommandResult(\n response,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n}\n\nfunction shouldFail(vulnerableResults: any[], failOn: FailOn) {\n // find reasons not to fail\n if (failOn === 'all') {\n return hasFixes(vulnerableResults);\n }\n if (failOn === 'upgradable') {\n return hasUpgrades(vulnerableResults);\n }\n if (failOn === 'patchable') {\n return hasPatches(vulnerableResults);\n }\n // should fail by default when there are vulnerable results\n return vulnerableResults.length > 0;\n}\n"],"names":[],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"917.index.js","mappings":";;;;;;;;;;AAAA,yCAA+B;AAC/B,wCAAyB;AACzB,MAAM,SAAS,GAAG,mBAAO,CAAC,KAAkB,CAAC,CAAC;AAC9C,MAAM,MAAM,GAAG,mBAAO,CAAC,KAAe,CAAC,CAAC;AACxC,2CAA0B;AAC1B,4CAAsD;AAEtD,uCAAqC;AAGrC,2CAAyD;AAGzD,gDAGiC;AACjC,yCAAiC;AACjC,+CAA6E;AAC7E,kDAA8E;AAE9E,yDAG0D;AAE1D,yDAA6D;AAC7D,2DAA8D;AAC9D,8DAAmE;AACnE,0DAA6D;AAC7D,uDAAsD;AACtD,oDAA4E;AAC5E,6CAAoD;AAEpD,iEAGkD;AAClD,iEAGkD;AAClD,yCAAmC;AAEnC,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AACjC,MAAM,SAAS,GAAG,6DAA6D,CAAC;AAEhF,oDAAoD;AAErC,KAAK,UAAU,IAAI,CAChC,GAAG,IAAgB;IAEnB,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,yCAAkB,CAAC,GAAG,IAAI,CAAC,CAAC;IAExE,IAAI,eAAe,CAAC,GAAG,EAAE;QACvB,OAAO,MAAM,aAAc,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;KAC7C;IAED,MAAM,OAAO,GAAG,gDAAqB,CAAC,eAAe,CAAC,CAAC;IACvD,2CAAmB,CAAC,OAAO,CAAC,CAAC;IAC7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,CAAC,EAAE;YACrC,IAAI,OAAO,GAAG,EAAE,CAAC;YACjB,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE;gBACrC,IAAI,MAAM,KAAK,yCAAyC,EAAE;oBACxD,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CACtC,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,oEAAoE;wBACvF,QAAG,CACN,CAAC;oBAEF,KAAK,MAAM,MAAM,IAAI,sBAAsB,EAAE;wBAC3C,OAAO,IAAI,OAAO,MAAM,8BAA8B,MAAM,GAAG,CAAC;qBACjE;oBAED,OAAO,IAAI,QAAG,GAAG,QAAG,CAAC;oBACrB,OAAO;wBACL,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAC3B,qHAAqH,CACtH;4BACD,QAAG;4BACH,2EAA2E;4BAC3E,QAAG;4BACH,6DAA6D;4BAC7D,QAAG,CAAC;iBACP;aACF;YACD,OAAO,OAAO,CAAC;SAChB;QACD,OAAO,EAAE,CAAC;KACX;IAAC,OAAO,GAAG,EAAE;QACZ,KAAK,CAAC,0CAA0C,EAAE,GAAG,CAAC,CAAC;QACvD,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AApCD,sEAoCC","sources":["webpack://snyk/./src/cli/commands/test/index.ts","webpack://snyk/./src/lib/protect-update-notification.ts","webpack://snyk/./src/lib/spotlight-vuln-notification.ts"],"sourcesContent":["import * as Debug from 'debug';\nimport { EOL } from 'os';\nconst cloneDeep = require('lodash.clonedeep');\nconst assign = require('lodash.assign');\nimport chalk from 'chalk';\nimport { MissingArgError } from '../../../lib/errors';\n\nimport * as snyk from '../../../lib';\nimport { Options, TestOptions } from '../../../lib/types';\nimport { MethodArgs } from '../../args';\nimport { TestCommandResult } from '../../commands/types';\nimport { LegacyVulnApiResult, TestResult } from '../../../lib/snyk-test/legacy';\n\nimport {\n summariseErrorResults,\n summariseVulnerableResults,\n} from '../../../lib/formatters';\nimport * as utils from './utils';\nimport { getEcosystemForTest, testEcosystem } from '../../../lib/ecosystems';\nimport { hasFixes, hasPatches, hasUpgrades } from '../../../lib/vuln-helpers';\nimport { FailOn } from '../../../lib/snyk-test/common';\nimport {\n createErrorMappedResultsForJsonOutput,\n extractDataToSendFromResults,\n} from '../../../lib/formatters/test/format-test-results';\n\nimport { validateCredentials } from './validate-credentials';\nimport { validateTestOptions } from './validate-test-options';\nimport { setDefaultTestOptions } from './set-default-test-options';\nimport { processCommandArgs } from '../process-command-args';\nimport { formatTestError } from './format-test-error';\nimport { displayResult } from '../../../lib/formatters/test/display-result';\nimport * as analytics from '../../../lib/analytics';\n\nimport {\n getPackageJsonPathsContainingSnykDependency,\n getProtectUpgradeWarningForPaths,\n} from '../../../lib/protect-update-notification';\nimport {\n containsSpotlightVulnIds,\n notificationForSpotlightVulns,\n} from '../../../lib/spotlight-vuln-notification';\nimport iacTestCommand from './iac';\n\nconst debug = Debug('snyk-test');\nconst SEPARATOR = '\\n-------------------------------------------------------\\n';\n\n// TODO: avoid using `as any` whenever it's possible\n\nexport default async function test(\n ...args: MethodArgs\n): Promise<TestCommandResult> {\n const { options: originalOptions, paths } = processCommandArgs(...args);\n\n if (originalOptions.iac) {\n return await iacTestCommand(false, ...args);\n }\n\n const options = setDefaultTestOptions(originalOptions);\n validateTestOptions(options);\n validateCredentials(options);\n\n const packageJsonPathsWithSnykDepForProtect: string[] = getPackageJsonPathsContainingSnykDependency(\n options.file,\n paths,\n );\n\n analytics.add(\n 'upgradable-snyk-protect-paths',\n packageJsonPathsWithSnykDepForProtect.length,\n );\n\n // Handles no image arg provided to the container command until\n // a validation interface is implemented in the docker plugin.\n if (options.docker && paths.length === 0) {\n throw new MissingArgError();\n }\n\n const ecosystem = getEcosystemForTest(options);\n if (ecosystem) {\n try {\n const commandResult = await testEcosystem(ecosystem, paths, options);\n return commandResult;\n } catch (error) {\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }\n }\n\n const resultOptions: Array<Options & TestOptions> = [];\n const results = [] as any[];\n\n // Promise waterfall to test all other paths sequentially\n for (const path of paths) {\n // Create a copy of the options so a specific test can\n // modify them i.e. add `options.file` etc. We'll need\n // these options later.\n const testOpts = cloneDeep(options);\n testOpts.path = path;\n testOpts.projectName = testOpts['project-name'];\n\n let res: (TestResult | TestResult[]) | Error;\n try {\n res = await snyk.test(path, testOpts);\n } catch (error) {\n // not throwing here but instead returning error response\n // for legacy flow reasons.\n res = formatTestError(error);\n }\n\n // Not all test results are arrays in order to be backwards compatible\n // with scripts that use a callback with test. Coerce results/errors to be arrays\n // and add the result options to each to be displayed\n const resArray: any[] = Array.isArray(res) ? res : [res];\n\n for (let i = 0; i < resArray.length; i++) {\n const pathWithOptionalProjectName = utils.getPathWithOptionalProjectName(\n path,\n resArray[i],\n );\n results.push(assign(resArray[i], { path: pathWithOptionalProjectName }));\n // currently testOpts are identical for each test result returned even if it's for multiple projects.\n // we want to return the project names, so will need to be crafty in a way that makes sense.\n if (!testOpts.projectNames) {\n resultOptions.push(testOpts);\n } else {\n resultOptions.push(\n assign(cloneDeep(testOpts), {\n projectName: testOpts.projectNames[i],\n }),\n );\n }\n }\n }\n\n const vulnerableResults = results.filter(\n (res) =>\n (res.vulnerabilities && res.vulnerabilities.length) ||\n (res.result &&\n res.result.cloudConfigResults &&\n res.result.cloudConfigResults.length),\n );\n const errorResults = results.filter((res) => res instanceof Error);\n const notSuccess = errorResults.length > 0;\n const foundVulnerabilities = vulnerableResults.length > 0;\n\n // resultOptions is now an array of 1 or more options used for\n // the tests results is now an array of 1 or more test results\n // values depend on `options.json` value - string or object\n const mappedResults = createErrorMappedResultsForJsonOutput(results);\n\n const {\n stdout: dataToSend,\n stringifiedData,\n stringifiedJsonData,\n stringifiedSarifData,\n } = extractDataToSendFromResults(results, mappedResults, options);\n\n if (options.json || options.sarif) {\n // if all results are ok (.ok == true)\n if (mappedResults.every((res) => res.ok)) {\n return TestCommandResult.createJsonTestCommandResult(\n stringifiedData,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n }\n\n const err = new Error(stringifiedData) as any;\n\n if (foundVulnerabilities) {\n if (options.failOn) {\n const fail = shouldFail(vulnerableResults, options.failOn);\n if (!fail) {\n // return here to prevent failure\n return TestCommandResult.createJsonTestCommandResult(\n stringifiedData,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n }\n }\n err.code = 'VULNS';\n const dataToSendNoVulns = dataToSend;\n delete dataToSendNoVulns.vulnerabilities;\n err.jsonNoVulns = dataToSendNoVulns;\n }\n\n if (notSuccess) {\n // Take the code of the first problem to go through error\n // translation.\n // Note: this is done based on the logic done below\n // for non-json/sarif outputs, where we take the code of\n // the first error.\n err.code = errorResults[0].code;\n }\n err.json = stringifiedData;\n err.jsonStringifiedResults = stringifiedJsonData;\n err.sarifStringifiedResults = stringifiedSarifData;\n throw err;\n }\n\n let response = results\n .map((result, i) => {\n return displayResult(\n results[i] as LegacyVulnApiResult,\n resultOptions[i],\n result.foundProjectCount,\n );\n })\n .join(`\\n${SEPARATOR}`);\n\n if (notSuccess) {\n debug(`Failed to test ${errorResults.length} projects, errors:`);\n errorResults.forEach((err) => {\n const errString = err.stack ? err.stack.toString() : err.toString();\n debug('error: %s', errString);\n });\n }\n\n let summaryMessage = '';\n const errorResultsLength = errorResults.length;\n\n if (results.length > 1) {\n const projects = results.length === 1 ? 'project' : 'projects';\n summaryMessage =\n `\\n\\n\\nTested ${results.length} ${projects}` +\n summariseVulnerableResults(vulnerableResults, options) +\n summariseErrorResults(errorResultsLength) +\n '\\n';\n }\n\n if (notSuccess) {\n response += chalk.bold.red(summaryMessage);\n const error = new Error(response) as any;\n // take the code of the first problem to go through error\n // translation\n // HACK as there can be different errors, and we pass only the\n // first one\n error.code = errorResults[0].code;\n error.userMessage = errorResults[0].userMessage;\n error.strCode = errorResults[0].strCode;\n throw error;\n }\n\n if (foundVulnerabilities) {\n if (options.failOn) {\n const fail = shouldFail(vulnerableResults, options.failOn);\n if (!fail) {\n // return here to prevent throwing failure\n response += chalk.bold.green(summaryMessage);\n response += EOL + EOL;\n response += getProtectUpgradeWarningForPaths(\n packageJsonPathsWithSnykDepForProtect,\n );\n\n return TestCommandResult.createHumanReadableTestCommandResult(\n response,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n }\n }\n\n response += chalk.bold.red(summaryMessage);\n\n response += EOL + EOL;\n const foundSpotlightVulnIds = containsSpotlightVulnIds(results);\n const spotlightVulnsMsg = notificationForSpotlightVulns(\n foundSpotlightVulnIds,\n );\n response += spotlightVulnsMsg;\n\n const error = new Error(response) as any;\n // take the code of the first problem to go through error\n // translation\n // HACK as there can be different errors, and we pass only the\n // first one\n error.code = vulnerableResults[0].code || 'VULNS';\n error.userMessage = vulnerableResults[0].userMessage;\n error.jsonStringifiedResults = stringifiedJsonData;\n error.sarifStringifiedResults = stringifiedSarifData;\n throw error;\n }\n\n response += chalk.bold.green(summaryMessage);\n response += EOL + EOL;\n response += getProtectUpgradeWarningForPaths(\n packageJsonPathsWithSnykDepForProtect,\n );\n\n return TestCommandResult.createHumanReadableTestCommandResult(\n response,\n stringifiedJsonData,\n stringifiedSarifData,\n );\n}\n\nfunction shouldFail(vulnerableResults: any[], failOn: FailOn) {\n // find reasons not to fail\n if (failOn === 'all') {\n return hasFixes(vulnerableResults);\n }\n if (failOn === 'upgradable') {\n return hasUpgrades(vulnerableResults);\n }\n if (failOn === 'patchable') {\n return hasPatches(vulnerableResults);\n }\n // should fail by default when there are vulnerable results\n return vulnerableResults.length > 0;\n}\n","import { EOL } from 'os';\nimport * as theme from './theme';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as createDebug from 'debug';\n\nconst debug = createDebug('snyk-protect-update-notification');\n\nexport function getProtectUpgradeWarningForPaths(\n packageJsonPaths: string[],\n): string {\n try {\n if (packageJsonPaths?.length > 0) {\n let message = theme.color.status.warn(\n `${theme.icon.WARNING} WARNING: It looks like you have the \\`snyk\\` dependency in the \\`package.json\\` file(s) at the following path(s):` +\n EOL,\n );\n\n packageJsonPaths.forEach((p) => {\n message += theme.color.status.warn(` - ${p}` + EOL);\n });\n\n const githubReadmeUrlShort = 'https://snyk.co/ud1cR'; // https://github.com/snyk/snyk/tree/master/packages/snyk-protect#migrating-from-snyk-protect-to-snykprotect\n\n message += theme.color.status.warn(\n `For more information and migration instructions, see ${githubReadmeUrlShort}` +\n EOL,\n );\n\n return message;\n } else {\n return '';\n }\n } catch (e) {\n debug('Error in getProtectUpgradeWarningForPaths()', e);\n return '';\n }\n}\n\nexport function packageJsonFileExistsInDirectory(\n directoryPath: string,\n): boolean {\n try {\n const packageJsonPath = path.resolve(directoryPath, 'package.json');\n const fileExists = fs.existsSync(packageJsonPath);\n return fileExists;\n } catch (e) {\n debug('Error in packageJsonFileExistsInDirectory()', e);\n return false;\n }\n}\n\nexport function checkPackageJsonForSnykDependency(\n packageJsonPath: string,\n): boolean {\n try {\n const fileExists = fs.existsSync(packageJsonPath);\n if (fileExists) {\n const packageJson = fs.readFileSync(packageJsonPath, 'utf8');\n const packageJsonObject = JSON.parse(packageJson);\n const snykDependency = packageJsonObject.dependencies['snyk'];\n if (snykDependency) {\n return true;\n }\n }\n } catch (e) {\n debug('Error in checkPackageJsonForSnykDependency()', e);\n }\n return false;\n}\n\nexport function getPackageJsonPathsContainingSnykDependency(\n fileOption: string | undefined,\n paths: string[],\n): string[] {\n const packageJsonPathsWithSnykDepForProtect: string[] = [];\n\n try {\n if (fileOption) {\n if (\n fileOption.endsWith('package.json') ||\n fileOption.endsWith('package-lock.json')\n ) {\n const directoryWithPackageJson = path.dirname(fileOption);\n if (packageJsonFileExistsInDirectory(directoryWithPackageJson)) {\n const packageJsonPath = path.resolve(\n directoryWithPackageJson,\n 'package.json',\n );\n const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(\n packageJsonPath,\n );\n if (packageJsonContainsSnykDep) {\n packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);\n }\n }\n }\n } else {\n paths.forEach((testPath) => {\n if (packageJsonFileExistsInDirectory(testPath)) {\n const packageJsonPath = path.resolve(testPath, 'package.json');\n const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(\n packageJsonPath,\n );\n if (packageJsonContainsSnykDep) {\n packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);\n }\n }\n });\n }\n } catch (e) {\n debug('Error in getPackageJsonPathsContainingSnykDependency()', e);\n }\n\n return packageJsonPathsWithSnykDepForProtect;\n}\n","import * as theme from './theme';\nimport * as createDebug from 'debug';\nimport { EOL } from 'os';\n\nconst debug = createDebug('snyk-spotlight-vuln-notification');\n\nconst spotlightVulnIds = ['SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720'];\n\nexport function containsSpotlightVulnIds(results: any[]): string[] {\n try {\n const spotlightVulnsFound = new Set<string>();\n for (const r of results) {\n if (r.vulnerabilities) {\n for (const v of r.vulnerabilities) {\n if (spotlightVulnIds.includes(v.id)) {\n spotlightVulnsFound.add(v.id);\n }\n }\n }\n }\n return [...spotlightVulnsFound];\n } catch (err) {\n debug('Error in containsSpotlightVulnIds()', err);\n return [];\n }\n}\n\ntype VulnerabilityId = string;\n\nexport function notificationForSpotlightVulns(\n foundSpotlightVulnsIds: VulnerabilityId[],\n) {\n try {\n if (foundSpotlightVulnsIds.length > 0) {\n let message = '';\n for (const vulnId of spotlightVulnIds) {\n if (vulnId === 'SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720') {\n message += theme.color.severity.critical(\n `${theme.icon.WARNING} WARNING: Critical severity vulnerabilities were found with Log4j!` +\n EOL,\n );\n\n for (const vulnId of foundSpotlightVulnsIds) {\n message += ` - ${vulnId} (See https://snyk.io/vuln/${vulnId})`;\n }\n\n message += EOL + EOL;\n message +=\n theme.color.severity.critical(\n `We highly recommend fixing this vulnerability. If it cannot be fixed by upgrading, see mitigation information here:`,\n ) +\n EOL +\n ' - https://security.snyk.io/vuln/SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720' +\n EOL +\n ' - https://snyk.io/blog/log4shell-remediation-cheat-sheet/' +\n EOL;\n }\n }\n return message;\n }\n return '';\n } catch (err) {\n debug('Error in notificationForSpotlightVulns()', err);\n return '';\n }\n}\n"],"names":[],"sourceRoot":""}
|
package/dist/cli/935.index.js
CHANGED
|
@@ -53,13 +53,11 @@ const os_1 = __webpack_require__(12087);
|
|
|
53
53
|
const cloneDeep = __webpack_require__(83465);
|
|
54
54
|
const assign = __webpack_require__(31730);
|
|
55
55
|
const chalk_1 = __webpack_require__(32589);
|
|
56
|
-
const errors_1 = __webpack_require__(55191);
|
|
57
56
|
const types_1 = __webpack_require__(55246);
|
|
58
57
|
const iac_test_result_1 = __webpack_require__(46816);
|
|
59
58
|
const formatters_1 = __webpack_require__(81329);
|
|
60
59
|
const utils = __webpack_require__(77978);
|
|
61
60
|
const iac_output_1 = __webpack_require__(68145);
|
|
62
|
-
const ecosystems_1 = __webpack_require__(5168);
|
|
63
61
|
const format_test_results_1 = __webpack_require__(59744);
|
|
64
62
|
const local_execution_1 = __webpack_require__(89627);
|
|
65
63
|
const validate_credentials_1 = __webpack_require__(4593);
|
|
@@ -68,9 +66,6 @@ const set_default_test_options_1 = __webpack_require__(13285);
|
|
|
68
66
|
const process_command_args_1 = __webpack_require__(52369);
|
|
69
67
|
const format_test_error_1 = __webpack_require__(68214);
|
|
70
68
|
const display_result_1 = __webpack_require__(89667);
|
|
71
|
-
const analytics = __webpack_require__(82744);
|
|
72
|
-
const protect_update_notification_1 = __webpack_require__(79304);
|
|
73
|
-
const spotlight_vuln_notification_1 = __webpack_require__(24083);
|
|
74
69
|
const assert_iac_options_flag_1 = __webpack_require__(33111);
|
|
75
70
|
const assert_iac_options_flag_2 = __webpack_require__(33111);
|
|
76
71
|
const feature_flags_1 = __webpack_require__(63011);
|
|
@@ -91,28 +86,6 @@ async function default_1(isReportCommand, ...args) {
|
|
|
91
86
|
const options = set_default_test_options_1.setDefaultTestOptions(originalOptions);
|
|
92
87
|
validate_test_options_1.validateTestOptions(options);
|
|
93
88
|
validate_credentials_1.validateCredentials(options);
|
|
94
|
-
const packageJsonPathsWithSnykDepForProtect = protect_update_notification_1.getPackageJsonPathsContainingSnykDependency(options.file, paths);
|
|
95
|
-
analytics.add('upgradable-snyk-protect-paths', packageJsonPathsWithSnykDepForProtect.length);
|
|
96
|
-
// Handles no image arg provided to the container command until
|
|
97
|
-
// a validation interface is implemented in the docker plugin.
|
|
98
|
-
if (options.docker && paths.length === 0) {
|
|
99
|
-
throw new errors_1.MissingArgError();
|
|
100
|
-
}
|
|
101
|
-
const ecosystem = ecosystems_1.getEcosystemForTest(options);
|
|
102
|
-
if (ecosystem) {
|
|
103
|
-
try {
|
|
104
|
-
const commandResult = await ecosystems_1.testEcosystem(ecosystem, paths, options);
|
|
105
|
-
return commandResult;
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
if (error instanceof Error) {
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
throw new Error(String(error));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
89
|
let testSpinner;
|
|
117
90
|
const resultOptions = [];
|
|
118
91
|
const results = [];
|
|
@@ -291,9 +264,6 @@ async function default_1(isReportCommand, ...args) {
|
|
|
291
264
|
if (foundVulnerabilities) {
|
|
292
265
|
response += chalk_1.default.bold.red(summaryMessage);
|
|
293
266
|
response += os_1.EOL + os_1.EOL;
|
|
294
|
-
const foundSpotlightVulnIds = spotlight_vuln_notification_1.containsSpotlightVulnIds(results);
|
|
295
|
-
const spotlightVulnsMsg = spotlight_vuln_notification_1.notificationForSpotlightVulns(foundSpotlightVulnIds);
|
|
296
|
-
response += spotlightVulnsMsg;
|
|
297
267
|
if (assert_iac_options_flag_1.isIacShareResultsOptions(options)) {
|
|
298
268
|
response += iac_output_2.formatShareResultsOutput(iacOutputMeta) + os_1.EOL.repeat(2);
|
|
299
269
|
if (isReportCommand) {
|
|
@@ -314,8 +284,6 @@ async function default_1(isReportCommand, ...args) {
|
|
|
314
284
|
throw error;
|
|
315
285
|
}
|
|
316
286
|
response += chalk_1.default.bold.green(summaryMessage);
|
|
317
|
-
response += os_1.EOL + os_1.EOL;
|
|
318
|
-
response += protect_update_notification_1.getProtectUpgradeWarningForPaths(packageJsonPathsWithSnykDepForProtect);
|
|
319
287
|
if (assert_iac_options_flag_1.isIacShareResultsOptions(options)) {
|
|
320
288
|
response += iac_output_2.formatShareResultsOutput(iacOutputMeta) + os_1.EOL.repeat(2);
|
|
321
289
|
if (isReportCommand) {
|
|
@@ -2750,110 +2718,6 @@ function convertIacResultToScanResult(iacResult, policy, gitTarget, options) {
|
|
|
2750
2718
|
exports.convertIacResultToScanResult = convertIacResultToScanResult;
|
|
2751
2719
|
|
|
2752
2720
|
|
|
2753
|
-
/***/ }),
|
|
2754
|
-
|
|
2755
|
-
/***/ 79304:
|
|
2756
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
2757
|
-
|
|
2758
|
-
"use strict";
|
|
2759
|
-
|
|
2760
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2761
|
-
exports.getPackageJsonPathsContainingSnykDependency = exports.checkPackageJsonForSnykDependency = exports.packageJsonFileExistsInDirectory = exports.getProtectUpgradeWarningForPaths = void 0;
|
|
2762
|
-
const os_1 = __webpack_require__(12087);
|
|
2763
|
-
const theme = __webpack_require__(86988);
|
|
2764
|
-
const fs = __webpack_require__(35747);
|
|
2765
|
-
const path = __webpack_require__(85622);
|
|
2766
|
-
const createDebug = __webpack_require__(15158);
|
|
2767
|
-
const debug = createDebug('snyk-protect-update-notification');
|
|
2768
|
-
function getProtectUpgradeWarningForPaths(packageJsonPaths) {
|
|
2769
|
-
try {
|
|
2770
|
-
if ((packageJsonPaths === null || packageJsonPaths === void 0 ? void 0 : packageJsonPaths.length) > 0) {
|
|
2771
|
-
let message = theme.color.status.warn(`${theme.icon.WARNING} WARNING: It looks like you have the \`snyk\` dependency in the \`package.json\` file(s) at the following path(s):` +
|
|
2772
|
-
os_1.EOL);
|
|
2773
|
-
packageJsonPaths.forEach((p) => {
|
|
2774
|
-
message += theme.color.status.warn(` - ${p}` + os_1.EOL);
|
|
2775
|
-
});
|
|
2776
|
-
const githubReadmeUrlShort = 'https://snyk.co/ud1cR'; // https://github.com/snyk/snyk/tree/master/packages/snyk-protect#migrating-from-snyk-protect-to-snykprotect
|
|
2777
|
-
message += theme.color.status.warn(`For more information and migration instructions, see ${githubReadmeUrlShort}` +
|
|
2778
|
-
os_1.EOL);
|
|
2779
|
-
return message;
|
|
2780
|
-
}
|
|
2781
|
-
else {
|
|
2782
|
-
return '';
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
catch (e) {
|
|
2786
|
-
debug('Error in getProtectUpgradeWarningForPaths()', e);
|
|
2787
|
-
return '';
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
exports.getProtectUpgradeWarningForPaths = getProtectUpgradeWarningForPaths;
|
|
2791
|
-
function packageJsonFileExistsInDirectory(directoryPath) {
|
|
2792
|
-
try {
|
|
2793
|
-
const packageJsonPath = path.resolve(directoryPath, 'package.json');
|
|
2794
|
-
const fileExists = fs.existsSync(packageJsonPath);
|
|
2795
|
-
return fileExists;
|
|
2796
|
-
}
|
|
2797
|
-
catch (e) {
|
|
2798
|
-
debug('Error in packageJsonFileExistsInDirectory()', e);
|
|
2799
|
-
return false;
|
|
2800
|
-
}
|
|
2801
|
-
}
|
|
2802
|
-
exports.packageJsonFileExistsInDirectory = packageJsonFileExistsInDirectory;
|
|
2803
|
-
function checkPackageJsonForSnykDependency(packageJsonPath) {
|
|
2804
|
-
try {
|
|
2805
|
-
const fileExists = fs.existsSync(packageJsonPath);
|
|
2806
|
-
if (fileExists) {
|
|
2807
|
-
const packageJson = fs.readFileSync(packageJsonPath, 'utf8');
|
|
2808
|
-
const packageJsonObject = JSON.parse(packageJson);
|
|
2809
|
-
const snykDependency = packageJsonObject.dependencies['snyk'];
|
|
2810
|
-
if (snykDependency) {
|
|
2811
|
-
return true;
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
}
|
|
2815
|
-
catch (e) {
|
|
2816
|
-
debug('Error in checkPackageJsonForSnykDependency()', e);
|
|
2817
|
-
}
|
|
2818
|
-
return false;
|
|
2819
|
-
}
|
|
2820
|
-
exports.checkPackageJsonForSnykDependency = checkPackageJsonForSnykDependency;
|
|
2821
|
-
function getPackageJsonPathsContainingSnykDependency(fileOption, paths) {
|
|
2822
|
-
const packageJsonPathsWithSnykDepForProtect = [];
|
|
2823
|
-
try {
|
|
2824
|
-
if (fileOption) {
|
|
2825
|
-
if (fileOption.endsWith('package.json') ||
|
|
2826
|
-
fileOption.endsWith('package-lock.json')) {
|
|
2827
|
-
const directoryWithPackageJson = path.dirname(fileOption);
|
|
2828
|
-
if (packageJsonFileExistsInDirectory(directoryWithPackageJson)) {
|
|
2829
|
-
const packageJsonPath = path.resolve(directoryWithPackageJson, 'package.json');
|
|
2830
|
-
const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(packageJsonPath);
|
|
2831
|
-
if (packageJsonContainsSnykDep) {
|
|
2832
|
-
packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
}
|
|
2837
|
-
else {
|
|
2838
|
-
paths.forEach((testPath) => {
|
|
2839
|
-
if (packageJsonFileExistsInDirectory(testPath)) {
|
|
2840
|
-
const packageJsonPath = path.resolve(testPath, 'package.json');
|
|
2841
|
-
const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(packageJsonPath);
|
|
2842
|
-
if (packageJsonContainsSnykDep) {
|
|
2843
|
-
packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
});
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
catch (e) {
|
|
2850
|
-
debug('Error in getPackageJsonPathsContainingSnykDependency()', e);
|
|
2851
|
-
}
|
|
2852
|
-
return packageJsonPathsWithSnykDepForProtect;
|
|
2853
|
-
}
|
|
2854
|
-
exports.getPackageJsonPathsContainingSnykDependency = getPackageJsonPathsContainingSnykDependency;
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
2721
|
/***/ }),
|
|
2858
2722
|
|
|
2859
2723
|
/***/ 46816:
|
|
@@ -2892,73 +2756,6 @@ function mapIacIssue(iacIssue) {
|
|
|
2892
2756
|
exports.mapIacIssue = mapIacIssue;
|
|
2893
2757
|
|
|
2894
2758
|
|
|
2895
|
-
/***/ }),
|
|
2896
|
-
|
|
2897
|
-
/***/ 24083:
|
|
2898
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
2899
|
-
|
|
2900
|
-
"use strict";
|
|
2901
|
-
|
|
2902
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2903
|
-
exports.notificationForSpotlightVulns = exports.containsSpotlightVulnIds = void 0;
|
|
2904
|
-
const theme = __webpack_require__(86988);
|
|
2905
|
-
const createDebug = __webpack_require__(15158);
|
|
2906
|
-
const os_1 = __webpack_require__(12087);
|
|
2907
|
-
const debug = createDebug('snyk-spotlight-vuln-notification');
|
|
2908
|
-
const spotlightVulnIds = ['SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720'];
|
|
2909
|
-
function containsSpotlightVulnIds(results) {
|
|
2910
|
-
try {
|
|
2911
|
-
const spotlightVulnsFound = new Set();
|
|
2912
|
-
for (const r of results) {
|
|
2913
|
-
if (r.vulnerabilities) {
|
|
2914
|
-
for (const v of r.vulnerabilities) {
|
|
2915
|
-
if (spotlightVulnIds.includes(v.id)) {
|
|
2916
|
-
spotlightVulnsFound.add(v.id);
|
|
2917
|
-
}
|
|
2918
|
-
}
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
return [...spotlightVulnsFound];
|
|
2922
|
-
}
|
|
2923
|
-
catch (err) {
|
|
2924
|
-
debug('Error in containsSpotlightVulnIds()', err);
|
|
2925
|
-
return [];
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
exports.containsSpotlightVulnIds = containsSpotlightVulnIds;
|
|
2929
|
-
function notificationForSpotlightVulns(foundSpotlightVulnsIds) {
|
|
2930
|
-
try {
|
|
2931
|
-
if (foundSpotlightVulnsIds.length > 0) {
|
|
2932
|
-
let message = '';
|
|
2933
|
-
for (const vulnId of spotlightVulnIds) {
|
|
2934
|
-
if (vulnId === 'SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720') {
|
|
2935
|
-
message += theme.color.severity.critical(`${theme.icon.WARNING} WARNING: Critical severity vulnerabilities were found with Log4j!` +
|
|
2936
|
-
os_1.EOL);
|
|
2937
|
-
for (const vulnId of foundSpotlightVulnsIds) {
|
|
2938
|
-
message += ` - ${vulnId} (See https://snyk.io/vuln/${vulnId})`;
|
|
2939
|
-
}
|
|
2940
|
-
message += os_1.EOL + os_1.EOL;
|
|
2941
|
-
message +=
|
|
2942
|
-
theme.color.severity.critical(`We highly recommend fixing this vulnerability. If it cannot be fixed by upgrading, see mitigation information here:`) +
|
|
2943
|
-
os_1.EOL +
|
|
2944
|
-
' - https://security.snyk.io/vuln/SNYK-JAVA-ORGAPACHELOGGINGLOG4J-2314720' +
|
|
2945
|
-
os_1.EOL +
|
|
2946
|
-
' - https://snyk.io/blog/log4shell-remediation-cheat-sheet/' +
|
|
2947
|
-
os_1.EOL;
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
return message;
|
|
2951
|
-
}
|
|
2952
|
-
return '';
|
|
2953
|
-
}
|
|
2954
|
-
catch (err) {
|
|
2955
|
-
debug('Error in notificationForSpotlightVulns()', err);
|
|
2956
|
-
return '';
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
exports.notificationForSpotlightVulns = notificationForSpotlightVulns;
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
2759
|
/***/ }),
|
|
2963
2760
|
|
|
2964
2761
|
/***/ 14784:
|