Skip to content

Commit b29c1f3

Browse files
authored
Add flag --reach-use-only-pregenerated-sboms (#969)
* add flag --reach-use-only-pregenerated-sboms * prepare for 1.1.45 * update @coana-tech/cli to 14.12.122
1 parent 903cc00 commit b29c1f3

12 files changed

+88
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6+
7+
## [1.1.45](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.43) - 2025-12-10
8+
9+
### Changed
10+
- Updated the Coana CLI to v `14.12.122`.
11+
12+
### Added
13+
- Added `--reach-use-only-pregenerated-sboms` to run the Tier 1 reachability based only on pre-computed CDX and SPDX SBOMs (all other manifests are excluded).
14+
615
## [1.1.44](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.43) - 2025-12-09
716

817
### Changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "1.1.44",
3+
"version": "1.1.45",
44
"description": "CLI for Socket.dev",
55
"homepage": "https://github.com/SocketDev/socket-cli",
66
"license": "MIT AND OFL-1.1",
@@ -94,7 +94,7 @@
9494
"@babel/preset-typescript": "7.27.1",
9595
"@babel/runtime": "7.28.4",
9696
"@biomejs/biome": "2.2.4",
97-
"@coana-tech/cli": "14.12.118",
97+
"@coana-tech/cli": "14.12.122",
9898
"@cyclonedx/cdxgen": "11.11.0",
9999
"@dotenvx/dotenvx": "1.49.0",
100100
"@eslint/compat": "1.3.2",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/ci/handle-ci.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export async function handleCi(autoManifest: boolean): Promise<void> {
6060
reachEcosystems: [],
6161
reachExcludePaths: [],
6262
reachSkipCache: false,
63+
reachUseOnlyPregeneratedSboms: false,
6364
reachVersion: undefined,
6465
runReachabilityAnalysis: false,
6566
},

src/commands/scan/cmd-scan-create.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ async function run(
244244
reachDisableAnalysisSplitting,
245245
reachDisableAnalytics,
246246
reachSkipCache,
247+
reachUseOnlyPregeneratedSboms,
247248
reachVersion,
248249
readOnly,
249250
reportLevel,
@@ -273,6 +274,7 @@ async function run(
273274
reachDisableAnalysisSplitting: boolean
274275
reachDisableAnalytics: boolean
275276
reachSkipCache: boolean
277+
reachUseOnlyPregeneratedSboms: boolean
276278
reachVersion: string | undefined
277279
}
278280

@@ -458,7 +460,8 @@ async function run(
458460
isUsingNonDefaultTimeout ||
459461
isUsingNonDefaultVersion ||
460462
reachDisableAnalysisSplitting ||
461-
reachSkipCache
463+
reachSkipCache ||
464+
reachUseOnlyPregeneratedSboms
462465

463466
// Validate target constraints when --reach is enabled.
464467
const reachTargetValidation = reach
@@ -573,6 +576,7 @@ async function run(
573576
reachEcosystems,
574577
reachExcludePaths,
575578
reachSkipCache: Boolean(reachSkipCache),
579+
reachUseOnlyPregeneratedSboms: Boolean(reachUseOnlyPregeneratedSboms),
576580
reachVersion,
577581
runReachabilityAnalysis: Boolean(reach),
578582
},

src/commands/scan/cmd-scan-create.test.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('socket scan create', async () => {
6363
--reach-ecosystems List of ecosystems to conduct reachability analysis on, as either a comma separated value or as multiple flags. Defaults to all ecosystems.
6464
--reach-exclude-paths List of paths to exclude from reachability analysis, as either a comma separated value or as multiple flags.
6565
--reach-skip-cache Skip caching-based optimizations. By default, the reachability analysis will use cached configurations from previous runs to speed up the analysis.
66+
--reach-use-only-pregenerated-sboms When using this option, the scan is created based only on pre-generated CDX and SPDX files in your project.
6667
--reach-version Override the version of @coana-tech/cli used for reachability analysis. Default: <coana-version>.
6768
6869
Uploads the specified dependency manifest files for Go, Gradle, JavaScript,

src/commands/scan/cmd-scan-reach.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ async function run(
128128
reachDisableAnalysisSplitting,
129129
reachDisableAnalytics,
130130
reachSkipCache,
131+
reachUseOnlyPregeneratedSboms,
131132
reachVersion,
132133
} = cli.flags as {
133134
cwd: string
@@ -143,6 +144,7 @@ async function run(
143144
reachDisableAnalysisSplitting: boolean
144145
reachDisableAnalytics: boolean
145146
reachSkipCache: boolean
147+
reachUseOnlyPregeneratedSboms: boolean
146148
reachVersion: string | undefined
147149
}
148150

@@ -263,6 +265,7 @@ async function run(
263265
reachEcosystems,
264266
reachExcludePaths,
265267
reachSkipCache: Boolean(reachSkipCache),
268+
reachUseOnlyPregeneratedSboms: Boolean(reachUseOnlyPregeneratedSboms),
266269
reachVersion,
267270
},
268271
targets,

src/commands/scan/cmd-scan-reach.test.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('socket scan reach', async () => {
4646
--reach-ecosystems List of ecosystems to conduct reachability analysis on, as either a comma separated value or as multiple flags. Defaults to all ecosystems.
4747
--reach-exclude-paths List of paths to exclude from reachability analysis, as either a comma separated value or as multiple flags.
4848
--reach-skip-cache Skip caching-based optimizations. By default, the reachability analysis will use cached configurations from previous runs to speed up the analysis.
49+
--reach-use-only-pregenerated-sboms When using this option, the scan is created based only on pre-generated CDX and SPDX files in your project.
4950
--reach-version Override the version of @coana-tech/cli used for reachability analysis. Default: <coana-version>.
5051
5152
Runs the Socket reachability analysis without creating a scan in Socket.

src/commands/scan/create-scan-from-github.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ async function scanOneRepo(
258258
reachEcosystems: [],
259259
reachExcludePaths: [],
260260
reachSkipCache: false,
261+
reachUseOnlyPregeneratedSboms: false,
261262
reachVersion: undefined,
262263
runReachabilityAnalysis: false,
263264
},

src/commands/scan/handle-create-new-scan.mts

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import path from 'node:path'
22

3+
import micromatch from 'micromatch'
4+
35
import { debugDir, debugFn } from '@socketsecurity/registry/lib/debug'
46
import { logger } from '@socketsecurity/registry/lib/logger'
57
import { pluralize } from '@socketsecurity/registry/lib/words'
@@ -22,6 +24,41 @@ import type { ReachabilityOptions } from './perform-reachability-analysis.mts'
2224
import type { REPORT_LEVEL } from './types.mts'
2325
import type { OutputKind } from '../../types.mts'
2426
import type { Remap } from '@socketsecurity/registry/lib/objects'
27+
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
28+
29+
// Keys for CDX and SPDX in the supported files response.
30+
const CDX_SPDX_KEYS = ['cdx', 'spdx']
31+
32+
function getCdxSpdxPatterns(
33+
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
34+
): string[] {
35+
const patterns: string[] = []
36+
for (const key of CDX_SPDX_KEYS) {
37+
const supported = supportedFiles[key]
38+
if (supported) {
39+
for (const entry of Object.values(supported)) {
40+
patterns.push(`**/${entry.pattern}`)
41+
}
42+
}
43+
}
44+
return patterns
45+
}
46+
47+
function filterToCdxSpdxAndFactsFiles(
48+
filepaths: string[],
49+
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
50+
): string[] {
51+
const patterns = getCdxSpdxPatterns(supportedFiles)
52+
return filepaths.filter(filepath => {
53+
const basename = path.basename(filepath).toLowerCase()
54+
// Include .socket.facts.json files.
55+
if (basename === constants.DOT_SOCKET_DOT_FACTS_JSON) {
56+
return true
57+
}
58+
// Include CDX and SPDX files.
59+
return micromatch.some(filepath, patterns)
60+
})
61+
}
2562

2663
export type HandleCreateNewScanConfig = {
2764
autoManifest: boolean
@@ -187,14 +224,20 @@ export async function handleCreateNewScan({
187224

188225
const reachabilityReport = reachResult.data?.reachabilityReport
189226

227+
// Ensure the .socket.facts.json isn't duplicated in case it happened
228+
// to be in the scan folder before the analysis was run.
229+
const filteredPackagePaths = packagePaths.filter(
230+
p =>
231+
path.basename(p).toLowerCase() !== constants.DOT_SOCKET_DOT_FACTS_JSON,
232+
)
233+
234+
// When using pregenerated SBOMs only, filter to CDX/SPDX files.
235+
const pathsForScan = reach.reachUseOnlyPregeneratedSboms
236+
? filterToCdxSpdxAndFactsFiles(filteredPackagePaths, supportedFiles)
237+
: filteredPackagePaths
238+
190239
scanPaths = [
191-
...packagePaths.filter(
192-
// Ensure the .socket.facts.json isn't duplicated in case it happened
193-
// to be in the scan folder before the analysis was run.
194-
p =>
195-
path.basename(p).toLowerCase() !==
196-
constants.DOT_SOCKET_DOT_FACTS_JSON,
197-
),
240+
...pathsForScan,
198241
...(reachabilityReport ? [reachabilityReport] : []),
199242
]
200243

0 commit comments

Comments
 (0)