GHSA-JGQW-XMHG-9RFM
Symbolic link at bom.json in a scanned repository makes cdxgen overwrite another file
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-JGQW-XMHG-9RFM divulgada | |
| Remediación | Parche 12.9.1 | @cyclonedx/cdxgen · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
When cdxgen wrote its output, it followed a symbolic link at the output path. A repository that commits `bom.json` as a link to another file made a scan from that checkout truncate the link's target and write the generated BOM into it. Node.js's permission model did not stop this, because it follows the link to a target outside `--allow-fs-write`.
Details
The CLI writes its BOM to `bom.json` by default, and in secure mode it places that file inside the scanned directory even when cdxgen runs from elsewhere. The write went through `safeWriteSync()`, which checked dry-run mode and write permission for the path and then called `writeFileSync()`. `writeFileSync()` opens the path with `O_TRUNC` and follows a symbolic link in its last component, so a committed link chose the file that was overwritten. A dangling link made cdxgen create its target. `cdx-sign` and `cdx-audit` wrote their output with `writeFileSync()` directly.
Proof of concept
mkdir -p /tmp/poc/project && cd /tmp/poc/project
printf 'SENTINEL\n' > ../victim.txt
printf '{"name":"demo","version":"1.0.0"}\n' > package.json
ln -s ../victim.txt bom.json
cdxgen --no-install-deps -t js .
head -c 40 ../victim.txt`victim.txt` now holds the BOM and `bom.json` is still a link. The same happens with `CDXGEN_SECURE_MODE=true node --permission --allow-fs-write=/tmp/poc/project/bom.json ...`.
Impact
A malicious repository can overwrite any file that the user running the scan can write and whose path it can predict, such as configuration, cache or workspace files on a CI runner. The written bytes are the generated BOM, not attacker-chosen content, so the effect is corruption and denial of service in later steps rather than direct code execution.
Patches
Fixed in `@cyclonedx/cdxgen` 12.9.1 (#4758, commits e45cc3d https://github.com/cdxgen/cdxgen/commit/e45cc3db5bde912de56f7564cd5718a2c5b7e827 and 63fc7ca https://github.com/cdxgen/cdxgen/commit/63fc7ca41678ad09158a525b7a9fccb61305f7e3). The fix for `@cdxgen/cdxgen` is in #4759 (commit a1ede52 https://github.com/cdxgen/cdxgen/commit/a1ede52847f3e007b01d2f80ce72c43f7856c9dc) and will ship in 13.7.0. `safeWriteSync()` now removes a symbolic link in the last component of the path and creates a regular file in its place, with a warning. The file is opened with `O_NOFOLLOW` where the platform has it, so a link that appears after the check makes the write fail. Paths under `/dev` and `/proc`, such as `/dev/stdout`, are written as given. `cdx-sign` and `cdx-audit` write through `safeWriteSync()` too. The behaviour was checked on Node.js, Bun and Deno.
Workarounds
Pass `-o` with a path outside the checkout, or remove `bom.json` from the checkout before scanning.
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-jgqw-xmhg-9rfmLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
