Repository navigation
fix(foundry-toolchain-zksync): prevent path traversal vulnerabilities via toolchain version strings - #1
Open
mozluk wants to merge 1 commit into
Open
fix(foundry-toolchain-zksync): prevent path traversal vulnerabilities via toolchain version strings#1mozluk wants to merge 1 commit into
mozluk wants to merge 1 commit into
Conversation
… via toolchain version strings
## Motivation
This PR resolves a High-severity path traversal vulnerability in the `foundry-toolchain-zksync` repository, identified during the workspace-wide security audit. Previously, the toolchain version string supplied to the GitHub Action was used directly to construct filesystem paths and download URLs. Because the version string was not validated or sanitized, an attacker-controlled string such as `../../etc/` could allow directory traversal, escaping the intended installation directory. If interpolated into the release download URL, it could also point the download to an arbitrary repository, causing the runner to execute an attacker-supplied binary.
## Modifications
* **Path Traversal Rejection (`src/utils.js`, `dist/index.js`)**:
* Implemented strict validation in `normalizeVersionName` using a regular expression (`/^[A-Za-z0-9][A-Za-z0-9._-]*$/`) to restrict the version string to a safe, alphanumeric format.
* Added an explicit check for `version.includes("..")` to reject any parent-directory traversal attempts outright, throwing an `Invalid version input` error if detected.
* Updated `dist/index.js` (compiled output) by applying the 9-line semantic patch directly to maintain parity with `src/utils.js` without generating line-ending (CRLF) churn. (Note: `dist/index.js.map` was deliberately left at `HEAD` to avoid semantic-free diffs caused by Windows pathing).
## Checklist
- [x] Format your code according to the Contributor Guide.
- [ ] Add unit tests as outlined in the Contributor Guide.
- [x] Update documentation as needed, including docstrings or example tutorials.
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.
Motivation
This PR resolves a High-severity path traversal vulnerability in the
foundry-toolchain-zksyncrepository, identified during the workspace-wide security audit. Previously, the toolchain version string supplied to the GitHub Action was used directly to construct filesystem paths and download URLs. Because the version string was not validated or sanitized, an attacker-controlled string such as../../etc/could allow directory traversal, escaping the intended installation directory. If interpolated into the release download URL, it could also point the download to an arbitrary repository, causing the runner to execute an attacker-supplied binary.Modifications
src/utils.js,dist/index.js):normalizeVersionNameusing a regular expression (/^[A-Za-z0-9][A-Za-z0-9._-]*$/) to restrict the version string to a safe, alphanumeric format.version.includes("..")to reject any parent-directory traversal attempts outright, throwing anInvalid version inputerror if detected.dist/index.js(compiled output) by applying the 9-line semantic patch directly to maintain parity withsrc/utils.jswithout generating line-ending (CRLF) churn. (Note:dist/index.js.mapwas deliberately left atHEADto avoid semantic-free diffs caused by Windows pathing).Checklist