Skip to content

Commit f650f5e

Browse files
committed
Use defaults that avoid arbitrary code execution for cdxgen
1 parent c365ffb commit f650f5e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/commands/cdxgen.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ const yargsConfig = {
5757
//evidence: false,
5858
//'include-crypto': false,
5959
//'include-formulation': false,
60-
//'install-deps': true,
60+
61+
// Default 'install-deps' to `false` and 'lifecycle' to 'pre-build' to
62+
// sidestep arbitrary code execution during a cdxgen scan.
63+
// https://github.com/CycloneDX/cdxgen/issues/1328
64+
'install-deps': false,
65+
lifecycle: 'pre-build',
66+
6167
//output: 'bom.json',
6268
//profile: 'generic',
6369
//'project-version': '',
@@ -103,6 +109,7 @@ const yargsConfig = {
103109
],
104110
string: [
105111
'api-key',
112+
'lifecycle',
106113
'output',
107114
'parent-project-id',
108115
'profile',
@@ -131,7 +138,7 @@ function argvToArray(argv: {
131138
} else if (value === true) {
132139
result.push(`--${key}`)
133140
} else if (typeof value === 'string') {
134-
result.push(`--${key}=${value}`)
141+
result.push(`--${key}`, String(value))
135142
} else if (Array.isArray(value)) {
136143
result.push(`--${key}`, ...value.map(String))
137144
}
@@ -149,7 +156,6 @@ export const cdxgen: CliSubcommand = {
149156
__proto__: null,
150157
...yargsParse(<string[]>argv_, yargsConfig)
151158
}
152-
153159
const unknown: string[] = yargv._
154160
const { length: unknownLength } = unknown
155161
if (unknownLength) {
@@ -159,7 +165,6 @@ export const cdxgen: CliSubcommand = {
159165
process.exitCode = 1
160166
return
161167
}
162-
163168
let cleanupPackageLock = false
164169
if (
165170
yargv.type !== 'yarn' &&
@@ -182,11 +187,9 @@ export const cdxgen: CliSubcommand = {
182187
} catch {}
183188
}
184189
}
185-
186190
if (yargv.output === undefined) {
187191
yargv.output = 'socket-cdx.json'
188192
}
189-
190193
await spawn(
191194
execPath,
192195
[await fs.realpath(cdxgenBinPath), ...argvToArray(yargv)],
@@ -201,7 +204,6 @@ export const cdxgen: CliSubcommand = {
201204
stdio: 'inherit'
202205
}
203206
)
204-
205207
if (cleanupPackageLock) {
206208
try {
207209
await fs.unlink('./package-lock.json')

0 commit comments

Comments
 (0)