Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

### Added
- Scan many repositories with `--dynamic-sbom-inference` without a `socket.json` in each: `--dynamic-sbom-inference-ignore-unresolved` tolerates unresolved dependencies in every build.
- `--dynamic-sbom-inference` no longer waits indefinitely on a hung build: a build root whose build tool runs take longer than 3600 seconds in all fails with a message saying so. Set the limit in seconds (e.g. `1800`) with `--dynamic-sbom-inference-build-timeout` on `socket scan create`, `socket scan reach` and `socket fix`, or `--build-timeout` on `socket manifest dynamic-sbom-inference`, and turn it off with `0`. The timeout needs Coana 15.15.10 or newer.

### Changed
- `--dynamic-sbom-inference` can be passed to every repository: one without a .NET, Gradle, Maven or sbt build is scanned as without the flag instead of failing, and `socket manifest dynamic-sbom-inference` reports that no build root was found and exits successfully.
- `socket scan create` and `socket scan reach` now reject `--ignore-unresolved`, `--exclude-configs`, `--include-configs` and `--verbose` instead of ignoring them, as each could swallow the scan target.

## [1.18.2](https://github.com/SocketDev/socket-cli/releases/tag/v1.18.2) - 2026-12-02

### Changed
Expand Down
11 changes: 11 additions & 0 deletions docs/dynamic-sbom-inference-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ Only reachability scans read the `reachability` fields, each cascading on its
own, and only for the build tools they run. An invalid value or a field the
build tool does not take fails the scan.

## On the command line

Only `ignoreUnresolved` also has a flag that overrides `socket.json`; set the
other fields there.

- `socket scan create`, `socket scan reach` and `socket fix` take
`--dynamic-sbom-inference-ignore-unresolved` with `--dynamic-sbom-inference`;
`socket manifest dynamic-sbom-inference` takes `--ignore-unresolved`.
- It applies to every build and wins over every `socket.json`, a build's own
`builds` entry included. The `--no-` form sets it to `false`.

## Skipping builds

