Skip to content

fix: harden SBOM tools against bad input - #19

Merged
sameehj merged 2 commits into
masterfrom
fix/low-findings-bundle
Oct 2, 2026
Merged

sameehj merged 2 commits into
masterfrom
fix/low-findings-bundle

Conversation

@MarkAtwood

@MarkAtwood MarkAtwood commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Small fixes across the SBOM tools, each with a regression test in tests/test_low_findings.py.

  • gen-sbom: writes CycloneDX/SPDX to a temp file in the output directory and renames it into place, so a crash or ENOSPC cannot leave a truncated document. Symlinks, devices and FIFOs (/dev/stdout) are written directly. An existing file keeps its mode; a read-only one is refused.
  • gen-sbom: dedups --srcs on the normalized absolute path, so foo.c and ./foo.c collapse instead of tripping the duplicate-basename guard. Distinct names symlinked to one file stay distinct.
  • validate_sbom.py: rejects unreadable, non-UTF-8 and non-object JSON input with an error instead of a traceback.
  • compdb frontend: a later -U cancels an earlier -D, including function-like macros. With --root, skips sources that resolve outside it, since compile_commands.json is untrusted. --root / works.
  • sbom-driver: an empty --version-macro returns "" instead of matching the first quoted string in the header.
  • selftest.yml: permissions: contents: read, and runs the new tests.

Copilot AI review requested due to automatic review settings July 24, 2026 04:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bundles a set of low-severity hardening fixes across SBOM generation/validation, the compilation-database frontend, and CI, with a new regression test suite (tests/test_low_findings.py) and workflow wiring to ensure these cases stay covered.

Changes:

  • Make gen-sbom write CycloneDX/SPDX outputs atomically and deduplicate --srcs on realpath.
  • Harden validate_sbom.py error handling and reject non-object top-level JSON.
  • Improve path/macro handling across sbom-driver.py, compdb_sbom.py, and CMake SBOM target naming; wire new regression tests into CI.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_low_findings.py Adds regression tests covering the bundled low-severity findings.
share/validate_sbom.py Improves robustness: broader read-error handling and top-level JSON type validation.
share/sbom-driver.py Enhances absolute-path scrubbing and guards version-macro extraction.
share/gen-sbom Adds atomic JSON writing and realpath-based --srcs dedup; uses atomic writer for outputs.
share/frontends/compdb_sbom.py Honors -U undefines and restricts sources to --root when provided.
share/build/sbom.cmake Avoids target-name collision on multiple wolfglass_add_sbom() calls.
.github/workflows/selftest.yml Restricts workflow permissions and runs the new low-findings test suite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +22
from importlib.machinery import SourceFileLoader

REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SHARE = os.path.join(REPO, "share")
GEN_SBOM = os.path.join(SHARE, "gen-sbom")
VALIDATE = os.path.join(SHARE, "validate_sbom.py")

gs = SourceFileLoader("gen_sbom", GEN_SBOM).load_module()
drv = SourceFileLoader("sbom_driver", os.path.join(SHARE, "sbom-driver.py")
).load_module()
compdb = SourceFileLoader(
"compdb_sbom", os.path.join(SHARE, "frontends", "compdb_sbom.py")
).load_module()
Comment on lines +130 to +135
if root_abs:
real = os.path.realpath(fpath)
if real != root_abs and not real.startswith(root_abs + os.sep):
sys.stderr.write(
f"WARNING: skipping source outside --root: {fpath}\n")
continue
Comment thread share/build/sbom.cmake Outdated
Comment on lines +146 to +149
set(_sbom_target sbom)
if(TARGET sbom)
set(_sbom_target sbom-${SB_NAME})
endif()
Comment thread share/sbom-driver.py Outdated
Comment on lines +44 to +47
# Absolute path at the start of a token: a Unix path (/home/...) or a Windows
# drive path (C:\Users\... or C:/Users/...). Redacted so a host path never
# leaks into the SBOM regardless of the build host OS.
_ABS_PATH = re.compile(r'^([A-Za-z]:[\\/]|/)[^ ]*')
Comment thread share/gen-sbom Outdated
Comment on lines +112 to +118
tmp = f'{path}.tmp'
try:
with open(tmp, 'w') as f:
json.dump(obj, f, indent=2)
f.write('\n')
os.replace(tmp, path)
except OSError:
@sameehj
sameehj force-pushed the master branch 4 times, most recently from 3ab77f9 to 9bdf5b7 Compare July 24, 2026 14:09
@MarkAtwood
MarkAtwood force-pushed the fix/low-findings-bundle branch from 61cf4d2 to 9ce1ea6 Compare August 13, 2026 01:25
@MarkAtwood
MarkAtwood force-pushed the fix/low-findings-bundle branch from 9ce1ea6 to dfc3dcc Compare September 29, 2026 01:09
- gen-sbom: write CycloneDX/SPDX to a temp file in the output directory
  and rename it into place, so a crash or ENOSPC cannot leave a
  truncated document. Symlinks, devices and FIFOs (/dev/stdout) are
  written directly. An existing file keeps its mode; a read-only one is
  refused.
- gen-sbom: dedup --srcs on the normalized absolute path, so foo.c and
  ./foo.c collapse instead of tripping the duplicate-basename guard.
- validate_sbom.py: reject unreadable, non-UTF-8 and non-object JSON
  input with an error instead of a traceback.
- compdb frontend: a later -U cancels an earlier -D, including
  function-like macros. With --root, skip sources that resolve outside
  it, since compile_commands.json is untrusted.
- sbom-driver: an empty --version-macro returns "" instead of matching
  the first quoted string in the header.
- selftest.yml: permissions: contents: read.

Adds tests/test_low_findings.py, wired into selftest.yml.
@MarkAtwood
MarkAtwood force-pushed the fix/low-findings-bundle branch from 3c3cf79 to 3c5bf65 Compare October 1, 2026 20:54
@MarkAtwood MarkAtwood changed the title fix(review): low-severity findings bundle fix: harden SBOM tools against bad input Oct 1, 2026
@sameehj
sameehj merged commit 50f37e4 into master Oct 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants