refactor: use path.relative for traversal guard, wrap env mutation in try/finally#9
Merged
danielmeppiel merged 1 commit intomainfrom Mar 10, 2026
Merged
Conversation
… try/finally - Replace startsWith prefix check with path.relative — handles edge cases like root directories where resolved + path.sep produces incorrect prefixes. - Wrap GITHUB_WORKSPACE mutation in test with try/finally to guarantee restoration even when assertions fail.
There was a problem hiding this comment.
Pull request overview
This PR refines the clearPrimitives safety logic and strengthens test isolation for the GitHub Action runner utilities, addressing edge cases and ensuring test environment cleanup.
Changes:
- Replace the traversal guard from
startsWith(resolved + path.sep)topath.relative()+path.isAbsolute()to correctly handle filesystem-root working directories. - Wrap
process.env.GITHUB_WORKSPACEmutation in the cross-workspace test withtry/finallyto guarantee restoration even on failure. - Update the compiled
dist/output to reflect the TypeScript changes.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/runner.ts |
Uses path.relative()-based traversal guard to correctly validate subpaths within the resolved working directory, including root edge cases. |
src/__tests__/runner.test.ts |
Ensures GITHUB_WORKSPACE is always restored via try/finally, preventing test pollution. |
dist/index.js |
Regenerates bundled output to match updated source logic (required by CI). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Addresses review feedback from #8:
path.relativetraversal guard — ReplacesstartsWith(resolved + path.sep)withpath.relative()+isAbsolute()check. The previous approach breaks whenresolvedis the filesystem root (/), producing a//prefix that rejects valid subpaths.path.relativehandles all edge cases correctly.try/finallyfor env mutation — The cross-workspace test mutatesprocess.env.GITHUB_WORKSPACE. If an assertion orclearPrimitivesthrows before the restore block, the env var stays polluted for subsequent tests. Wrapping intry/finallyguarantees cleanup.