GHSA-PHJ7-7J69-XMFH
Config file in a scanned repository can make cdxgen run attacker-chosen commands, even with --no-install-deps
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-PHJ7-7J69-XMFH divulgada | |
| Remediación | Parche 12.9.1 | @cyclonedx/cdxgen · 0 d desde divulgación | |
| Divulgación | Modificada | Última actualización del registro | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
cdxgen reads `.cdxgenrc`, `.cdxgen.json`, `.cdxgen.yml` or `.cdxgen.yaml` from the directory it runs in, which is usually the checkout being scanned. The file was handed to yargs and copied into the options object with almost no filtering, so a repository could set options that name the program cdxgen runs. A scan of a malicious checkout could therefore run the attacker's code, even with `--no-install-deps`, in secure mode and in the `cdxgen-secure` image.
Details
`bin/cdxgen.js` passed the parsed config to yargs with `.config()`, and `buildInitialOptions()` copied every resulting argument into `options`. In `@cdxgen/cdxgen`, `sanitizeProjectConfig()` only confined a handful of path options and announced a few others. Four routes led from the file to code execution:
- `dosaiCommand` is not a CLI option, but `runDosaiCommand()` in `lib/inventory/dosai.js` (`lib/helpers/dosai.js` in 12.x) runs `options.dosaiCommand` when it is set. With `evidence: true` and a .NET project, `"dosaiCommand": "/bin/sh"` makes the shell run a repository file named `methods`, the first argument cdxgen passes to dosai.
- `scalasem-command` (13.4.0 and later) names the script that `process.execPath` runs for Scala evidence. With `installDeps` off cdxgen only adds `--no-build`, so the script still runs.
- `traceCmd` with `type: dynamic` makes `createDynamicBom()` run that command under the tracer, and `traceWritePaths` and `traceDisableNetwork` from the same file widen the tracer's sandbox.
- yargs honours an `extends` key in a config object. A value that does not look like a JSON or rc file is loaded with `require()` inside the cdxgen process, so `"extends": "/proc/self/cwd/payload.js"` runs JavaScript in cdxgen itself. A JSON value merges another config file, which never passed through the sanitizer. This requires yargs 18, which cdxgen uses from 12.0.0; the ESM build of yargs 17 refuses `require()`.
The path checks were also lexical and ignored aliases, so `"o": "../file"` or a path through a symbolic link committed to the repository placed output outside the project. Routes 3 and 4 and the alias gap were found by AI agents while triaging this report.
The same config-file route also reaches the project's own build tooling. From 13.3.0, a `.cdxgen.json` that turns on introspection through a key the operator check did not recognise, such as `{"extends": "./shared-settings.json"}` naming a file that sets it, or a dashed spelling such as `{"-introspect": true}` that yargs folds onto `introspect`, made cdxgen run the repository's `gradlew` or `mvnw` although `--no-install-deps` or `--lifecycle pre-build` was given. The check added in 13.5.0 recognised only the literal `introspect` and `profile` keys. Anthropic's OSS Scanner reported this route as ANT-2026-354UYNOH. The fix below closes it too, because the sanitizer drops `extends` and every key that is not the exact spelling of a declared option before yargs reads the file.
Proof of concept
A checkout containing these three files writes a marker file when scanned with `cdxgen --no-install-deps .` from inside it:
`.cdxgenrc`
{ "type": ["dotnet"], "evidence": true, "dosaiCommand": "/bin/sh" }`methods`
printf 'executed\n' > "$PWD/CDXGEN_DOSAI_RCE"`app.csproj` is any project file with a `PackageReference`. The same marker appears with `{"type": ["dynamic"], "traceCmd": "/bin/sh -c 'touch marker'"}`, and with `{"extends": "/absolute/path/to/payload.js"}` where `payload.js` writes a file.
Impact
Anyone who controls a repository or pull request that a CI job or developer scans with cdxgen, from inside the checkout, can run code as the cdxgen user. That exposes CI secrets and source, and lets the attacker alter the workspace or the generated SBOM. The `--no-install-deps` option, secure mode and the `cdxgen-secure` image are documented to keep the scanned project's code from running, and none of them prevented this. The secure image grants `--allow-child-process`, and the `extends` route runs inside the Node.js process. Scanning a path while running cdxgen from a different, trusted directory does not load the target's config file.
Patches
Fixed in `@cyclonedx/cdxgen` 12.9.1 (#4758, commit 8c6415f https://github.com/cdxgen/cdxgen/commit/8c6415fe08c44696124dcf229a66ee9cbfa641b6). The fix for `@cdxgen/cdxgen` is in #4759 (commit ba53031 https://github.com/cdxgen/cdxgen/commit/ba53031be493b1ea7f228be8a22cbb1e8ecd345b) and shipped in 13.7.0. A config file may now set only the options `bin/cdxgen.js` declares, by their kebab-case or camelCase name or a declared alias. Every other key, including `dosaiCommand`, `traceCmd` and `extends`, is ignored with a warning, and a test fails when a new CLI option is added without deciding whether config files may set it. `scalasem-command`, `server`, `server-host`, `server-port`, `skip-dt-tls-check`, `feature-flags` and `help` can only come from the command line or a `CDXGEN_` environment variable. Path options must resolve inside the config's directory after symbolic links are resolved, and project types that inventory the host, such as `os` and `hbom`, are dropped. The operator's own `CDXGEN_DOSAI_COMMAND` and `--scalasem-command` keep working.
The same pull requests also bound the `exclude` and `include-regex` patterns a config file may set (commits e9839f9 https://github.com/cdxgen/cdxgen/commit/e9839f9eda251dd0fa9d761fe16ca453761d5be0 and 2c08bdb https://github.com/cdxgen/cdxgen/commit/2c08bdb25af5113e403628518e90df55727e0ac1), since brace expansion let a short pattern stand for thousands.
Workarounds
Run cdxgen from a trusted directory and pass the checkout as the path argument, so no config file from the checkout is read. Alternatively, delete `.cdxgenrc`, `.cdxgen.json`, `.cdxgen.yml` and `.cdxgen.yaml` from the checkout before scanning. Setting `CDXGEN_ALLOWED_COMMANDS` without `sh` or other shells blocks the dosai route but not the others.
Credits
Reported by @andife.
References
- https://github.com/cdxgen/cdxgen/pull/4758
- https://github.com/cdxgen/cdxgen/pull/4759
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npm@cyclonedx/cdxgen |
Corregida | 12.9.1 | 0 d | 12.9.2 no afectada |
12.9.113.7.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/cdxgen/cdxgen/security/advisories/GHSA-phj7-7j69-xmfhLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
