fix[faustwp]: (#2311) clean up uploaded blockset zip when extraction fails#2338
Merged
josephfusco merged 2 commits intoMay 14, 2026
Merged
Conversation
…raction fails When unzip_uploaded_file() returns a WP_Error in process_and_replace_blocks(), the uploaded zip was left behind in the target directory. On repeat failures this accumulates dead files on disk. Delete the target file before returning the error so the upload slot stays clean. Mirrors the existing cleanup_temp_directory() call on the success path. Split out from wpengine#2312 per @josephfusco review feedback — the hash_equals security hardening half stays on that PR so each can be reviewed and reverted independently.
|
Currently, we do not support the creation of preview deployments based on changes coming from forked repositories. |
🦋 Changeset detectedLatest commit: a0302a8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
5 tasks
…-failure cleanup (wpengine#2311) Adds two unit tests covering process_and_replace_blocks() in includes/blocks/functions.php, which previously had zero direct coverage (every existing test in BlockFunctionTests.php stubbed it out via Brain Monkey). - test_process_and_replace_blocks_cleans_up_on_unzip_failure asserts that on a WP_Error from unzip_uploaded_file(), the function calls $wp_filesystem->delete($target_file) exactly once before returning the error. Verified red-on-revert: removing the new delete line in functions.php fails this test cleanly with a precise Mockery error ('delete should be called exactly 1 times but called 0 times'). This is the regression guard against future changes that drop the cleanup. - test_process_and_replace_blocks_success_path_does_not_delete_target asserts the inverse: on the happy path, delete() is NOT called on the target file (the extracted zip remains on disk) and cleanup_temp_directory() runs for the staging dir. Catches a future over-aggressive change that would delete the target on success. Both tests follow the existing Brain Monkey + Mockery pattern in BlockFunctionTests.php; the cleanup_temp_directory stub in the failure-path test additionally throws a LogicException so we catch regressions where the is_wp_error early-return is removed (and success-path cleanup leaks into the failure path). Verified locally with the full suite (composer test, single-site + multisite): 123 tests, 283 assertions, all green. Targeted run: "OK (2 tests, 6 assertions)".
josephfusco
approved these changes
May 14, 2026
|
Currently, we do not support the creation of preview deployments based on changes coming from forked repositories. |
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
When
unzip_uploaded_file()returns aWP_Errorinsideprocess_and_replace_blocks(), the moved-but-never-extracted.zipwas left on disk at the predictable pathwp-content/uploads/faustwp/blocks/. Repeated failures accumulate dead files.This PR deletes the target file before returning the error so the upload slot stays clean. The endpoint is auth-gated by the
x-faustwp-secretheader, so this is hygiene-class rather than directly exploitable, but it's still incorrect cleanup behaviour.Related Issue
Closes #2311
Split out from #2312 per @josephfusco's review feedback — the
hash_equals()security hardening landed via #2312 (merged as5d73ec86) so each change could be reviewed and reverted independently.Confirm the issue (on canary)
Confirm the fix (this branch)
Run the test suite (corrected from earlier draft)
The
test_process_and_replace_blocks_cleans_up_on_unzip_failuretest is the regression guard — verified to fail when the new$wp_filesystem->delete()line is reverted (Mockery reportsdelete should be called exactly 1 times but called 0 times), pass with it in place.Checklist
canary@faustwp/wordpress-pluginpatch)tests/unit/BlockFunctionTests.php) — covers both unzip-failure path and success path