Skip to content

Commit da83fa1

Browse files
authored
add --all flag for socket fix and make it incompatible with --id (#967)
implicitly use `--all` if no `--id` but warn that this is deprecated in local mode
1 parent 361afe8 commit da83fa1

File tree

8 files changed

+97
-10
lines changed

8 files changed

+97
-10
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ 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/).
66

7+
## [1.1.43](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.43) - 2025-12-08
8+
9+
### Added
10+
- Added `--all` flag to `socket fix` for explicitly processing all vulnerabilities in local mode. Cannot be used with `--id`.
11+
12+
### Deprecated
13+
- Running `socket fix` in local mode without `--all` or `--id` is deprecated. A warning is shown when neither flag is provided. In a future release, one of these flags will be required.
14+
715
## [1.1.42](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.42) - 2025-12-04
816

917
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "1.1.42",
3+
"version": "1.1.43",
44
"description": "CLI for Socket.dev",
55
"homepage": "https://github.com/SocketDev/socket-cli",
66
"license": "MIT AND OFL-1.1",

src/commands/fix/cmd-fix.integration.test.mts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ describe('socket fix', async () => {
164164
- Permissions: full-scans:create and packages:list
165165
166166
Options
167+
--all Process all discovered vulnerabilities in local mode. Cannot be used with --id.
167168
--autopilot Enable auto-merge for pull requests that Socket opens.
168169
See GitHub documentation (https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-auto-merge-for-pull-requests-in-your-repository) for managing auto-merge for pull requests in your repository.
169170
--ecosystems Limit fix analysis to specific ecosystems. Can be provided as comma separated values or as multiple flags. Defaults to all ecosystems.
@@ -173,7 +174,7 @@ describe('socket fix', async () => {
173174
- GHSA IDs (https://docs.github.com/en/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/about-the-github-advisory-database#about-ghsa-ids) (e.g., GHSA-xxxx-xxxx-xxxx)
174175
- CVE IDs (https://cve.mitre.org/cve/identifiers/) (e.g., CVE-2025-1234) - automatically converted to GHSA
175176
- PURLs (https://github.com/package-url/purl-spec) (e.g., pkg:npm/[email protected]) - automatically converted to GHSA
176-
Can be provided as comma separated values or as multiple flags
177+
Can be provided as comma separated values or as multiple flags. Cannot be used with --all.
177178
--include Include workspaces matching these glob patterns. Can be provided as comma separated values or as multiple flags
178179
--json Output as JSON
179180
--markdown Output as Markdown
@@ -1127,6 +1128,55 @@ describe('socket fix', async () => {
11271128
)
11281129
})
11291130

1131+
describe('--all flag behavior', () => {
1132+
cmdit(
1133+
['fix', FLAG_DRY_RUN, '--all', FLAG_CONFIG, '{"apiToken":"fakeToken"}'],
1134+
'should accept --all flag',
1135+
async cmd => {
1136+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
1137+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Not saving"`)
1138+
expect(code, 'should exit with code 0').toBe(0)
1139+
},
1140+
)
1141+
1142+
cmdit(
1143+
[
1144+
'fix',
1145+
FLAG_DRY_RUN,
1146+
'--all',
1147+
FLAG_ID,
1148+
'GHSA-1234-5678-9abc',
1149+
FLAG_CONFIG,
1150+
'{"apiToken":"fakeToken"}',
1151+
],
1152+
'should fail when --all and --id are used together',
1153+
async cmd => {
1154+
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
1155+
const output = stdout + stderr
1156+
expect(output).toContain('--all and --id flags cannot be used together')
1157+
expect(code, 'should exit with non-zero code').not.toBe(0)
1158+
},
1159+
)
1160+
1161+
cmdit(
1162+
[
1163+
'fix',
1164+
FLAG_DRY_RUN,
1165+
'--all',
1166+
'--ecosystems',
1167+
'npm',
1168+
FLAG_CONFIG,
1169+
'{"apiToken":"fakeToken"}',
1170+
],
1171+
'should accept --all with --ecosystems',
1172+
async cmd => {
1173+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
1174+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Not saving"`)
1175+
expect(code, 'should exit with code 0').toBe(0)
1176+
},
1177+
)
1178+
})
1179+
11301180
describe('--id flag behavior', () => {
11311181
cmdit(
11321182
[

src/commands/fix/cmd-fix.mts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ const generalFlags: MeowFlags = {
9595
// Hidden to allow custom documenting of the negated `--no-major-updates` variant.
9696
hidden: true,
9797
},
98+
all: {
99+
type: 'boolean',
100+
default: false,
101+
description:
102+
'Process all discovered vulnerabilities in local mode. Cannot be used with --id.',
103+
},
98104
id: {
99105
type: 'string',
100106
default: [],
@@ -111,7 +117,7 @@ const generalFlags: MeowFlags = {
111117
'PURLs',
112118
'https://github.com/package-url/purl-spec',
113119
)} (e.g., pkg:npm/[email protected]) - automatically converted to GHSA
114-
Can be provided as comma separated values or as multiple flags`,
120+
Can be provided as comma separated values or as multiple flags. Cannot be used with --all.`,
115121
isMultiple: true,
116122
},
117123
prLimit: {
@@ -272,6 +278,7 @@ async function run(
272278
)
273279

274280
const {
281+
all,
275282
applyFixes,
276283
autopilot,
277284
ecosystems,
@@ -292,6 +299,7 @@ async function run(
292299
// socket-cli/patches/meow#13.2.0.patch.
293300
unknownFlags = [],
294301
} = cli.flags as {
302+
all: boolean
295303
applyFixes: boolean
296304
autopilot: boolean
297305
ecosystems: string[]
@@ -338,6 +346,13 @@ async function run(
338346
validatedEcosystems.push(ecosystem as PURL_Type)
339347
}
340348

349+
// Collect ghsas early to validate --all and --id mutual exclusivity.
350+
const ghsas = arrayUnique([
351+
...cmdFlagValueToArray(cli.flags['id']),
352+
...cmdFlagValueToArray(cli.flags['ghsa']),
353+
...cmdFlagValueToArray(cli.flags['purl']),
354+
])
355+
341356
const wasValidInput = checkCommandInput(
342357
outputKind,
343358
{
@@ -351,6 +366,12 @@ async function run(
351366
message: 'The json and markdown flags cannot be both set, pick one',
352367
fail: 'omit one',
353368
},
369+
{
370+
nook: true,
371+
test: !all || !ghsas.length,
372+
message: 'The --all and --id flags cannot be used together',
373+
fail: 'omit one',
374+
},
354375
)
355376
if (!wasValidInput) {
356377
return
@@ -379,16 +400,11 @@ async function run(
379400

380401
const { spinner } = constants
381402

382-
const ghsas = arrayUnique([
383-
...cmdFlagValueToArray(cli.flags['id']),
384-
...cmdFlagValueToArray(cli.flags['ghsa']),
385-
...cmdFlagValueToArray(cli.flags['purl']),
386-
])
387-
388403
const includePatterns = cmdFlagValueToArray(include)
389404
const excludePatterns = cmdFlagValueToArray(exclude)
390405

391406
await handleFix({
407+
all,
392408
applyFixes,
393409
autopilot,
394410
coanaVersion: fixVersion,

src/commands/fix/coana-fix.mts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export async function coanaFix(
107107
fixConfig: FixConfig,
108108
): Promise<CResult<{ data?: unknown; fixed: boolean }>> {
109109
const {
110+
all,
110111
applyFixes,
111112
autopilot,
112113
coanaVersion,
@@ -173,11 +174,18 @@ export async function coanaFix(
173174
}
174175
}
175176

176-
const shouldDiscoverGhsaIds = !ghsas.length
177+
const shouldDiscoverGhsaIds = all || !ghsas.length
177178

178179
const shouldOpenPrs = fixEnv.isCi && fixEnv.repoInfo
179180

180181
if (!shouldOpenPrs) {
182+
// In local mode, if neither --all nor --id is provided, show deprecation warning.
183+
if (shouldDiscoverGhsaIds && !all) {
184+
logger.warn(
185+
'Implicit --all is deprecated in local mode and will be removed in a future release. Please use --all explicitly.',
186+
)
187+
}
188+
181189
// Inform user about local mode when fixes will be applied.
182190
if (applyFixes && ghsas.length) {
183191
const envCheck = checkCiEnvVars()

src/commands/fix/handle-fix-limit.test.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ vi.mock('./branch-cleanup.mts', () => ({
7272

7373
describe('socket fix --pr-limit behavior verification', () => {
7474
const baseConfig: FixConfig = {
75+
all: false,
7576
applyFixes: true,
7677
autopilot: false,
7778
coanaVersion: undefined,

src/commands/fix/handle-fix.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export async function convertIdsToGhsas(ids: string[]): Promise<string[]> {
9797
}
9898

9999
export async function handleFix({
100+
all,
100101
applyFixes,
101102
autopilot,
102103
coanaVersion,
@@ -120,6 +121,7 @@ export async function handleFix({
120121
}: HandleFixConfig) {
121122
debugFn('notice', `Starting fix command for ${orgSlug}`)
122123
debugDir('inspect', {
124+
all,
123125
applyFixes,
124126
autopilot,
125127
coanaVersion,
@@ -142,6 +144,7 @@ export async function handleFix({
142144

143145
await outputFixResult(
144146
await coanaFix({
147+
all,
145148
applyFixes,
146149
autopilot,
147150
coanaVersion,

src/commands/fix/types.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { RangeStyle } from '../../utils/semver.mts'
33
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
44

55
export type FixConfig = {
6+
all: boolean
67
applyFixes: boolean
78
autopilot: boolean
89
coanaVersion: string | undefined

0 commit comments

Comments
 (0)