Repository navigation
Validate asset keys before writing files - #1046
Open
stephanie-shopify wants to merge 2 commits into
Open
stephanie-shopify wants to merge 2 commits into
stephanie-shopify wants to merge 2 commits into
Conversation
tgeselle
approved these changes
Oct 16, 2026
The check also rejects Windows device names and keys with colons, which don't escape the directory, so describe what a valid key is instead. The caller already logs the key, so don't repeat it in the error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
Validate asset keys before
Asset.Writeperforms any filesystem operations. Usefilepath.IsLocal(filepath.FromSlash(asset.Key))to reject empty, absolute, and directory-escaping keys, returning a wrappedErrAssetKeyEscapesDirectoryerror.Normal relative asset keys, including nested paths and paths that normalize within the destination, continue to work. This uses the existing Go version requirement and adds no dependencies.
Regression tests cover rejected keys, unchanged files outside the destination, absence of unexpected filesystem changes, and valid writes. Windows-specific cases cover backslash traversal, drive paths, UNC paths, rooted paths, and reserved device names.
This is lexical path validation; resolving or containing pre-existing symlinks is outside this change's scope.
Verification
Run locally with Go 1.24.3 on macOS:
go test ./src/shopify -run 'TestAsset_Write' -count=1go test -race -covermode=atomic ./...go vet ./...gofmton changed files andgit diff --checksrc/shopifytest binary for Windows/amd64. Windows-specific cases were not executed locally.make lintwas not run becausegolintis not installed locally.Warn Checklist