fix(contract): constrain canonical code-evidence paths - #542
Open
sylvesterkaczmarek wants to merge 2 commits into
Open
fix(contract): constrain canonical code-evidence paths#542sylvesterkaczmarek wants to merge 2 commits into
sylvesterkaczmarek wants to merge 2 commits into
Conversation
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.
Summary
Require canonical
codeEvidence[].pathvalues to stay inside the same repository-relative POSIX path boundary used elsewhere in the scan contract.Fixes #541.
Reproduction / evidence
Current upstream
mainat37bf87a692fc72d41f7312cc48808d699d204fbaexplicitly validates every ordinary finding location with the canonical safe-path helper, but the findings schema definescodeEvidence[].pathas only a nonempty string.A sealed-contract reproduction is:
../../outside.ts;findings.jsondigest inscan-manifest.json;loadContract().On the unfixed schema, the traversal path satisfies the code-evidence schema and no separate canonical code-evidence path check rejects it.
The regression in this PR exercises the real sealed loader with these invalid shapes:
../../outside.ts;/etc/passwd;C:/outside.ts;src\\outside.ts;.;src:stream.ts;It also reseals and loads a valid
src/extract.pycontrol.Root cause
Location path safety was implemented in explicit validator code, while optional code evidence was added with only a schema-level nonempty-string requirement. The shared findings schema is consumed by both TypeScript validation and the Python finalizer, so the missing constraint crossed both validation surfaces.
Fix
Add a safe repository-relative path pattern to
codeEvidence[].path. It rejects absolute paths, traversal segments, backslashes, colon-bearing paths, the standalone dot path, and NUL characters.The schema remains otherwise unchanged.
Tests / validation
Added
code-evidence-paths.test.ts, which mutates the real completed-scan fixture, recomputes the findings artifact digest, and callsloadContract()for every invalid path plus a valid control.The branch is based directly on current upstream
mainat37bf87a692fc72d41f7312cc48808d699d204fbaand is not behind it. Production change: 2 additions and 1 deletion in the shared findings schema. The remainder is focused regression coverage.Full repository tests cannot be run in this execution environment because the repository cannot be cloned here. Pushed-head CI remains the authoritative full-suite validation.
Risk
Low. This only rejects code-evidence paths that violate the repository-relative path model already enforced for canonical finding locations. Valid repository-relative paths are unchanged.