fix: prevent path traversal in remote file synchronization #1109
+12
−1
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.
This PR fixes a critical path traversal vulnerability in the fetchRemote method of the Files class. Previously, remote filenames containing traversal sequences (e.g., ../../) were resolved without validation, allowing files to be written outside the intended project directory.
Changes
Established a Security Boundary: Resolved the absolute path of the contentDir to serve as a "jail" for file operations.
Path Normalization: Used path.resolve to normalize remote filenames and extensions into absolute local paths.
Boundary Validation: Implemented a check to ensure that the resolvedPath starts with the absoluteContentDir followed by the platform-specific path separator.
Security Error Handling: Added logic to throw a Security Error if a file resolution attempt falls outside the project directory, halting potentially malicious write operations.
Impact This fix prevents an attacker with control over a remote Apps Script project from performing arbitrary file writes on a user's local machine during a clasp pull or clasp clone. This effectively neutralizes a potential Remote Code Execution (RCE) vector.