Repository navigation
Sanitized SVG uploads across all paths - #1030
girishpanchal30 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes requested
The new wp_upload_bits() guard accepts a script-carrying SVG and refuses legacy SVGs, and two upload routes still store unsanitized SVGs.
obfx_modules/svg-uploads/init.php:112-117—security✓ Verified in the sandbox The font-face REST route still stores an unsanitized SVG when SVG Uploads is active. WordPress 6.5+ swapsupload_mimesfor font types during that upload.wp_check_filetype()here then returns no type, sosanitize_uploaded_file()skips the file.adjust_filetype_extension()(:213-225) then forces.svgacceptance, and core moves the file touploads/fonts. Classify the name with a fixed map,wp_check_filetype( $name, array( 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml' ) ), as the new helper does. Add a test that posts an SVG with<script>to/wp/v2/font-families/<id>/font-facesand asserts the stored file has no<script.obfx_modules/svg-uploads/init.php:80-89—securityWordPress Importer still stores unsanitized SVG attachments. Itsfetch_remote_file()downloads to a temp file andcopy()s it into uploads. That path runs no upload prefilter and nowp_upload_bits(), while this module forces.svgacceptance. A WXR file whose attachment URL serves an SVG with<script>creates a public attachment with the script intact. This assumes WordPress Importer is installed and an administrator imports such a file. Sanitize the stored file of every new SVG attachment, for example onadd_attachment, so writers that skip the upload hooks are covered. Add a test that inserts an attachment for a copied SVG with<script>and asserts the stored file has none.
Validation details
- Files reviewed: 4/4 changed files.
- The added test passes at HEAD on WordPress 7.1.5 and PHP 8.3.37:
cd /repo && set -o pipefail; (timeout 900 phpunit --do-not-cache-result --filter 'Test_Svg_Upload_Paths::' 2>&1 | tee /w…printedOK (10 tests, 20 assertions)(run R7) - The added test fails on the pr-base code with 7 failures on the
<scriptand refusal assertions. The A/B helper printed no run record. - A DOCTYPE
ATTLISTdefaultonloadSVG passedwp_upload_bits()mkdir -p /workspace/checks/C11 && cd /workspace/checks/C11 && curl -fsSL --max-redirs 3 -o /dev/null -w '%{http_code}\n'…(run R14, exit 0) and ran in Chromiumcd /workspace/checks/C11 && sed -i "s/const files = \['c-attr.svg', 'c-title.svg', 'c-control-direct.svg'\];/const files…(run R22, exit 0). - A font-face upload stored a
<script>SVG underuploads/fontscd /var/www/html/wp-content/uploads/fonts && find . -type f | head; for f in $(find . -type f -name '*.svg'); do echo "=…(run R26, exit 0). - Upload, sideload, REST media and XML-RPC routes reach the new guards.
Untested areas
- Firefox and WebKit were not installed, so the browser check ran in Chromium only.
- WordPress versions between 5.3 and 7.1 were not inspected.
- The WordPress Importer route was traced in source only.
- Issue #2112 text was not available.
- The variant pass did not settle these places, where the fixed cause may still reach:
/repo/obfx_modules/svg-uploads/init.php:162-174— unverified: Both sanitizers ignore replacement-write failure and return success. A reachable producer supplying a readable but non-writable source, followed by successful upload copying, was n…/repo/obfx_modules/custom-fonts/custom_fonts_admin.php:471-485— unverified: Both sanitizers ignore replacement-write failure and return success. A reachable producer supplying a readable but non-writable source, followed by successful upload copying, was n…/deps/wordpress/5.3/wp-includes/version.php:16— unverified: Only these endpoint versions were inspected; intermediate supported releases remain unchecked./deps/wordpress/7.1/wp-includes/version.php:19— unverified: Only these endpoint versions were inspected; intermediate supported releases remain unchecked./deps/wordpress/7.1/wp-includes/deprecated.php:3678-3719— unverified: wp_get_http() writes the response directly to a supplied path without sanitization; repository/core searches found no non-recursive caller. A reachable upload entry point using it …- not reached: Complete independent unsafe-source trace for the existing-attachment copy at /deps/wordpress/7.1/wp-admin/includes/image.php:1333-1352, called by /deps/wordpress/7.1/wp-admin/inclu…
🤖 Automated review · run code-review-agent_6b0e698578b1f3.40729406.
🤖 Review agent — review posted ✅ on 195aa8be · changes requested · 5 findings · 20 min
Run code-review-agent_6b0e698578b1f3.40729406 · trail
There was a problem hiding this comment.
🟡 Changes requested
Uploads through wp_upload_bits() without an attachment still store unsanitized SVGs, and the new attachment hook deletes clean SVGs imported with no current user.
Validation details
- Files reviewed: 5/5 changed files.
- The changed test passes at this head on WordPress 7.1.5 and PHP 8.3.37:
cd /repo && set -o pipefail; timeout 300 phpunit --do-not-cache-result --filter 'Test_Svg_Upload_Paths::' 2>&1 | tee /wo…printedOK (18 tests, 57 assertions)(run R2) - The same tests fail against the pr-base code:
set -o pipefail; P=/var/www/html/wp-content/plugins; B=/workspace/checks/C2/base; ln -sfn $B $P/themeisle-companion && r…printedTests: 18, Assertions: 35, Errors: 1, Failures: 17(run R3) - The font-face upload and the copied-file import now store sanitized SVGs. Both earlier body findings are fixed.
- An XML-RPC upload with another user's post ID kept the script:
cd /workspace/checks/C7 && mv test-c7-xmlrpc-other-post.php Test_C7_Xmlrpc_Other_Post.php && rm -f result.txt && set -o …printedcontains_script=yes(run R16) - A clean SVG inserted as user 0 lost its file:
cd /workspace/checks/C9 && ls -la && rm -f result.txt && set -o pipefail; timeout 280 phpunit --do-not-cache-result --bo…printedfile_exists_after=no(run R17) - Non-SVG attachment inserts logged no PHP warnings on PHP 8.0 and 8.3 (run R11).
- Earlier runs R7, R14, R22 and R26 come from run code-review-agent_6b0e698578b1f3.40729406, not rerun.
Untested areas
- WP All Import removes all
add_attachmentactions. Its local-copy branches were not traced. - A failed rewrite of the stored file is ignored. No producer of a non-writable stored file was found.
- WordPress releases between 5.3 and 7.1 were not inspected.
- A third variant pass, for those two gaps, was not run.
- Issue #2112 text was not available.
- The variant pass did not settle these places, where the fixed cause may still reach:
/repo/obfx_modules/svg-uploads/init.php:190-192— unverified: both ignore replacement-write failure. No inspected producer establishes an attacker-supplied readable, non-writable file that survives the complete upload/attachment chain. Filesy…/repo/obfx_modules/custom-fonts/custom_fonts_admin.php:501-503— unverified: both ignore replacement-write failure. No inspected producer establishes an attacker-supplied readable, non-writable file that survives the complete upload/attachment chain. Filesy…/deps/wordpress/5.3/wp-includes/version.php:16— unverified: confirms 5.3 only; /repo/readme.txt:4-5 declares the broader 5.3–7.1 range. Intermediate-release behavior remains unchecked./deps/wordpress/7.1/wp-includes/version.php:19— unverified: confirms 7.1 only, not intermediate supported releases./deps/wordpress/7.1/wp-includes/deprecated.php:3678-3719— unverified: wp_get_http() writes response bytes without sanitization, but searches found no nonrecursive caller in this checkout or either inspected core version. WordPress Importer 0.9.7 inst…
🤖 Automated review · run code-review-agent_6b0e7192a3c762.05693376.
🤖 Review agent — review posted ✅ on fe912b39 · changes requested · 2 findings · 23 min
Run code-review-agent_6b0e7192a3c762.05693376 · trail
There was a problem hiding this comment.
🟡 Changes requested
The earlier findings are fixed, but an SVG from wp_upload_bits() stays unsanitized and public until the request ends.
Validation details
- Files reviewed: 5/5 changed files.
- The upload tests pass at this head on WordPress 7.1.5 and PHP 8.3.37:
cd /repo && set -o pipefail; timeout 280 phpunit --do-not-cache-result --filter 'Test_Svg_Upload_Paths::' 2>&1 | tee /wo…printedOK (22 tests, 69 assertions)(run R2) - The two new tests fail on the prior head fe912b3:
cd /workspace/checks/C3/prior && L=/var/www/html/wp-content/plugins/themeisle-companion; ln -sfn /workspace/checks/C3/pr…printedTests: 22, Assertions: 63, Errors: 2, Failures: 2(run R3) - Live XML-RPC uploads with a denied parent left sanitized files for both modules and both payloads (runs R6, R7).
- A PNG insert with both modules logged no Orbit Fox warnings (run R10).
- Question:
CONTRIBUTING.md:155places tests undertests/php/unit. Is that rule still current?
Untested areas
- A failed rewrite of the stored file is ignored. No producer of a non-writable stored SVG was found.
- WP All Import writes files after it removes
add_attachmentactions. This was not traced. - WordPress 5.4 to 7.0 were not inspected. The warning check ran on PHP 8.3 only.
- No run fetched the file during an open request.
- The variant pass did not settle these places, where the fixed cause may still reach:
obfx_modules/svg-uploads/init.php:202-204— unverified: both sanitizers ignore replacement-write failure and return success, preventing deletion at core/includes/class-orbit-fox-svg-compatibility.php:183-184. Missing fact: a reachable w…obfx_modules/custom-fonts/custom_fonts_admin.php:514-516— unverified: both sanitizers ignore replacement-write failure and return success, preventing deletion at core/includes/class-orbit-fox-svg-compatibility.php:183-184. Missing fact: a reachable w…
🤖 Automated review · run code-review-agent_6b0e7971ae49e3.74397531.
🤖 Review agent — review posted ✅ on b30073b8 · changes requested · 1 finding · 14 min
Run code-review-agent_6b0e7971ae49e3.74397531 · trail
There was a problem hiding this comment.
🟡 Changes requested
The new pre-write check still lets unsafe SVG bits through wp_upload_bits(), and imported SVGs stay public until the attachment hook runs.
Validation details
- Files reviewed: 5/5 changed files. Unchecked rows: issue #663 PHP 8.0 debug-log warnings on starter-site import; Narrowed input: Base; Narrowed input: Sources; replacement-write failure; WP All Import local-SVG route.
- The upload tests pass at this head:
cd /repo && set -o pipefail; timeout 280 bash -c "cd /repo && phpunit --do-not-cache-result --filter 'Test_Svg_Upload_Pa…printedOK (33 tests, 92 assertions)(run R2) - Both modules stored a CDATA fake-comment
<script>payload unchanged (run R7) and a DOCTYPE fake-commentonloadpayload unchanged (run R9). - Chromium ran that
onloaddefault (run R10). It did not fetch an external DTD (run R13). - UTF-16 and plain script payloads were refused (run R7).
Untested areas
- Firefox was not installed. Browser checks ran in Chromium only.
- Replacement-write failure needs an uploads folder without owner write. No run built one.
- WP All Import reaches its SVG copy only through an add-on. No add-on was traced.
- The rows "issue #663 PHP 8.0 debug-log warnings", "Narrowed input: Base" and "Narrowed input: Sources" were not settled.
- The variant pass did not settle these places, where the fixed cause may still reach:
/deps/plugins/wp-all-import/latest/models/import/record.php:3563-3582,3629-3635,4396-4403— unverified: WP All Import 4.2.0 has a raw local-SVG copy route whose attachment creation removes Orbit Fox’s hook. Unlike remote .svg downloads, this route does not call its own sanitizer. How…/repo/obfx_modules/svg-uploads/init.php:202-204— unverified: both replacement writes still ignore failure. No reachable producer of a readable but non-writable malicious stored SVG was established./repo/obfx_modules/custom-fonts/custom_fonts_admin.php:514-516— unverified: both replacement writes still ignore failure. No reachable producer of a readable but non-writable malicious stored SVG was established.
🤖 Automated review · run code-review-agent_6b0e891416a751.14521724.
🤖 Review agent — review posted ✅ on 0749e4b4 · changes requested · 1 finding · 37 min
Run code-review-agent_6b0e891416a751.14521724 · trail
There was a problem hiding this comment.
🟡 Changes requested
Both earlier findings are fixed, but WP All Import still copies a raw local SVG into uploads without any Orbit Fox guard.
Questions for the author: Does wp_upload_bits() write the original bits to a public file before the shutdown sanitizer runs? The filter returns accepted bits unchanged, and sanitizing waits for shutdown.
securityWP All Import still stores a raw SVG. The new guards cover XML-RPC bits and WordPress Importer temp files. WP All Import 4.2.0 copies a local.svginto uploads unchanged (models/import/record.php:3548-3582). It then callsremove_all_actions('add_attachment')before it inserts the attachment (:3629-3635,:4396-4403). No upload, sideload, bits, temp-file or attachment hook of Orbit Fox runs. This assumes a product import consumes an unsafe SVG already present in WP All Import's local image folder. Sanitize SVG files on this route before the copy into uploads, or refuse SVG there. Add a test that runs the import with each module enabled on its own.
Validation details
- Files reviewed: 5/5 changed files. Unchecked row: Narrowed input: Base.
- The upload tests pass at this head on WordPress 7.1.5 and PHP 8.3.37:
cd /repo && set -o pipefail; timeout 280 phpunit --do-not-cache-result --filter 'Test_Svg_Upload_Paths::' 2>&1 | tee /wo…printedOK (40 tests, 110 assertions)(run R4) - WordPress Importer 0.9.7 imports of a
<script>SVG stored a clean file beforeadd_attachment, with each module enabled (runs R22, R26). - An unparseable SVG was refused, and no file was written (runs R28, R29).
- Clean SVG imports logged no new debug lines:
cd /var/www/html && cat wp-content/uploads/2026/12/mal-1.svg; echo; DBG=wp-content/debug.log; PRE=$(wc -l < $DBG); rm -f…printednew debug.log lines: 0(run R27) - The WP All Import route is traced in source only. It was not executed.
Untested areas
- The row "Narrowed input: Base" was not settled.
- Replacement-write failure needs an uploads folder without write access. No run built one.
- The custom header copy of an SVG was not traced to an unsafe source.
- Browser checks did not run. PHP 8.0 did not run.
- The variant pass did not settle these places, where the fixed cause may still reach:
/repo/obfx_modules/svg-uploads/init.php:217-219— unverified: both replacement writers ignore failure and return success. Missing fact: a reachable upload/import producer leaving readable unsafe SVG bytes that these writes cannot replace. No …/repo/obfx_modules/custom-fonts/custom_fonts_admin.php:527-529— unverified: both replacement writers ignore failure and return success. Missing fact: a reachable upload/import producer leaving readable unsafe SVG bytes that these writes cannot replace. No …/deps/wordpress/7.1/wp-admin/includes/image.php:1333-1352— unverified: copy_image_file() copies without a pre-publication sanitization hook; custom-header skip-cropping reaches it at /deps/wordpress/7.1/wp-admin/includes/class-custom-image-header.php:…
🤖 Automated review · run code-review-agent_6b0e9968bf1a13.22193409.
🤖 Review agent — review posted ✅ on 5e094ed9 · changes requested · 0 findings · 17 min
Run code-review-agent_6b0e9968bf1a13.22193409 · trail
|
Replies to the review summary on X4 (WP All Import local-SVG copy): not valid for this PR. Moved to a follow-up issue: Codeinwp/themeisle#2114.
Question: does |
Summary
Strengthened SVG upload security by introducing a shared helper to reject unsafe SVG files across all WordPress upload paths, including
wp_upload_bits(). Applied consistent sanitization and validation logic in both the SVG Uploads and Custom Fonts modules. Added comprehensive tests to verify safe SVG handling and rejection of unsafe files across different upload methods.Will affect visual aspect of the product
NO
Check before Pull Request is ready:
Closes https://github.com/Codeinwp/themeisle/issues/2112