Skip to content

Commit 338056b

Browse files
barslevjdalton
andauthored
Barslev/add min release age option to socket fix (#744)
* Add --minimum-release-age to socket fix * Use SOCKET_CLI_COANA_LOCAL_PATH to run using local Coana version * Update description of --minumum-release-age * Update description for --minimum-release-age --------- Signed-off-by: Benjamin Barslev Nielsen <barslev@socket.dev> Signed-off-by: John-David Dalton <jdalton@users.noreply.github.com> Co-authored-by: John-David Dalton <jdalton@users.noreply.github.com>
1 parent 1ec2e86 commit 338056b

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

src/commands/fix/cmd-fix.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ Available styles:
100100
default: '',
101101
description: 'Path to store upgrades as a JSON file at this path.',
102102
},
103+
minimumReleaseAge: {
104+
type: 'string',
105+
default: '',
106+
description:
107+
'Set a minimum age requirement for suggested upgrade versions (e.g., 1h, 2d, 3w). A higher age requirement reduces the risk of upgrading to malicious versions. For example, setting the value to 1 week (1w) gives ecosystem maintainers one week to remove potentially malicious versions.',
108+
},
103109
}
104110

105111
const hiddenFlags: MeowFlags = {
@@ -224,6 +230,7 @@ async function run(
224230
limit,
225231
markdown,
226232
maxSatisfying,
233+
minimumReleaseAge,
227234
outputFile,
228235
prCheck,
229236
rangeStyle,
@@ -243,6 +250,7 @@ async function run(
243250
rangeStyle: RangeStyle
244251
unknownFlags?: string[]
245252
outputFile: string
253+
minimumReleaseAge: string
246254
}
247255

248256
const dryRun = !!cli.flags['dryRun']
@@ -306,6 +314,7 @@ async function run(
306314
ghsas,
307315
glob,
308316
limit,
317+
minimumReleaseAge,
309318
minSatisfying,
310319
prCheck,
311320
orgSlug,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ describe('socket fix', async () => {
180180
--json Output as JSON
181181
--limit The number of fixes to attempt at a time (default 10)
182182
--markdown Output as Markdown
183+
--minimum-release-age Set a minimum age requirement for suggested upgrade versions (e.g., 1h, 2d, 3w). A higher age requirement reduces the risk of upgrading to malicious versions. For example, setting the value to 1 week (1w) gives ecosystem maintainers one week to remove potentially malicious versions.
183184
--no-apply-fixes Compute fixes only, do not apply them. Logs what upgrades would be applied. If combined with --output-file, the output file will contain the upgrades that would be applied.
184185
--output-file Path to store upgrades as a JSON file at this path.
185186
--range-style Define how dependency version ranges are updated in package.json (default 'preserve').

src/commands/fix/coana-fix.mts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export async function coanaFix(
4949
ghsas,
5050
glob,
5151
limit,
52+
minimumReleaseAge,
5253
orgSlug,
5354
outputFile,
5455
spinner,
@@ -142,6 +143,9 @@ export async function coanaFix(
142143
...(fixConfig.rangeStyle
143144
? ['--range-style', fixConfig.rangeStyle]
144145
: []),
146+
...(minimumReleaseAge
147+
? ['--minimum-release-age', minimumReleaseAge]
148+
: []),
145149
...(glob ? ['--glob', glob] : []),
146150
...(!applyFixes ? [FLAG_DRY_RUN] : []),
147151
...(outputFile ? ['--output-file', outputFile] : []),
@@ -194,6 +198,9 @@ export async function coanaFix(
194198
...(fixConfig.rangeStyle
195199
? ['--range-style', fixConfig.rangeStyle]
196200
: []),
201+
...(minimumReleaseAge
202+
? ['--minimum-release-age', minimumReleaseAge]
203+
: []),
197204
...(glob ? ['--glob', glob] : []),
198205
...fixConfig.unknownFlags,
199206
],
@@ -251,6 +258,9 @@ export async function coanaFix(
251258
...(fixConfig.rangeStyle
252259
? ['--range-style', fixConfig.rangeStyle]
253260
: []),
261+
...(minimumReleaseAge
262+
? ['--minimum-release-age', minimumReleaseAge]
263+
: []),
254264
...(glob ? ['--glob', glob] : []),
255265
...fixConfig.unknownFlags,
256266
],

src/commands/fix/handle-fix.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type HandleFixConfig = Remap<
2323
outputKind: OutputKind
2424
unknownFlags: string[]
2525
outputFile: string
26+
minimumReleaseAge: string
2627
}
2728
>
2829

@@ -105,6 +106,7 @@ export async function handleFix({
105106
glob,
106107
limit,
107108
minSatisfying,
109+
minimumReleaseAge,
108110
orgSlug,
109111
outputFile,
110112
outputKind,
@@ -138,6 +140,7 @@ export async function handleFix({
138140
ghsas: await convertIdsToGhsas(ghsas),
139141
glob,
140142
limit,
143+
minimumReleaseAge,
141144
minSatisfying,
142145
orgSlug,
143146
prCheck,

src/commands/fix/types.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type FixConfig = {
88
ghsas: string[]
99
glob: string
1010
limit: number
11+
minimumReleaseAge: string
1112
minSatisfying: boolean
1213
orgSlug: string
1314
prCheck: boolean

src/utils/dlx.mts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import { createRequire } from 'node:module'
2222

2323
import { getOwn } from '@socketsecurity/registry/lib/objects'
24+
import { spawn } from '@socketsecurity/registry/lib/spawn'
2425

2526
import { getDefaultOrgSlug } from '../commands/ci/fetch-default-org-slug.mts'
2627
import constants, {
@@ -168,6 +169,9 @@ export async function spawnDlx(
168169
* Helper to spawn coana with dlx.
169170
* Automatically uses force and silent when version is not pinned exactly.
170171
* Returns a CResult with stdout extraction for backward compatibility.
172+
*
173+
* If SOCKET_CLI_COANA_LOCAL_PATH environment variable is set, uses the local
174+
* Coana CLI at that path instead of downloading from npm.
171175
*/
172176
export async function spawnCoanaDlx(
173177
args: string[] | readonly string[],
@@ -207,6 +211,25 @@ export async function spawnCoanaDlx(
207211
}
208212

209213
try {
214+
const localCoanaPath = process.env['SOCKET_CLI_COANA_LOCAL_PATH']
215+
// Use local Coana CLI if path is provided.
216+
if (localCoanaPath) {
217+
const finalEnv = {
218+
...process.env,
219+
...constants.processEnv,
220+
...mixinsEnv,
221+
...spawnEnv,
222+
}
223+
const spawnResult = await spawn('node', [localCoanaPath, ...args], {
224+
cwd: dlxOptions.cwd,
225+
env: finalEnv,
226+
stdio: spawnExtra?.['stdio'] || 'inherit',
227+
})
228+
229+
return { ok: true, data: spawnResult.stdout }
230+
}
231+
232+
// Use npm/dlx version.
210233
const result = await spawnDlx(
211234
{
212235
name: '@coana-tech/cli',

0 commit comments

Comments
 (0)