diff --git a/.gitignore b/.gitignore index 282f2d317..9e30e7be3 100644 --- a/.gitignore +++ b/.gitignore @@ -80,6 +80,8 @@ !/src/commands/raw-npx/ !/src/commands/repository/ !/src/commands/scan/ +!/src/commands/scan/gitlab-dependency-report.mts +!/src/commands/scan/gitlab-dependency-report.test.mts !/src/commands/threat-feed/ !/src/commands/uninstall/ !/src/commands/wrapper/ diff --git a/docs/commands/README.md b/docs/commands/README.md index e88b5bbd0..dd1115c44 100644 --- a/docs/commands/README.md +++ b/docs/commands/README.md @@ -10,6 +10,7 @@ Guides for Socket CLI commands: - [cdxgen](cdxgen.md) - [patch](patch/README.md) - [ci](ci.md) +- [`socket scan report`](scan/report.md) Patch subcommands: diff --git a/docs/commands/scan/report.md b/docs/commands/scan/report.md new file mode 100644 index 000000000..bf864f4d5 --- /dev/null +++ b/docs/commands/scan/report.md @@ -0,0 +1,34 @@ +# `socket scan report` + +Generate a report for a completed Socket scan. The command can also write a +GitLab Dependency Scanning report for GitLab's Security Dashboard: + +```sh +socket scan report "$SOCKET_SCAN_ID" --enable-gitlab-security +``` + +This writes `gl-dependency-scanning-report.json` in the current directory. +Choose another destination with `--gitlab-security-file`: + +```sh +socket scan report "$SOCKET_SCAN_ID" \ + --enable-gitlab-security \ + --gitlab-security-file reports/dependency-scanning.json +``` + +Add the report to the `dependency_scanning` CI artifact so GitLab can ingest it: + +```yaml +socket-dependency-scan: + script: + - socket scan report "$SOCKET_SCAN_ID" --enable-gitlab-security + artifacts: + reports: + dependency_scanning: gl-dependency-scanning-report.json + paths: + - gl-dependency-scanning-report.json +``` + +The report uses GitLab Dependency Scanning schema version `15.0.0`. Findings +are generated from the scan's package and alert data before CLI report folding +or policy-level filtering is applied. diff --git a/package.json b/package.json index 020b0d4d6..cae35a1d0 100644 --- a/package.json +++ b/package.json @@ -173,6 +173,8 @@ "@typescript-eslint/parser": "8.43.0", "@typescript/native-preview": "7.0.0-dev.20250912.1", "@vitest/coverage-v8": "5.1.1", + "ajv": "8.20.0", + "ajv-formats": "3.0.1", "blessed": "0.1.81", "blessed-contrib": "4.11.0", "browserslist": "4.29.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 846d5b294..34e0827ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -465,6 +465,12 @@ importers: '@vitest/coverage-v8': specifier: 5.1.1 version: 5.1.1(vitest@5.1.1) + ajv: + specifier: 8.20.0 + version: 8.20.0 + ajv-formats: + specifier: 3.0.1 + version: 3.0.1(ajv@8.20.0) blessed: specifier: 0.1.81 version: 0.1.81(patch_hash=cab33a0881f68052e914af0948c3b5964e8dafe16980ba0027cbe6d9d216082d) @@ -6727,7 +6733,7 @@ snapshots: '@npmcli/name-from-folder': 4.0.0 '@npmcli/package-json': 7.0.5 ajv: 8.20.0 - ajv-formats: 3.0.1 + ajv-formats: 3.0.1(ajv@8.20.0) cheerio: 1.2.0 common-ancestor-path: 1.0.1 edn-data: 1.2.2 @@ -8473,8 +8479,8 @@ snapshots: agent-base@9.0.0: {} - ajv-formats@3.0.1: - dependencies: + ajv-formats@3.0.1(ajv@8.20.0): + optionalDependencies: ajv: 8.20.0 ajv@6.15.0: diff --git a/src/commands/scan/cmd-scan-report.mts b/src/commands/scan/cmd-scan-report.mts index 2a7d29ee7..16faf5e15 100644 --- a/src/commands/scan/cmd-scan-report.mts +++ b/src/commands/scan/cmd-scan-report.mts @@ -49,6 +49,16 @@ async function run( default: constants.FOLD_SETTING_NONE, description: `Fold reported alerts to some degree (default '${constants.FOLD_SETTING_NONE}')`, }, + enableGitlabSecurity: { + type: 'boolean', + default: false, + description: 'Write a GitLab Dependency Scanning report', + }, + gitlabSecurityFile: { + type: 'string', + default: 'gl-dependency-scanning-report.json', + description: 'Output path for the GitLab Dependency Scanning report', + }, interactive: { type: 'boolean', default: true, @@ -124,7 +134,13 @@ async function run( parentName, }) - const { json, markdown, org: orgFlag } = cli.flags + const { + enableGitlabSecurity, + gitlabSecurityFile, + json, + markdown, + org: orgFlag, + } = cli.flags const dryRun = !!cli.flags['dryRun'] @@ -194,5 +210,9 @@ async function run( fold, short, reportLevel, + enableGitlabSecurity: !!enableGitlabSecurity, + gitlabSecurityFile: String( + gitlabSecurityFile || 'gl-dependency-scanning-report.json', + ), }) } diff --git a/src/commands/scan/cmd-scan-report.test.mts b/src/commands/scan/cmd-scan-report.test.mts index 5ebcf3bca..0ab191a5c 100644 --- a/src/commands/scan/cmd-scan-report.test.mts +++ b/src/commands/scan/cmd-scan-report.test.mts @@ -30,7 +30,9 @@ describe('socket scan report', async () => { - Permissions: full-scans:list Options + --enable-gitlab-security Write a GitLab Dependency Scanning report --fold Fold reported alerts to some degree (default 'none') + --gitlab-security-file Output path for the GitLab Dependency Scanning report --interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no. --json Output as JSON diff --git a/src/commands/scan/gitlab-dependency-report.mts b/src/commands/scan/gitlab-dependency-report.mts new file mode 100644 index 000000000..6fbf69f29 --- /dev/null +++ b/src/commands/scan/gitlab-dependency-report.mts @@ -0,0 +1,313 @@ +import { createHash } from 'node:crypto' + +import { getSocketDevPackageOverviewUrlFromPurl } from '../../utils/socket-url.mts' + +import type { SocketArtifact } from '../../utils/alert/artifact.mts' + +const GITLAB_NAMESPACE = Buffer.from('6ba7b8109dad11d180b400c04fd430c8', 'hex') + +type GitLabIdentifier = { + type: string + name: string + value: string + url?: string +} + +type GitLabVulnerability = { + id: string + category: 'dependency_scanning' + name: string + message: string + description: string + severity: string + identifiers: GitLabIdentifier[] + links: Array<{ url: string }> + location: { + file: string + dependency: { + package: { name: string } + version: string + direct: boolean + } + } + solution?: string +} + +type GitLabAlert = NonNullable[number] & { + url?: string + title?: string + description?: string + suggestion?: string +} + +type GitLabArtifact = SocketArtifact & { namespace?: string; purl?: string } + +const severityMap: Record = { + critical: 'Critical', + high: 'High', + medium: 'Medium', + middle: 'Medium', + low: 'Low', +} + +const packageManagerMap: Record = { + npm: 'npm', + pypi: 'pip', + go: 'go', + golang: 'go', + maven: 'maven', + gem: 'bundler', + nuget: 'nuget', + cargo: 'cargo', +} + +function uuid5(name: string): string { + const bytes = createHash('sha1') + .update(GITLAB_NAMESPACE) + .update(name, 'utf8') + .digest() + .subarray(0, 16) + bytes[6] = (bytes[6]! & 0x0f) | 0x50 + bytes[8] = (bytes[8]! & 0x3f) | 0x80 + const hex = bytes.toString('hex') + return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}` +} + +function getFindingId( + ecosystem: string, + coordinate: string, + type: string, + severity: string, + advisory: string, + alertKey: string, + manifest: string, +): string { + const serialized = JSON.stringify([ + ecosystem, + coordinate, + type, + severity, + advisory, + alertKey, + manifest, + ]) + let identity = '' + for (let index = 0; index < serialized.length; index += 1) { + const code = serialized.charCodeAt(index) + identity += + code > 0x7f + ? `\\u${code.toString(16).padStart(4, '0')}` + : serialized[index] + } + return uuid5(identity) +} + +function getAdvisory(alert: GitLabAlert): string { + const props = alert.props ?? {} + const values = ['ghsaId', 'ghsa_id', 'cveId', 'cve_id', 'cve'].flatMap( + field => { + const value = props[field] + return Array.isArray(value) ? value : [value] + }, + ) + const advisory = values.find( + (value): value is string => typeof value === 'string' && !!value.trim(), + ) + return advisory?.trim().toUpperCase() ?? '' +} + +function getIdentifiers(alert: GitLabAlert): GitLabIdentifier[] { + const identifiers: GitLabIdentifier[] = [ + { + type: 'socket_alert', + name: `Socket ${alert.type}`, + value: alert.type, + ...(alert.url ? { url: alert.url } : {}), + }, + ] + const props = alert.props ?? {} + const seen = new Set() + const sources: Array<[string[], string, string]> = [ + [['cveId', 'cve_id', 'cve'], 'cve', 'https://nvd.nist.gov/vuln/detail/'], + [['ghsaId', 'ghsa_id'], 'ghsa', 'https://github.com/advisories/'], + ] + for (const [fields, type, prefix] of sources) { + for (const field of fields) { + const value = props[field] + const values = + typeof value === 'string' ? [value] : Array.isArray(value) ? value : [] + for (const id of values) { + if ( + typeof id !== 'string' || + !id.trim() || + seen.has(`${type}:${id.toUpperCase()}`) + ) { + continue + } + seen.add(`${type}:${id.toUpperCase()}`) + identifiers.push({ type, name: id, value: id, url: `${prefix}${id}` }) + } + } + } + return identifiers +} + +function getLocation( + artifact: GitLabArtifact, + artifactsById: Map, + packageName = artifact.name || 'unknown', +) { + let manifest: string | undefined + for (const ancestorId of artifact.topLevelAncestors ?? []) { + manifest = artifactsById + .get(ancestorId) + ?.manifestFiles?.find(entry => entry.file)?.file + if (manifest) { + break + } + } + manifest ??= artifact.manifestFiles?.find(entry => entry.file)?.file + return { + file: manifest || 'unknown', + dependency: { + package: { name: packageName }, + version: artifact.version || 'unknown', + direct: Boolean(artifact.direct), + }, + } +} + +function getDisplayPackageName( + ecosystem: string, + artifact: GitLabArtifact, +): string { + const packageName = artifact.name || 'unknown' + const namespace = artifact.namespace?.replace(/^\/+|\/+$/g, '') || '' + if (!namespace) { + return packageName + } + return ecosystem === 'maven' + ? `${namespace}:${packageName}` + : `${namespace}/${packageName}` +} + +export function createGitLabDependencyReport( + artifacts: SocketArtifact[], + version: string, + startTime = new Date(), +): Record { + const vulnerabilities: GitLabVulnerability[] = [] + const dependencyFiles = new Map< + string, + { + path: string + package_manager: string + dependencies: Array<{ package: { name: string }; version: string }> + } + >() + const seen = new Set() + const artifactsById = new Map() + for (const sourceArtifact of artifacts) { + const artifact = sourceArtifact as GitLabArtifact + if (artifact.id) { + artifactsById.set(artifact.id, artifact) + } + } + + for (const sourceArtifact of artifacts) { + const artifact = sourceArtifact as GitLabArtifact + const ecosystem = artifact.type || '' + const packageName = artifact.name || 'unknown' + const displayPackageName = getDisplayPackageName(ecosystem, artifact) + const packageVersion = artifact.version || 'unknown' + for (const sourceAlert of artifact.alerts ?? []) { + const alert = sourceAlert as GitLabAlert + const namespace = artifact.namespace?.replace(/^\/+|\/+$/g, '') || '' + const purl = + artifact.purl || + `${ecosystem}/${namespace ? `${namespace}/` : ''}${packageName}@${packageVersion}` + const normalizedPurl = purl.replace(/^pkg:/, '').replace(/^\/+/, '') + const coordinate = normalizedPurl.startsWith(`${ecosystem}/`) + ? normalizedPurl.slice(ecosystem.length + 1) + : normalizedPurl + const location = getLocation(artifact, artifactsById, displayPackageName) + const id = getFindingId( + ecosystem, + coordinate, + alert.type, + alert.severity || '', + getAdvisory(alert), + alert.key || '', + location.file, + ) + if (seen.has(id)) { + continue + } + seen.add(id) + + const title = alert.title || alert.type + const url = alert.url || getSocketDevPackageOverviewUrlFromPurl(artifact) + vulnerabilities.push({ + id, + category: 'dependency_scanning', + name: title, + message: `${displayPackageName}@${packageVersion}: ${title}`, + description: alert.description || '', + severity: severityMap[alert.severity?.toLowerCase() ?? ''] || 'Unknown', + identifiers: getIdentifiers(alert), + links: url ? [{ url }] : [], + location, + ...(alert.suggestion ? { solution: alert.suggestion } : {}), + }) + + if (location.file !== 'unknown') { + let dependencyFile = dependencyFiles.get(location.file) + if (!dependencyFile) { + dependencyFile = { + path: location.file, + package_manager: + packageManagerMap[ecosystem] || ecosystem || 'unknown', + dependencies: [], + } + dependencyFiles.set(location.file, dependencyFile) + } + const duplicate = dependencyFile.dependencies.some( + dependency => + dependency.package.name === displayPackageName && + dependency.version === packageVersion, + ) + if (!duplicate) { + dependencyFile.dependencies.push({ + package: { name: displayPackageName }, + version: packageVersion, + }) + } + } + } + } + + const timestamp = startTime.toISOString().replace(/\.\d{3}Z$/, '') + return { + version: '15.0.0', + scan: { + analyzer: { + id: 'socket-security', + name: 'Socket Security', + version, + vendor: { name: 'Socket' }, + }, + scanner: { + id: 'socket-cli', + name: 'Socket CLI', + version, + vendor: { name: 'Socket' }, + }, + type: 'dependency_scanning', + start_time: timestamp, + end_time: timestamp, + status: 'success', + }, + vulnerabilities, + dependency_files: [...dependencyFiles.values()], + } +} diff --git a/src/commands/scan/gitlab-dependency-report.test.mts b/src/commands/scan/gitlab-dependency-report.test.mts new file mode 100644 index 000000000..f00e2a4d2 --- /dev/null +++ b/src/commands/scan/gitlab-dependency-report.test.mts @@ -0,0 +1,314 @@ +import AjvCtor from 'ajv' +import addFormats from 'ajv-formats' +import { describe, expect, it } from 'vitest' + +import { createGitLabDependencyReport } from './gitlab-dependency-report.mts' +import gitLabSchema from '../../../test/fixtures/schemas/gitlab/dependency-scanning-report-v15.json' with { + type: 'json', +} + +import type { SocketArtifact } from '../../utils/alert/artifact.mts' + +const version = '1.2.3' +const timestamp = new Date('2026-01-02T03:04:05.000Z') + +function artifact(severity: string, alertType = 'cve'): SocketArtifact { + return { + type: 'npm', + name: 'left-pad', + version: '1.3.0', + purl: 'pkg:npm/left-pad@1.3.0', + direct: true, + manifestFiles: [{ file: 'package-lock.json' }], + alerts: [ + { + key: `${alertType}-${severity}`, + type: alertType, + severity, + action: 'warn', + props: { cveId: ['CVE-2024-0001'], ghsaId: 'GHSA-0000-0000-0000' }, + url: 'https://socket.dev/npm/package/left-pad/overview/1.3.0', + title: `${severity} issue`, + description: 'Finding description', + suggestion: 'Upgrade to 2.0.0', + }, + ], + } as unknown as SocketArtifact +} + +describe('GitLab Dependency Scanning report', () => { + it('validates populated and empty reports against the pinned GitLab v15 schema', () => { + const ajv = new AjvCtor({ allErrors: true, strict: false }) + addFormats(ajv) + const validate = ajv.compile(gitLabSchema) + const reports = [ + createGitLabDependencyReport([], version, timestamp), + createGitLabDependencyReport( + ['critical', 'high', 'medium', 'middle', 'low', 'other'].map(value => + artifact(value), + ), + version, + timestamp, + ), + ] + + for (const report of reports) { + expect(validate(report), JSON.stringify(validate.errors)).toBe(true) + } + }) + + it('emits an empty v15 report with stable scan metadata', () => { + expect(createGitLabDependencyReport([], version, timestamp)).toEqual({ + version: '15.0.0', + scan: { + analyzer: { + id: 'socket-security', + name: 'Socket Security', + version, + vendor: { name: 'Socket' }, + }, + scanner: { + id: 'socket-cli', + name: 'Socket CLI', + version, + vendor: { name: 'Socket' }, + }, + type: 'dependency_scanning', + start_time: '2026-01-02T03:04:05', + end_time: '2026-01-02T03:04:05', + status: 'success', + }, + vulnerabilities: [], + dependency_files: [], + }) + }) + + it('maps supported severities, locations, identifiers, Socket links, and stable IDs', () => { + const artifacts = [ + 'critical', + 'high', + 'medium', + 'middle', + 'low', + 'other', + ].map(value => artifact(value)) + const report = createGitLabDependencyReport( + artifacts, + version, + timestamp, + ) as { + vulnerabilities: Array> + dependency_files: Array> + } + expect(report.vulnerabilities.map(finding => finding.severity)).toEqual([ + 'Critical', + 'High', + 'Medium', + 'Medium', + 'Low', + 'Unknown', + ]) + expect(report.vulnerabilities[0]).toMatchObject({ + category: 'dependency_scanning', + name: 'critical issue', + message: 'left-pad@1.3.0: critical issue', + description: 'Finding description', + links: [ + { url: 'https://socket.dev/npm/package/left-pad/overview/1.3.0' }, + ], + location: { + file: 'package-lock.json', + dependency: { + package: { name: 'left-pad' }, + version: '1.3.0', + direct: true, + }, + }, + solution: 'Upgrade to 2.0.0', + }) + expect(report.vulnerabilities[0]?.identifiers).toContainEqual({ + type: 'ghsa', + name: 'GHSA-0000-0000-0000', + value: 'GHSA-0000-0000-0000', + url: 'https://github.com/advisories/GHSA-0000-0000-0000', + }) + expect(report.vulnerabilities[0]?.id).toBe( + '49c00d5f-ee98-56f6-bb66-f5e184fa9497', + ) + expect(report.dependency_files).toEqual([ + { + path: 'package-lock.json', + package_manager: 'npm', + dependencies: [ + { + package: { name: 'left-pad' }, + version: '1.3.0', + }, + ], + }, + ]) + }) + + it('deduplicates identical findings in the raw scan data', () => { + const report = createGitLabDependencyReport( + [artifact('high'), artifact('high')], + version, + timestamp, + ) as { + vulnerabilities: unknown[] + } + expect(report.vulnerabilities).toHaveLength(1) + }) + + it('keeps same-name packages in different namespaces as distinct findings', () => { + const scopedArtifacts = ['@first', '@second'].map(namespace => ({ + ...artifact('high'), + name: 'same', + version: '1.0.0', + namespace, + purl: undefined, + })) + const report = createGitLabDependencyReport( + scopedArtifacts, + version, + timestamp, + ) as { + vulnerabilities: Array> + } + expect(report.vulnerabilities.map(finding => finding.id)).toEqual([ + 'c9c5b12a-04a6-581d-8676-5033e5feaa0d', + '38cd0cfb-a713-5511-b577-7ee64e7096e8', + ]) + }) + + it('preserves alert and manifest identity, namespaces, and ecosystem mappings', () => { + const alert = artifact('high').alerts?.[0] + const reports = createGitLabDependencyReport( + [ + { + ...artifact('high'), + namespace: '@scope', + manifestFiles: [{ file: 'package-lock.json' }], + alerts: [ + alert, + { ...alert, key: 'second-alert', type: 'socketRisk' }, + ], + }, + { + ...artifact('high'), + namespace: '@scope', + manifestFiles: [{ file: 'other-lock.json' }], + }, + { + ...artifact('high'), + type: 'golang', + namespace: 'example.com/acme', + name: 'widget', + manifestFiles: [{ file: 'go.sum' }], + }, + { + ...artifact('high'), + type: 'maven', + namespace: 'com.google.guava', + name: 'guava', + manifestFiles: [{ file: 'pom.xml' }], + }, + ] as unknown as SocketArtifact[], + version, + timestamp, + ) as { + vulnerabilities: Array> + dependency_files: Array> + } + + expect(reports.vulnerabilities).toHaveLength(5) + expect( + reports.vulnerabilities.map( + finding => finding.location.dependency.package.name, + ), + ).toEqual([ + '@scope/left-pad', + '@scope/left-pad', + '@scope/left-pad', + 'example.com/acme/widget', + 'com.google.guava:guava', + ]) + expect(reports.dependency_files).toEqual( + expect.arrayContaining([ + expect.objectContaining({ path: 'go.sum', package_manager: 'go' }), + expect.objectContaining({ path: 'pom.xml', package_manager: 'maven' }), + ]), + ) + expect( + reports.dependency_files.find(file => file.path === 'package-lock.json') + ?.dependencies, + ).toHaveLength(1) + }) + + it('uses top-level ancestor manifests before the artifact manifest and ignores alert files', () => { + const transitive = { + ...artifact('high'), + id: 'transitive', + topLevelAncestors: ['root'], + manifestFiles: [{ file: 'node_modules/some-package/package.json' }], + alerts: [ + { + ...artifact('high').alerts?.[0], + key: 'high-transitive', + file: 'dist/bundle.js', + }, + ], + } + const root = { + type: 'npm', + id: 'root', + name: 'application', + version: '1.0.0', + manifestFiles: [{ file: 'package-lock.json' }], + } + const report = createGitLabDependencyReport( + [transitive, root] as unknown as SocketArtifact[], + version, + timestamp, + ) as { vulnerabilities: Array> } + expect(report.vulnerabilities[0]?.location).toMatchObject({ + file: 'package-lock.json', + }) + }) + + it('uses an artifact manifest or unknown when there is no ancestor manifest', () => { + const withOwnManifest = { + ...artifact('high'), + id: 'with-manifest', + topLevelAncestors: ['root-without-manifest'], + manifestFiles: [{ file: 'pnpm-lock.yaml' }], + alerts: [{ ...artifact('high').alerts?.[0], key: 'own-manifest' }], + } + const withoutManifest = { + ...artifact('low'), + id: 'without-manifest', + alerts: [ + { + ...artifact('low').alerts?.[0], + key: 'no-manifest', + file: 'dist/bundle.js', + }, + ], + manifestFiles: [], + } + const root = { + type: 'npm', + id: 'root-without-manifest', + name: 'app', + version: '1', + } + const report = createGitLabDependencyReport( + [withOwnManifest, withoutManifest, root] as unknown as SocketArtifact[], + version, + timestamp, + ) as { vulnerabilities: Array> } + expect( + report.vulnerabilities.map(finding => finding.location.file), + ).toEqual(['pnpm-lock.yaml', 'unknown']) + }) +}) diff --git a/src/commands/scan/handle-scan-report.mts b/src/commands/scan/handle-scan-report.mts index 3fee42c95..5c4f86fb2 100644 --- a/src/commands/scan/handle-scan-report.mts +++ b/src/commands/scan/handle-scan-report.mts @@ -13,11 +13,15 @@ export type HandleScanReportConfig = { fold: FOLD_SETTING reportLevel: REPORT_LEVEL short: boolean + enableGitlabSecurity?: boolean + gitlabSecurityFile?: string } export async function handleScanReport({ + enableGitlabSecurity, filepath, fold, + gitlabSecurityFile, includeLicensePolicy, orgSlug, outputKind, @@ -38,5 +42,8 @@ export async function handleScanReport({ outputKind, reportLevel, short, + enableGitlabSecurity: enableGitlabSecurity ?? false, + gitlabSecurityFile: + gitlabSecurityFile ?? 'gl-dependency-scanning-report.json', }) } diff --git a/src/commands/scan/output-scan-report.mts b/src/commands/scan/output-scan-report.mts index 0a48f3701..b5cfd3f89 100644 --- a/src/commands/scan/output-scan-report.mts +++ b/src/commands/scan/output-scan-report.mts @@ -1,6 +1,8 @@ import fs from 'node:fs/promises' +import path from 'node:path' import { generateReport } from './generate-report.mts' +import { createGitLabDependencyReport } from './gitlab-dependency-report.mts' import constants, { EXT_JSON, FOLD_SETTING_NONE, @@ -32,6 +34,8 @@ export type OutputScanReportConfig = { fold: FOLD_SETTING reportLevel: REPORT_LEVEL short: boolean + enableGitlabSecurity?: boolean + gitlabSecurityFile?: string } export type ReportAlertRow = { @@ -110,8 +114,10 @@ export async function outputScanReport( scan: SocketArtifact[] }>, { + enableGitlabSecurity, filepath, fold, + gitlabSecurityFile, includeLicensePolicy, orgSlug, outputKind, @@ -133,6 +139,33 @@ export async function outputScanReport( return } + const gitlabOutputPath = + gitlabSecurityFile || 'gl-dependency-scanning-report.json' + if ( + enableGitlabSecurity && + filepath && + filepath !== '-' && + path.resolve(filepath) === path.resolve(gitlabOutputPath) + ) { + setCiExitCode('infrastructure', 1) + logger.fail( + `The Socket scan report and GitLab Dependency Scanning report cannot use the same output path: ${filepath}`, + ) + return + } + + if (enableGitlabSecurity) { + const report = createGitLabDependencyReport( + result.data.scan, + constants.ENV.INLINED_SOCKET_CLI_VERSION, + ) + await fs.mkdir(path.dirname(gitlabOutputPath), { recursive: true }) + await fs.writeFile(gitlabOutputPath, `${JSON.stringify(report, null, 2)}\n`) + logger.info( + `GitLab Dependency Scanning report saved to ${gitlabOutputPath}`, + ) + } + const scanReport = generateReport(result.data.scan, { orgSlug, scanId, diff --git a/src/commands/scan/output-scan-report.test.mts b/src/commands/scan/output-scan-report.test.mts index 8159f9255..c0c4fc0e5 100644 --- a/src/commands/scan/output-scan-report.test.mts +++ b/src/commands/scan/output-scan-report.test.mts @@ -1,3 +1,7 @@ +import { mkdtemp, readFile, rm } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join } from 'node:path' + import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -263,6 +267,89 @@ describe('output-scan-report', () => { expect(process.exitCode).toBe(42) }) + + it('writes GitLab output to nested custom paths without changing policy exit behavior', async () => { + const previousExitCode = process.exitCode + const tempDir = await mkdtemp(join(tmpdir(), 'socket-gitlab-report-')) + mockGenerateReport.mockReturnValue({ + ok: true, + data: getUnhealthyReport(), + }) + + try { + await outputScanReport( + { + ok: true, + data: { scan: [] }, + } as any, + { + orgSlug: 'test-org', + scanId: 'test-scan', + includeLicensePolicy: false, + outputKind: 'json', + filepath: '-', + fold: 'none', + reportLevel: 'error', + short: false, + enableGitlabSecurity: true, + gitlabSecurityFile: join( + tempDir, + 'nested', + 'reports', + 'gl-report.json', + ), + }, + ) + + const report = JSON.parse( + await readFile( + join(tempDir, 'nested', 'reports', 'gl-report.json'), + 'utf8', + ), + ) as { version: string; vulnerabilities: unknown[] } + expect(report.version).toBe('15.0.0') + expect(report.vulnerabilities).toEqual([]) + expect(process.exitCode).toBe(1) + } finally { + process.exitCode = previousExitCode + await rm(tempDir, { recursive: true, force: true }) + } + }) + + it('rejects equivalent Socket and GitLab output paths before writing either report', async () => { + const previousExitCode = process.exitCode + const tempDir = await mkdtemp(join(tmpdir(), 'socket-gitlab-collision-')) + const gitlabPath = join(tempDir, 'report.json') + const socketPath = join(tempDir, 'nested', '..', 'report.json') + + try { + await outputScanReport( + { + ok: true, + data: { scan: [] }, + } as any, + { + orgSlug: 'test-org', + scanId: 'test-scan', + includeLicensePolicy: false, + outputKind: 'json', + filepath: socketPath, + fold: 'none', + reportLevel: 'error', + short: false, + enableGitlabSecurity: true, + gitlabSecurityFile: gitlabPath, + }, + ) + + await expect(readFile(gitlabPath, 'utf8')).rejects.toThrow() + expect(mockGenerateReport).not.toHaveBeenCalled() + expect(process.exitCode).toBe(1) + } finally { + process.exitCode = previousExitCode + await rm(tempDir, { recursive: true, force: true }) + } + }) }) }) diff --git a/test/fixtures/schemas/gitlab/LICENSE.md b/test/fixtures/schemas/gitlab/LICENSE.md new file mode 100644 index 000000000..2aab9b734 --- /dev/null +++ b/test/fixtures/schemas/gitlab/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017-present GitLab B.V. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/schemas/gitlab/README.md b/test/fixtures/schemas/gitlab/README.md new file mode 100644 index 000000000..70669716a --- /dev/null +++ b/test/fixtures/schemas/gitlab/README.md @@ -0,0 +1,5 @@ +# GitLab Dependency Scanning schema fixture + +`dependency-scanning-report-v15.json` is copied from GitLab's +[`security-report-schemas` v15.0.0 dependency scanning schema](https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/blob/v15.0.0/dist/dependency-scanning-report-format.json). +The upstream license is included in `LICENSE.md`. diff --git a/test/fixtures/schemas/gitlab/dependency-scanning-report-v15.json b/test/fixtures/schemas/gitlab/dependency-scanning-report-v15.json new file mode 100644 index 000000000..50582a1ce --- /dev/null +++ b/test/fixtures/schemas/gitlab/dependency-scanning-report-v15.json @@ -0,0 +1,775 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/raw/master/dist/dependency-scanning-report-format.json", + "title": "Report format for GitLab Dependency Scanning", + "description": "This schema provides the the report format for Dependency Scanning analyzers (https://docs.gitlab.com/ee/user/application_security/dependency_scanning).", + "definitions": { + "detail_type": { + "oneOf": [ + { + "$ref": "#/definitions/named_list" + }, + { + "$ref": "#/definitions/list" + }, + { + "$ref": "#/definitions/table" + }, + { + "$ref": "#/definitions/text" + }, + { + "$ref": "#/definitions/url" + }, + { + "$ref": "#/definitions/code" + }, + { + "$ref": "#/definitions/value" + }, + { + "$ref": "#/definitions/diff" + }, + { + "$ref": "#/definitions/markdown" + }, + { + "$ref": "#/definitions/commit" + }, + { + "$ref": "#/definitions/file_location" + }, + { + "$ref": "#/definitions/module_location" + } + ] + }, + "text_value": { + "type": "string" + }, + "named_field": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "$ref": "#/definitions/text_value", + "minLength": 1 + }, + "description": { + "$ref": "#/definitions/text_value" + } + } + }, + "named_list": { + "type": "object", + "description": "An object with named and typed fields", + "required": ["type", "items"], + "properties": { + "type": { + "const": "named-list" + }, + "items": { + "type": "object", + "patternProperties": { + "^.*$": { + "allOf": [ + { + "$ref": "#/definitions/named_field" + }, + { + "$ref": "#/definitions/detail_type" + } + ] + } + } + } + } + }, + "list": { + "type": "object", + "description": "A list of typed fields", + "required": ["type", "items"], + "properties": { + "type": { + "const": "list" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/detail_type" + } + } + } + }, + "table": { + "type": "object", + "description": "A table of typed fields", + "required": ["type", "rows"], + "properties": { + "type": { + "const": "table" + }, + "header": { + "type": "array", + "items": { + "$ref": "#/definitions/detail_type" + } + }, + "rows": { + "type": "array", + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/detail_type" + } + } + } + } + }, + "text": { + "type": "object", + "description": "Raw text", + "required": ["type", "value"], + "properties": { + "type": { + "const": "text" + }, + "value": { + "$ref": "#/definitions/text_value" + } + } + }, + "url": { + "type": "object", + "description": "A single URL", + "required": ["type", "href"], + "properties": { + "type": { + "const": "url" + }, + "text": { + "$ref": "#/definitions/text_value" + }, + "href": { + "type": "string", + "minLength": 1, + "examples": ["http://mysite.com"] + } + } + }, + "code": { + "type": "object", + "description": "A codeblock", + "required": ["type", "value"], + "properties": { + "type": { + "const": "code" + }, + "value": { + "type": "string" + }, + "lang": { + "type": "string", + "description": "A programming language" + } + } + }, + "value": { + "type": "object", + "description": "A field that can store a range of types of value", + "required": ["type", "value"], + "properties": { + "type": { + "const": "value" + }, + "value": { + "type": ["number", "string", "boolean"] + } + } + }, + "diff": { + "type": "object", + "description": "A diff", + "required": ["type", "before", "after"], + "properties": { + "type": { + "const": "diff" + }, + "before": { + "type": "string" + }, + "after": { + "type": "string" + } + } + }, + "markdown": { + "type": "object", + "description": "GitLab flavoured markdown, see https://docs.gitlab.com/ee/user/markdown.html", + "required": ["type", "value"], + "properties": { + "type": { + "const": "markdown" + }, + "value": { + "$ref": "#/definitions/text_value", + "examples": [ + "Here is markdown `inline code` #1 [test](gitlab.com)\n\n![GitLab Logo](https://about.gitlab.com/images/press/logo/preview/gitlab-logo-white-preview.png)" + ] + } + } + }, + "commit": { + "type": "object", + "description": "A commit/tag/branch within the GitLab project", + "required": ["type", "value"], + "properties": { + "type": { + "const": "commit" + }, + "value": { + "type": "string", + "description": "The commit SHA", + "minLength": 1 + } + } + }, + "file_location": { + "type": "object", + "description": "A location within a file in the project", + "required": ["type", "file_name", "line_start"], + "properties": { + "type": { + "const": "file-location" + }, + "file_name": { + "type": "string", + "minLength": 1 + }, + "line_start": { + "type": "integer" + }, + "line_end": { + "type": "integer" + } + } + }, + "module_location": { + "type": "object", + "description": "A location within a binary module of the form module+relative_offset", + "required": ["type", "module_name", "offset"], + "properties": { + "type": { + "const": "module-location" + }, + "module_name": { + "type": "string", + "minLength": 1, + "examples": ["compiled_binary"] + }, + "offset": { + "type": "integer", + "examples": [100] + } + } + } + }, + "self": { + "version": "15.0.0" + }, + "required": ["dependency_files", "scan", "version", "vulnerabilities"], + "additionalProperties": true, + "properties": { + "scan": { + "type": "object", + "required": [ + "analyzer", + "end_time", + "scanner", + "start_time", + "status", + "type" + ], + "properties": { + "end_time": { + "type": "string", + "description": "ISO8601 UTC value with format yyyy-mm-ddThh:mm:ss, representing when the scan finished.", + "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$", + "examples": ["2020-01-28T03:26:02"] + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "description": "Communication intended for the initiator of a scan.", + "required": ["level", "value"], + "properties": { + "level": { + "type": "string", + "description": "Describes the severity of the communication. Use info to communicate normal scan behaviour; warn to communicate a potentially recoverable problem, or a partial error; fatal to communicate an issue that causes the scan to halt.", + "enum": ["info", "warn", "fatal"], + "examples": ["info"] + }, + "value": { + "type": "string", + "description": "The message to communicate.", + "minLength": 1, + "examples": ["Permission denied, scanning aborted"] + } + } + } + }, + "analyzer": { + "type": "object", + "description": "Object defining the analyzer used to perform the scan. Analyzers typically delegate to an underlying scanner to run the scan.", + "required": ["id", "name", "version", "vendor"], + "properties": { + "id": { + "type": "string", + "description": "Unique id that identifies the analyzer.", + "minLength": 1, + "examples": ["gitlab-dast"] + }, + "name": { + "type": "string", + "description": "A human readable value that identifies the analyzer, not required to be unique.", + "minLength": 1, + "examples": ["GitLab DAST"] + }, + "url": { + "type": "string", + "pattern": "^https?://.+", + "description": "A link to more information about the analyzer.", + "examples": [ + "https://docs.gitlab.com/ee/user/application_security/dast" + ] + }, + "vendor": { + "description": "The vendor/maintainer of the analyzer.", + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "description": "The name of the vendor.", + "minLength": 1, + "examples": ["GitLab"] + } + } + }, + "version": { + "type": "string", + "description": "The version of the analyzer.", + "minLength": 1, + "examples": ["1.0.2"] + } + } + }, + "scanner": { + "type": "object", + "description": "Object defining the scanner used to perform the scan.", + "required": ["id", "name", "version", "vendor"], + "properties": { + "id": { + "type": "string", + "description": "Unique id that identifies the scanner.", + "minLength": 1, + "examples": ["my-sast-scanner"] + }, + "name": { + "type": "string", + "description": "A human readable value that identifies the scanner, not required to be unique.", + "minLength": 1, + "examples": ["My SAST Scanner"] + }, + "url": { + "type": "string", + "description": "A link to more information about the scanner.", + "examples": ["https://scanner.url"] + }, + "version": { + "type": "string", + "description": "The version of the scanner.", + "minLength": 1, + "examples": ["1.0.2"] + }, + "vendor": { + "description": "The vendor/maintainer of the scanner.", + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "description": "The name of the vendor.", + "minLength": 1, + "examples": ["GitLab"] + } + } + } + } + }, + "start_time": { + "type": "string", + "description": "ISO8601 UTC value with format yyyy-mm-ddThh:mm:ss, representing when the scan started.", + "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$", + "examples": ["2020-02-14T16:01:59"] + }, + "status": { + "type": "string", + "description": "Result of the scan.", + "enum": ["success", "failure"] + }, + "type": { + "type": "string", + "description": "Type of the scan.", + "enum": ["dependency_scanning"] + } + } + }, + "schema": { + "type": "string", + "description": "URI pointing to the validating security report schema.", + "pattern": "^https?://.+" + }, + "version": { + "type": "string", + "description": "The version of the schema to which the JSON report conforms.", + "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" + }, + "vulnerabilities": { + "type": "array", + "description": "Array of vulnerability objects.", + "items": { + "type": "object", + "description": "Describes the vulnerability using GitLab Flavored Markdown", + "required": ["id", "identifiers", "location"], + "properties": { + "id": { + "type": "string", + "minLength": 1, + "description": "Unique identifier of the vulnerability. This is recommended to be a UUID.", + "examples": ["642735a5-1425-428d-8d4e-3c854885a3c9"] + }, + "name": { + "type": "string", + "maxLength": 255, + "description": "The name of the vulnerability. This must not include the finding's specific information." + }, + "description": { + "type": "string", + "maxLength": 1048576, + "description": "A long text section describing the vulnerability more fully." + }, + "severity": { + "type": "string", + "description": "How much the vulnerability impacts the software. Possible values are Info, Unknown, Low, Medium, High, or Critical. Note that some analyzers may not report all these possible values.", + "enum": ["Info", "Unknown", "Low", "Medium", "High", "Critical"] + }, + "solution": { + "type": "string", + "maxLength": 7000, + "description": "Explanation of how to fix the vulnerability." + }, + "identifiers": { + "type": "array", + "minItems": 1, + "description": "An ordered array of references that identify a vulnerability on internal or external databases. The first identifier is the Primary Identifier, which has special meaning.", + "items": { + "type": "object", + "required": ["type", "name", "value"], + "properties": { + "type": { + "type": "string", + "description": "for example, cve, cwe, osvdb, usn, or an analyzer-dependent type such as gemnasium).", + "minLength": 1 + }, + "name": { + "type": "string", + "description": "Human-readable name of the identifier.", + "minLength": 1 + }, + "url": { + "type": "string", + "description": "URL of the identifier's documentation.", + "pattern": "^https?://.+" + }, + "value": { + "type": "string", + "description": "Value of the identifier, for matching purpose.", + "minLength": 1 + } + } + } + }, + "links": { + "type": "array", + "description": "An array of references to external documentation or articles that describe the vulnerability.", + "items": { + "type": "object", + "required": ["url"], + "properties": { + "name": { + "type": "string", + "description": "Name of the vulnerability details link." + }, + "url": { + "type": "string", + "description": "URL of the vulnerability details document.", + "pattern": "^https?://.+" + } + } + } + }, + "details": { + "$ref": "#/definitions/named_list/properties/items" + }, + "tracking": { + "description": "Describes how this vulnerability should be tracked as the project changes.", + "oneOf": [ + { + "description": "Declares that a series of items should be tracked using source-specific tracking methods.", + "required": ["items"], + "properties": { + "type": { + "const": "source" + }, + "items": { + "type": "array", + "items": { + "description": "An item that should be tracked using source-specific tracking methods.", + "type": "object", + "required": ["signatures"], + "properties": { + "file": { + "type": "string", + "description": "Path to the file where the vulnerability is located." + }, + "start_line": { + "type": "number", + "description": "The first line of the file that includes the vulnerability." + }, + "end_line": { + "type": "number", + "description": "The last line of the file that includes the vulnerability." + }, + "signatures": { + "type": "array", + "description": "An array of calculated tracking signatures for this tracking item.", + "minItems": 1, + "items": { + "description": "A calculated tracking signature value and metadata.", + "required": ["algorithm", "value"], + "properties": { + "algorithm": { + "type": "string", + "description": "The algorithm used to generate the signature." + }, + "value": { + "type": "string", + "description": "The result of this signature algorithm." + } + } + } + } + } + } + } + } + } + ], + "properties": { + "type": { + "type": "string", + "description": "Each tracking type must declare its own type." + } + } + }, + "flags": { + "description": "Flags that can be attached to vulnerabilities.", + "type": "array", + "items": { + "type": "object", + "description": "Informational flags identified and assigned to a vulnerability.", + "required": ["type", "origin", "description"], + "properties": { + "type": { + "type": "string", + "minLength": 1, + "description": "Result of the scan.", + "enum": ["flagged-as-likely-false-positive"] + }, + "origin": { + "minLength": 1, + "description": "Tool that issued the flag.", + "type": "string" + }, + "description": { + "minLength": 1, + "description": "What the flag is about.", + "type": "string" + } + } + } + }, + "location": { + "type": "object", + "description": "Identifies the vulnerability's location.", + "required": ["file", "dependency"], + "properties": { + "file": { + "type": "string", + "minLength": 1, + "description": "Path to the manifest or lock file where the dependency is declared (such as yarn.lock)." + }, + "dependency": { + "type": "object", + "description": "Describes the dependency of a project where the vulnerability is located.", + "required": ["package", "version"], + "properties": { + "package": { + "type": "object", + "description": "Provides information on the package where the vulnerability is located.", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "description": "Name of the package where the vulnerability is located." + } + } + }, + "version": { + "type": "string", + "description": "Version of the vulnerable package." + }, + "iid": { + "description": "ID that identifies the dependency in the scope of a dependency file.", + "type": "number" + }, + "direct": { + "type": "boolean", + "description": "Tells whether this is a direct, top-level dependency of the scanned project." + }, + "dependency_path": { + "type": "array", + "description": "Ancestors of the dependency, starting from a direct project dependency, and ending with an immediate parent of the dependency. The dependency itself is excluded from the path. Direct dependencies have no path.", + "items": { + "type": "object", + "required": ["iid"], + "properties": { + "iid": { + "type": "number", + "description": "ID that is unique in the scope of a parent object, and specific to the resource type." + } + } + } + } + } + } + } + } + } + } + }, + "remediations": { + "type": "array", + "description": "An array of objects containing information on available remediations, along with patch diffs to apply.", + "items": { + "type": "object", + "required": ["fixes", "summary", "diff"], + "properties": { + "fixes": { + "type": "array", + "description": "An array of strings that represent references to vulnerabilities fixed by this remediation.", + "items": { + "type": "object", + "required": ["id"], + "properties": { + "id": { + "type": "string", + "minLength": 1, + "description": "Unique identifier of the vulnerability. This is recommended to be a UUID.", + "examples": ["642735a5-1425-428d-8d4e-3c854885a3c9"] + } + } + } + }, + "summary": { + "type": "string", + "minLength": 1, + "description": "An overview of how the vulnerabilities were fixed." + }, + "diff": { + "type": "string", + "minLength": 1, + "description": "A base64-encoded remediation code diff, compatible with git apply." + } + } + } + }, + "dependency_files": { + "type": "array", + "description": "List of dependency files identified in the project.", + "items": { + "type": "object", + "required": ["path", "package_manager", "dependencies"], + "properties": { + "path": { + "type": "string", + "minLength": 1 + }, + "package_manager": { + "type": "string", + "minLength": 1 + }, + "dependencies": { + "type": "array", + "items": { + "type": "object", + "description": "Describes the dependency of a project where the vulnerability is located.", + "required": ["package", "version"], + "properties": { + "package": { + "type": "object", + "description": "Provides information on the package where the vulnerability is located.", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "description": "Name of the package where the vulnerability is located." + } + } + }, + "version": { + "type": "string", + "description": "Version of the vulnerable package." + }, + "iid": { + "description": "ID that identifies the dependency in the scope of a dependency file.", + "type": "number" + }, + "direct": { + "type": "boolean", + "description": "Tells whether this is a direct, top-level dependency of the scanned project." + }, + "dependency_path": { + "type": "array", + "description": "Ancestors of the dependency, starting from a direct project dependency, and ending with an immediate parent of the dependency. The dependency itself is excluded from the path. Direct dependencies have no path.", + "items": { + "type": "object", + "required": ["iid"], + "properties": { + "iid": { + "type": "number", + "description": "ID that is unique in the scope of a parent object, and specific to the resource type." + } + } + } + } + } + } + } + } + } + } + } +} diff --git a/test/snapshots/termless/cli.native.socket-help-scan-report.svg b/test/snapshots/termless/cli.native.socket-help-scan-report.svg index 089df3eb3..2b32f89c8 100644 --- a/test/snapshots/termless/cli.native.socket-help-scan-report.svg +++ b/test/snapshots/termless/cli.native.socket-help-scan-report.svg @@ -1,4 +1,4 @@ - + CLI: v2.1.1-rc.0 | cmd: socket scan report | org: (not set) | token: (not set) @@ -25,89 +25,93 @@ Options - --fold Fold reported alerts to some degree (default 'none') + --enable-gitlab-security Write a GitLab Dependency Scanning report - --interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, + --fold Fold reported alerts to some degree (default 'none') - defaulting them to cancel/no. + --gitlab-security-file Output path for the GitLab Dependency Scanning report - --json Output as JSON + --interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, - --license Also report the license policy status. Default: false + defaulting them to cancel/no. - --markdown Output as Markdown + --json Output as JSON - --org Force override the organization slug, overrides the default org from config + --license Also report the license policy status. Default: false - --report-level Which policy level alerts should be reported (default 'warn') + --markdown Output as Markdown - --short Report only the healthy status + --org Force override the organization slug, overrides the default org from config - + --report-level Which policy level alerts should be reported (default 'warn') - When no output path is given the contents is sent to stdout. + --short Report only the healthy status - By default the result is a nested object that looks like this: + When no output path is given the contents is sent to stdout. - `{ + - [ecosystem]: { + By default the result is a nested object that looks like this: - [pkgName]: { + `{ - [version]: { + [ecosystem]: { - [file]: { + [pkgName]: { - [line:col]: alert + [version]: { - }}}}` + [file]: { - So one alert for each occurrence in every file, version, etc, a huge response. + [line:col]: alert - + }}}}` - You can --fold these up to given level: 'pkg', 'version', 'file', and 'none'. + So one alert for each occurrence in every file, version, etc, a huge response. - For example: `socket scan report --fold=version` will dedupe alerts to only + - show one alert of a particular kind, no matter how often it was found in a + You can --fold these up to given level: 'pkg', 'version', 'file', and 'none'. - file or in how many files it was found. At most one per version that has it. + For example: `socket scan report --fold=version` will dedupe alerts to only - + show one alert of a particular kind, no matter how often it was found in a - By default only the warn and error policy level alerts are reported. You can + file or in how many files it was found. At most one per version that has it. - override this and request more ('defer' < 'ignore' < 'monitor' < 'warn' < 'error') - + + By default only the warn and error policy level alerts are reported. You can - Short responses look like this: + override this and request more ('defer' < 'ignore' < 'monitor' < 'warn' < 'error') - --json: `{healthy:bool}` + - --markdown: `healthy = bool` + Short responses look like this: - neither: `OK/ERR` + --json: `{healthy:bool}` - + --markdown: `healthy = bool` - Examples + neither: `OK/ERR` - $ socket scan report 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json --fold=version + - $ socket scan report 000aaaa1-0000-0a0a-00a0-00a0000000a0 --license --markdown --short + Examples - + $ socket scan report 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json --fold=version - + $ socket scan report 000aaaa1-0000-0a0a-00a0-00a0000000a0 --license --markdown --short - \ No newline at end of file + + + + + \ No newline at end of file