fix: make spec_path containment mandatory in readSpecArg (#76) - #79
Open
TheAmericanMaker wants to merge 1 commit into
Open
fix: make spec_path containment mandatory in readSpecArg (#76)#79TheAmericanMaker wants to merge 1 commit into
TheAmericanMaker wants to merge 1 commit into
Conversation
readSpecArg enforced path containment only when allowedRoots was non-empty, and allowedRoots defaulted to []. Containment was therefore opt-in: any caller that omitted the argument would read whatever absolute path the client supplied, reopening the arbitrary-file-read class of bug fixed in v0.12.11 (#75). The only live caller (handlePublish) always passes a non-empty root set, so no released version is exploitable. This closes the gap by construction: - allowedRoots is now a required parameter, so omitting it is a compile error rather than a silent bypass. - An empty root set throws when spec_path is used, instead of skipping the check. - The guard runs before the existence check, so it cannot be used to probe which files exist. - The inline `spec` path is unaffected — it returns before containment. readSpecArg is now exported so the guarantee is directly testable; it is hardened rather than merely private. Four tests added, two of which fail against the previous implementation (verified by reverting). Closes #76 Co-Authored-By: Claude Opus 5 <noreply@anthropic.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.
Closes #76.
Problem
readSpecArgenforced containment only whenallowedRootswas non-empty — andallowedRootsdefaulted to[]:Any caller that omitted the argument would read whatever absolute path the client supplied — the same arbitrary-file-read class fixed in v0.12.11 (#75).
No released version is exploitable. The only live caller,
handlePublish, always passes a non-empty root set (library path +cwd/.codecarto). This is defense-in-depth.Fix
Containment is now the default posture and an empty root set fails closed:
allowedRootsis a required parameter — omitting it is a compile error, not a silent bypass. This is the part that actually prevents recurrence.spec_pathis used.specis unaffected — it returns before containment, as before.One deviation from the issue: it describes
readSpecArgas already exported. It wasn't — it was module-private with a single caller, so the exposure was narrower than stated. I've exported it now so the guarantee is directly testable, which is safe because the function is hardened rather than merely hidden.Tests
Four added to
tests/publish-path-containment.test.mjs, matching the issue's acceptance criteria:spec_pathwhenallowedRootsis emptyspec_pathwithin an allowed rootspecregardless of rootsI verified the two guard tests fail against the previous implementation by reverting the fix and re-running — they reported
not ok, so they are not vacuous.274/274 pass, build clean.
🤖 Generated with Claude Code