| To skip | Set | Effect |
Expand Down
2 changes: 2 additions & 0 deletions src/commands/fix/cmd-fix.integration.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ describe('socket fix', async () => {
--debug Enable debug logging in the Coana-based Socket Fix CLI invocation.
--disable-external-tool-checks Disable external tool checks during fix analysis.
--dynamic-sbom-inference For Gradle, sbt, Maven and .NET: generate a Socket facts SBOM (produced directly by each package manager) per independent build root, instead of one synthetic root. Fixes are then attributed to the projects/modules that actually resolve each vulnerable dependency. The generated files are removed afterwards.
--dynamic-sbom-inference-build-timeout With --dynamic-sbom-inference: set the timeout for each build root's build tool runs, taken together, as a whole number of seconds (e.g. 1800), optionally followed by s, m or h. A root that runs past it fails, and 0 means no timeout. Defaults to 3600.
--dynamic-sbom-inference-ecosystems With --dynamic-sbom-inference: generate Socket facts only for these ecosystems, as either a comma separated value or as multiple flags; the others keep their manifest files as they are. Supported: maven (Gradle, Maven, and sbt) and nuget (.NET). Defaults to all of them.
--dynamic-sbom-inference-ignore-unresolved With --dynamic-sbom-inference: warn on unresolved dependencies instead of failing the build (unresolved deps are not emitted to the facts files); overrides each build's socket.json setting.
--ecosystems Limit fix analysis to specific ecosystems. Accepts space- or comma-separated values and is case-insensitive. Defaults to all ecosystems.
--exclude-paths Skip matching paths from the scan entirely: manifests under these paths are not uploaded, and fixes are not applied to workspaces under them. Patterns are anchored micromatch globs matched relative to the target directory (CWD); \`data/postgres/pgdata\` matches that exact path, \`**/pgdata\` matches at any depth. Use this to skip directories the current user cannot read so they do not abort manifest collection. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags.
--fix-version Override the version of @coana-tech/cli used for fix analysis. Default: <coana-version>.
Expand Down
4 changes: 2 additions & 2 deletions src/commands/fix/cmd-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { getDefaultOrgSlug } from '../ci/fetch-default-org-slug.mts'
import { assertValidExcludePaths } from '../scan/exclude-paths.mts'
import {
DYNAMIC_SBOM_INFERENCE_DESCRIPTION,
dynamicSbomInferenceEcosystemsFlags,
dynamicSbomInferenceFlags,
parseDynamicSbomInferenceFlags,
} from '../scan/reachability-flags.mts'

Expand Down Expand Up @@ -191,7 +191,7 @@ Available styles:
default: false,
description: `${DYNAMIC_SBOM_INFERENCE_DESCRIPTION} Fixes are then attributed to the projects/modules that actually resolve each vulnerable dependency. The generated files are removed afterwards.`,
},
...dynamicSbomInferenceEcosystemsFlags,
...dynamicSbomInferenceFlags,
ecosystems: {
type: 'string',
default: [],
Expand Down
30 changes: 28 additions & 2 deletions src/commands/fix/coana-fix-dynamic-sbom-inference.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { promises as fs } from 'node:fs'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { coanaFix } from './coana-fix.mts'
import {
BUILD_TIMEOUT,
makeDynamicSbomInference,
} from '../../../test/reachability-options.mts'
import { logger } from '../../utils/logger.mts'

import type { FixConfig } from './types.mts'
Expand Down Expand Up @@ -101,7 +105,10 @@ describe('socket fix --dynamic-sbom-inference', () => {
debug: false,
disableExternalToolChecks: false,
disableMajorUpdates: false,
dynamicSbomInference: ['maven'],
dynamicSbomInference: makeDynamicSbomInference({
buildTimeout: BUILD_TIMEOUT,
purlTypes: ['maven'],
}),
ecosystems: [],
exclude: [],
excludePaths: [],
Expand Down Expand Up @@ -147,7 +154,10 @@ describe('socket fix --dynamic-sbom-inference', () => {

expect(result.ok).toBe(true)
expect(mockGenerateSocketFactsForFix).toHaveBeenCalledWith(
expect.objectContaining({ purlTypes: ['maven'] }),
expect.objectContaining({
buildTimeout: BUILD_TIMEOUT,
purlTypes: ['maven'],
}),
)
expect(uploadManifestFiles).toHaveBeenCalledWith(
'test-org',
Expand All @@ -163,6 +173,22 @@ describe('socket fix --dynamic-sbom-inference', () => {
expect(generated.remove).toHaveBeenCalledTimes(1)
})

it('runs Coana as without the flag when no build root was found', async () => {
mockGenerateSocketFactsForFix.mockResolvedValue(undefined)

const result = await coanaFix(baseConfig)

expect(result.ok).toBe(true)
const args = coanaCalls('compute-fixes-and-upgrade-purls')[0]!
expect(args).not.toContain('--use-only-socket-facts-artifacts')
expect(args).not.toContain('--socket-facts-sidecar')
expect(uploadManifestFiles).toHaveBeenCalledWith(
'test-org',
['/test/cwd/app/build.gradle'],
{ pathsRelativeTo: '/test/cwd' },
)
})

it('discovers vulnerabilities only through the generated facts', async () => {
mockSpawnCoana.mockImplementation(async (args: string[]) => {
if (args[0] === 'find-vulnerabilities') {
Expand Down
29 changes: 16 additions & 13 deletions src/commands/fix/coana-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ import { withoutDiscardedFacts } from '../scan/run-dynamic-sbom-inference.mts'
import type { GeneratedSocketFacts } from './generated-socket-facts.mts'
import type { FixConfig } from './types.mts'
import type { CResult } from '../../types.mts'
import type { FactsOnlyTypes } from '../../utils/coana.mts'
import type { PURL_Type } from '../../utils/ecosystem.mts'
import type { Spinner } from '../../utils/spinner.mts'
import type { DynamicSbomInference } from '../scan/reachability-flags.mts'

type DiscoverGhsaIdsOptions = {
coanaVersion?: string | undefined
Expand Down Expand Up @@ -283,18 +283,18 @@ function formatNotAppliedFixes(notApplied: NotAppliedFix[]): string {
}

type GeneratedSocketFactsSlot = {
dynamicSbomInference: DynamicSbomInference
generated?: GeneratedSocketFacts | undefined
purlTypes: FactsOnlyTypes
tmpDir: string
}

export async function coanaFix(fixConfig: FixConfig): Promise<CoanaFixResult> {
const purlTypes = fixConfig.dynamicSbomInference
if (!purlTypes) {
const { dynamicSbomInference } = fixConfig
if (!dynamicSbomInference) {
return await coanaFixWithFacts(fixConfig, undefined)
}
return await withTmpDir('socket-fix-facts-', async tmpDir => {
const slot: GeneratedSocketFactsSlot = { purlTypes, tmpDir }
const slot: GeneratedSocketFactsSlot = { dynamicSbomInference, tmpDir }
try {
return await coanaFixWithFacts(fixConfig, slot)
} finally {
Expand Down Expand Up @@ -396,21 +396,24 @@ async function coanaFixWithFacts(
spinner?.stop()
logger.info('Generating Socket facts for each build ...')
}
factsSlot.generated = await generateSocketFactsForFix({
const generated = await generateSocketFactsForFix({
context: { coanaVersion, orgSlug },
cwd,
excludePaths,
purlTypes: factsSlot.purlTypes,
...factsSlot.dynamicSbomInference,
findFactsPaths: async () =>
(await findScanFilepaths()).filter(isSocketFactsFile),
tmpDir: factsSlot.tmpDir,
})
scanFilepaths = await withoutDiscardedFacts(
scanFilepaths,
factsSlot.generated.discardedPaths,
)
const known = new Set(scanFilepaths)
scanFilepaths.push(...factsSlot.generated.paths.filter(p => !known.has(p)))
factsSlot.generated = generated
if (generated) {
scanFilepaths = await withoutDiscardedFacts(
scanFilepaths,
generated.discardedPaths,
)
const known = new Set(scanFilepaths)
scanFilepaths.push(...generated.paths.filter(p => !known.has(p)))
}
if (!silence) {
spinner?.start()
}
Expand Down
17 changes: 12 additions & 5 deletions src/commands/fix/generated-socket-facts.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
import { runDynamicSbomInference } from '../scan/run-dynamic-sbom-inference.mts'

import type { FactsOnlyTypes } from '../../utils/coana.mts'
import type { PURL_Type } from '../../utils/ecosystem.mts'
import type { SocketFactsContext } from '../manifest/run-manifest-facts.mts'
import type { DynamicSbomInference } from '../scan/reachability-flags.mts'

export type GeneratedSocketFacts = {
// Facts files of dropped runs, which Coana must not read.
Expand Down Expand Up @@ -45,22 +45,24 @@ async function restoreAll(backups: Backup[]): Promise<void> {
}

// Backed up so each fix attempt sees the pre-fix build after `git clean`, and
// facts files already present are left as they were found.
// facts files already present are left as they were found. Undefined when no
// build root was discovered, so the fix runs as without facts.
export async function generateSocketFactsForFix({
buildTimeout,
context,
cwd,
excludePaths,
findFactsPaths,
ignoreUnresolved,
purlTypes,
tmpDir,
}: {
}: DynamicSbomInference & {
context: Omit<SocketFactsContext, 'workDir'>
cwd: string
excludePaths: string[]
findFactsPaths: () => Promise<string[]>
purlTypes: readonly PURL_Type[]
tmpDir: string
}): Promise<GeneratedSocketFacts> {
}): Promise<GeneratedSocketFacts | undefined> {
const existingPaths = await findFactsPaths()
const originals = await backUp(existingPaths, path.join(tmpDir, 'existing'))
const existing = new Set(existingPaths)
Expand All @@ -80,12 +82,17 @@ export async function generateSocketFactsForFix({
)
try {
const inferred = await runDynamicSbomInference({
buildTimeout,
context: { ...context, workDir },
cwd,
excludePaths,
hints: EXCLUDE_PATHS_HINTS,
ignoreUnresolved,
purlTypes,
})
if (!inferred.factsOnlyTypes) {
return undefined
}
discardedPaths = inferred.discardedFactsPaths
factsOnlyTypes = inferred.factsOnlyTypes
paths = inferred.factsPaths.map(p => path.resolve(cwd, p))
Expand Down
28 changes: 24 additions & 4 deletions src/commands/fix/generated-socket-facts.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import { generateSocketFactsForFix } from './generated-socket-facts.mts'
import { makeDynamicSbomInference } from '../../../test/reachability-options.mts'

const mockRunDynamicSbomInference = vi.hoisted(() => vi.fn())

Expand Down Expand Up @@ -32,17 +33,25 @@ describe('generateSocketFactsForFix', () => {
await fs.rm(tmpDir, { force: true, recursive: true })
})

async function generate() {
return await generateSocketFactsForFix({
function generateOrNone() {
return generateSocketFactsForFix({
context: { coanaVersion: '1.2.3', orgSlug: 'acme' },
cwd,
excludePaths: [],
findFactsPaths: async () => [existing, fresh].filter(p => existsSync(p)),
purlTypes: ['maven'],
...makeDynamicSbomInference({ purlTypes: ['maven'] }),
tmpDir,
})
}

async function generate() {
const generated = await generateOrNone()
if (!generated) {
throw new Error('Expected generated facts.')
}
return generated
}

it('restores the generated facts per attempt and the original facts afterwards', async () => {
mockRunDynamicSbomInference.mockImplementation(async () => {
await fs.writeFile(existing, 'regenerated')
Expand Down Expand Up @@ -96,7 +105,7 @@ describe('generateSocketFactsForFix', () => {
purpose: 'fix',
},
},
purlTypes: ['maven'],
...makeDynamicSbomInference({ purlTypes: ['maven'] }),
}),
)
expect(factsOnlyTypes).toEqual(['maven', 'nuget'])
Expand All @@ -117,6 +126,17 @@ describe('generateSocketFactsForFix', () => {
expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual([])
})

it('generates nothing when no build root was discovered', async () => {
mockRunDynamicSbomInference.mockResolvedValue({
discardedFactsPaths: [],
factsOnlyTypes: undefined,
factsPaths: [],
})

expect(await generateOrNone()).toBeUndefined()
expect(await fs.readFile(existing, 'utf8')).toBe('original')
})

it('restores an existing facts file that generation does not rewrite', async () => {
mockRunDynamicSbomInference.mockImplementation(async () => {
await fs.writeFile(fresh, 'generated')
Expand Down
6 changes: 3 additions & 3 deletions src/commands/fix/types.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FactsOnlyTypes } from '../../utils/coana.mts'
import type { PURL_Type } from '../../utils/ecosystem.mts'
import type { RangeStyle } from '../../utils/semver.mts'
import type { Spinner } from '../../utils/spinner.mts'
import type { DynamicSbomInference } from '../scan/reachability-flags.mts'

export type FixConfig = {
all: boolean
Expand All @@ -13,8 +13,8 @@ export type FixConfig = {
debug: boolean
disableExternalToolChecks: boolean
disableMajorUpdates: boolean
// The ecosystems to generate Socket facts for; undefined when off.
dynamicSbomInference: FactsOnlyTypes | undefined
// Undefined when off.
dynamicSbomInference: DynamicSbomInference | undefined
ecosystems: PURL_Type[]
exclude: string[]
excludePaths: string[]
Expand Down
8 changes: 8 additions & 0 deletions src/commands/manifest/cmd-manifest-dynamic-sbom-inference.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { logger } from '../../utils/logger.mts'
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
import { getFlagListOutput } from '../../utils/output-formatting.mts'
import { assertValidExcludePaths } from '../scan/exclude-paths.mts'
import {
MANIFEST_BUILD_TIMEOUT_KEY,
buildTimeoutFlags,
parseBuildTimeout,
} from '../scan/reachability-flags.mts'

import type {
CliCommandConfig,
Expand All @@ -26,6 +31,7 @@ const config: CliCommandConfig = {
...commonFlags,
...outputFlags,
...excludePathsFlag,
...buildTimeoutFlags(MANIFEST_BUILD_TIMEOUT_KEY),
ignoreUnresolved: {
type: 'boolean',
description:
Expand Down Expand Up @@ -131,13 +137,15 @@ async function run(

const excludePaths = cmdFlagValueToArray(cli.flags['excludePaths'])
assertValidExcludePaths(excludePaths)
const buildTimeout = parseBuildTimeout(cli.flags, MANIFEST_BUILD_TIMEOUT_KEY)

if (dryRun) {
logger.log(constants.DRY_RUN_BAILING_NOW)
return
}

await handleManifestDynamicSbomInference({
buildTimeout,
cwd,
excludePaths,
ignoreUnresolved,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('socket manifest dynamic-sbom-inference', async () => {
CWD itself.

Options
--build-timeout Set the timeout for each build root's build tool runs, taken together, as a whole number of seconds (e.g. 1800), optionally followed by s, m or h. A root that runs past it fails, and 0 means no timeout. Defaults to 3600.
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module or .NET project is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project. A build module or project outside CWD cannot be excluded.
--ignore-unresolved Warn on unresolved dependencies instead of failing the run (unresolved deps are not emitted to the facts files); overrides each build's socket.json setting
--json Output as JSON
Expand Down
Loading
Loading