Skip to content

fix(advisory): validate ids used in output paths (path traversal) - #25

Merged
sameehj merged 2 commits into
masterfrom
fix/advisory-path-traversal
Aug 19, 2026
Merged

fix(advisory): validate ids used in output paths (path traversal)#25
sameehj merged 2 commits into
masterfrom
fix/advisory-path-traversal

Conversation

@MarkAtwood

Copy link
Copy Markdown
Contributor

Supersedes #8, which GitHub closed permanently when its base branch
feat/advisory-test-infra was deleted on merging #7, and which cannot be
reopened because the head branch was force-pushed afterwards. Same branch, same
commit content, rebased onto master. Review history is on #8.

gen-advisory interpolated advisory ids straight into output paths, so an id
containing path separators could write outside the intended directory. Validates
the id before it reaches any path construction, with unit coverage in
central/test_gen_advisory.py.

cveId comes verbatim from remotely-fetched CVE records and was
interpolated into output filenames (<id>.csaf.json / <id>.cdx.json)
and the CSAF self URL without validation -- an untrusted-input ->
arbitrary-file-write vector (e.g. cveId "../ESCAPED" escaped --out-dir).

Constrain cveId to ^CVE-[0-9]{4}-[0-9]{4,}$ and --advisory-id to a
path-safe grammar before either is used to build a path.

Fixes #1

Adds a TestPathIdValidation regression class.

Fixes #1

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 hardens central/gen-advisory against path traversal by validating untrusted IDs (CVE record cveId and --advisory-id) before they are interpolated into output filenames/self-URLs, and adds unit coverage to prevent regressions.

Changes:

  • Add strict regex validation for CVE IDs and advisory IDs prior to any path construction.
  • Reject unsafe IDs with a clear error message and non-zero exit status.
  • Add CLI-level tests covering traversal/absolute-path payloads and a valid CVE ID acceptance case.

Reviewed changes

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

File Description
central/gen-advisory Adds _validate_path_id() + applies it to cveId parsing and --advisory-id handling.
central/test_gen_advisory.py Adds TestPathIdValidation to exercise rejection/acceptance paths and verify no escaped writes occur.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread central/gen-advisory
Comment thread central/gen-advisory
a non-string cveId reaches re.match and throws instead of failing cleanly.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sameehj
sameehj merged commit b3bccce into master Aug 19, 2026
1 check 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