Skip to main content
Menu
Advisories

C/C++ scans run a compiler that the scanned repository names in compile_commands.json

GHSA-4P2J-75XR-7VC4Published Updated GitHub

Description

To identify the compilers of a C/C++ project, cdxgen runs each compiler driver named in the project's compile_commands.json with --version. The check that is meant to keep this to real toolchains, trustedCompilerPath(), only refuses paths spelled inside the scan root. A database can therefore name a program shipped in the same checkout, and cdxgen runs it. This happens in -t c, -t cpp and untyped scans, which otherwise start no project build tool, and it still happens with --no-install-deps and --lifecycle pre-build.

Details

trustedCompilerPath() in lib/ecosystems/cppBuildContext.js accepts every absolute path unless isInsideDir() places it under the scan root. A file from the same checkout passes this check in three cases:

  • The operator scans a subdirectory of the checkout, and the database names a file elsewhere in it.
  • The path goes through a directory whose name starts with ... isInsideDir() tests rel.startsWith(".."), so such a directory counts as outside even in a scan of the whole checkout.
  • The database spells the scan root in a different letter case on a case-insensitive file system.

The database must give an absolute path. A repository can do this when cdxgen is started inside the checkout (on Linux, through /proc/self/cwd) or when the checkout sits at a predictable location such as a CI workspace. queryCompilerBanner() then starts the file through safeSpawnSync(), and its output is recorded in the BOM as the compiler version.

Impact

The author of a repository, or of a pull request to it, gets code of their choice run on the scanning host with the privileges and environment of the cdxgen process, including any CI tokens or registry credentials. Secure mode, --dry-run and a CDXGEN_ALLOWED_COMMANDS list that does not include the file are not affected. A repository that cdxgen --server clones into a random temporary directory is not reachable, because the database cannot name its path.

Patches

Fixed in @cdxgen/cdxgen 13.8.0. Versions 13.4.0 through 13.7.0 of @cdxgen/cdxgen are affected. The 12.x line, published as @cyclonedx/cdxgen, does not contain the affected code.

Workarounds

  • Use CDXGEN_SECURE_MODE=true, or set CDXGEN_ALLOWED_COMMANDS to the tools the scan needs.
  • Scan untrusted repositories from outside the checkout, by path, and scan the whole checkout rather than a subdirectory.
  • Delete compile_commands.json files from untrusted checkouts before scanning.

Credit

This issue was found by Anthropic's OSS Scanner (scan cdxgen-20261108-009) and reported as ANT-2026-3FMLUTQ4.

References

Affected versions

References

GitHub · cdxgen/cdxgen