Repository navigation
Conversation
…multisite size check. `WP_REST_Attachments_Controller::upload_from_data()` writes the request body to a file from `wp_tempnam()` before calling `check_upload_size()`. When that check fails (file too big, not enough upload space, or user over quota), the method returned the error without deleting the file, so every rejected upload left a copy of its body in the temporary directory. Delete the temporary file before returning, as the method already does when `wp_handle_sideload()` fails and as the URL sideload path does for the same check. Fixes #66409.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Test ReportThis report validates that the indicated patch addresses the issue. Patch tested: #15134 Environment
Steps taken1. PHPUnit
2. Manual test (multisite)
Expected ResultsWhen a raw-body REST upload is rejected by the multisite size check, the temporary file is removed. Actual Results
Additional Notes
|
WP_REST_Attachments_Controller::upload_from_data()writes the request body to afile from
wp_tempnam()before callingcheck_upload_size(). When that checkfails on multisite (file too big, not enough upload space, or user over quota),
the method returned the error without deleting the file, so every rejected
raw-body upload left a copy of its body in the temporary directory.
This deletes the file before returning, as the method already does when
wp_handle_sideload()fails and as the URL sideload path does after the samecheck.
Adds
test_create_item_with_data_exceeds_multisite_max_filesize_removes_temp_file()(
ms-required), which checks that nocanola-*.tmpis left after a rejected upload.Tested on a local 7.1.4 multisite (subdirectory): with
fileupload_maxk = 1, a5 KB raw-body upload returned
400 rest_upload_file_too_bigand left one.tmp(5120 bytes) in the temp dir; with the change, the same request leaves none.Trac ticket: https://core.trac.wordpress.org/ticket/66409
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code, with code-intruder (my own static analysis tool)
Model(s): Claude Opus, Claude Haiku
Used for: code-intruder flagged the temporary file left on the error return and
an AI review triaged the finding. AI helped reproduce it on a local multisite
install (REST request, checking the temp dir before/after) and write the test.
I reviewed and tested the change myself.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.