Skip to content

Sanitized SVG uploads across all paths - #1030

Open
girishpanchal30 wants to merge 6 commits into
developmentfrom
bugfix/themeisle/2112
Open

girishpanchal30 wants to merge 6 commits into
developmentfrom
bugfix/themeisle/2112

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

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

@pirate-bot

pirate-bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Plugin build for 5e094ed is ready 🛎️!

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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+ swaps upload_mimes for font types during that upload. wp_check_filetype() here then returns no type, so sanitize_uploaded_file() skips the file. adjust_filetype_extension() (:213-225) then forces .svg acceptance, and core moves the file to uploads/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-faces and asserts the stored file has no <script.
  • obfx_modules/svg-uploads/init.php:80-89 — security WordPress Importer still stores unsanitized SVG attachments. Its fetch_remote_file() downloads to a temp file and copy()s it into uploads. That path runs no upload prefilter and no wp_upload_bits(), while this module forces .svg acceptance. 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 on add_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… printed OK (10 tests, 20 assertions) (run R7)
  • The added test fails on the pr-base code with 7 failures on the <script and refusal assertions. The A/B helper printed no run record.
  • A DOCTYPE ATTLIST default onload SVG passed wp_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 Chromium cd /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 under uploads/fonts cd /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

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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… printed OK (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… printed Tests: 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 … printed contains_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… printed file_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_attachment actions. 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

Comment thread obfx_modules/svg-uploads/init.php Resolved

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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… printed OK (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… printed Tests: 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:155 places tests under tests/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_attachment actions. 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

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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… printed OK (33 tests, 92 assertions) (run R2)
  • Both modules stored a CDATA fake-comment <script> payload unchanged (run R7) and a DOCTYPE fake-comment onload payload unchanged (run R9).
  • Chromium ran that onload default (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

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

  • security WP 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 .svg into uploads unchanged (models/import/record.php:3548-3582). It then calls remove_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… printed OK (40 tests, 110 assertions) (run R4)
  • WordPress Importer 0.9.7 imports of a <script> SVG stored a clean file before add_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… printed new 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

@girishpanchal30

Copy link
Copy Markdown
Contributor Author

Replies to the review summary on 5e094ed:

X4 (WP All Import local-SVG copy): not valid for this PR. Moved to a follow-up issue: Codeinwp/themeisle#2114.

  • Only a user who can run WP All Import imports reaches this route: setup_network, i.e. manage_options on single site (WP All Import Pro 4.10.0 wp-all-import-pro.php:155,312). That user already has unfiltered_html, so no privilege boundary is crossed. The SVG also has to be in WP All Import's own local import folder already.
  • In Pro 4.10.0, add_attachment is removed only in the opt-in fast mode (models/import/record.php:2686-2688). That mode strips every plugin's attachment and post hooks, so covering it needs a WP All Import integration rather than a change to the core-path guards here.
  • The base branch has the same gap, and this PR adds no path through it.

Question: does wp_upload_bits() write the original bits to a public file before the shutdown sanitizer runs?
Yes, but only bits that have already passed Orbit_Fox_Svg_Compatibility::is_safe_as_given(). Anything else is refused before the write, so nothing unsafe is written. The shutdown pass only matters for files written after wp_upload_bits() returns, such as an empty placeholder an importer fills later. Covered by test_xmlrpc_upload_with_denied_parent_never_writes_unsafe_svg and test_upload_bits_placeholder_written_later_is_sanitized_at_shutdown.

@pirate-bot
pirate-bot removed their request for review December 1, 2026 10:30
@pirate-bot
pirate-bot removed their request for review December 1, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants