fix(advisory): validate ids used in output paths (path traversal) - #25
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #8, which GitHub closed permanently when its base branch
feat/advisory-test-infrawas deleted on merging #7, and which cannot bereopened because the head branch was force-pushed afterwards. Same branch, same
commit content, rebased onto master. Review history is on #8.
gen-advisoryinterpolated advisory ids straight into output paths, so an idcontaining 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.