[Blueprints] Keep directory theme writes inside the target folder - #3857
Merged
Conversation
adamziel
force-pushed
the
add/theme-directory-path-safety
branch
from
July 1, 2026 18:50
a902371 to
cfd6731
Compare
Base automatically changed from
add/theme-directory-if-already-installed
to
trunk
July 1, 2026 18:54
adamziel
force-pushed
the
add/theme-directory-path-safety
branch
2 times, most recently
from
July 1, 2026 19:06
4c0b117 to
ba288f1
Compare
adamziel
force-pushed
the
add/theme-directory-path-safety
branch
from
July 1, 2026 19:13
ba288f1 to
471a241
Compare
adamziel
force-pushed
the
add/theme-directory-path-safety
branch
from
July 1, 2026 19:23
471a241 to
ee700b7
Compare
adamziel
marked this pull request as ready for review
July 1, 2026 22:06
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Hardens directory-based theme installs and generic file-tree writes to prevent path traversal outside the intended target folder.
Changes:
- Validates directory-theme target folder names to be a single directory segment.
- Adds a root-boundary guard in
writeFiles()to reject writes outside the provided root. - Adds regression tests for theme install and
writeFiles()traversal cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/playground/blueprints/src/lib/steps/install-theme.ts | Adds validation to keep directory theme installs confined to a single folder name. |
| packages/php-wasm/universal/src/lib/write-files.ts | Enforces that each written path stays inside the caller-provided root directory. |
| packages/playground/blueprints/src/tests/steps/install-theme.spec.ts | Adds tests covering invalid theme folder names and file paths. |
| packages/php-wasm/node/src/test/write-files.spec.ts | Adds a test ensuring traversal paths are rejected by writeFiles(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
124
to
+132
| assetFolderName = targetFolderName || assetNiceName; | ||
| if ( | ||
| !assetFolderName || | ||
| basename(assetFolderName) !== assetFolderName | ||
| ) { | ||
| throw new Error( | ||
| 'Theme folder name must be a single directory name.' | ||
| ); | ||
| } |
Comment on lines
+48
to
+52
| if (!isParentOf(root, filePath)) { | ||
| throw new Error( | ||
| 'File paths must stay inside the target directory.' | ||
| ); | ||
| } |
| expect(php.fileExists(expectedThemeIndexPhpPath)).toBe(true); | ||
| }); | ||
|
|
||
| it('should reject directory theme names outside the themes directory', async () => { |
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.
What it does
Prevents directory-based theme installs from writing outside the intended theme folder.
Rejected examples:
{ "themeData": { "name": "../escape" } } { "options": { "targetFolderName": "nested/theme" } } { "themeData": { "files": { "../escape.php": "..." } } }Rationale
Zip-based theme installs go through
installAsset(), which moves one resolved asset folder intowp-content/themes.Directory resources skip
installAsset()and pass caller-provided names and file keys directly towriteFiles(). Without an explicit boundary check,../segments can resolve outside the theme directory before the files are written.Blueprint v2 lowering emits directory resources, so this needs to be enforced before the v2 runner depends on that path.
Implementation
Uses the existing POSIX path utilities instead of local string parsing:
installTheme()requires the resolved directory theme target to be a single directory name by checkingbasename(assetFolderName) === assetFolderName.writeFiles()computes each destination withjoinPaths(root, relativePath)and rejects it unlessisParentOf(root, filePath)is true.The
writeFiles()guard is intentionally shared: anyFileTreewrite now stays inside the root passed by the caller.This does not add symlink hardening or change zip install behavior.
Testing instructions