Skip to content

pr: [Nightly Fix] - Security - Secure Admin Image Upload#48

Open
jewel-claw wants to merge 1 commit into
masterfrom
nightly-fix/secure-admin-image-upload
Open

pr: [Nightly Fix] - Security - Secure Admin Image Upload#48
jewel-claw wants to merge 1 commit into
masterfrom
nightly-fix/secure-admin-image-upload

Conversation

@jewel-claw

Copy link
Copy Markdown

What

Harden the admin image upload endpoint by restoring nonce protection and validating uploaded files from their actual file type instead of trusting the request MIME header.

Why

The wpf_upload_image route is currently exempt from wpf_admin_nonce verification, which leaves the admin upload action open to CSRF. It also trusts $_FILES['file']['type'], which is client-controlled and should not be the only file-type check.

Fix

  • Require the existing admin nonce for all global settings routes, including image upload
  • Append the nonce to the localized admin upload URL
  • Reject missing uploads early
  • Validate uploads with wp_check_filetype_and_ext() and allow only jpg/jpeg/png files

Confidence

High. The route already has an admin nonce in localized data, the change is localized, and both modified files pass php -l.

@greptile-apps

greptile-apps Bot commented Mar 20, 2026

Copy link
Copy Markdown

PR author is not in the allowed authors list.

@kilo-code-bot

kilo-code-bot Bot commented Mar 20, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • includes/Classes/GlobalSettingsHandler.php - Security fixes properly implemented
  • includes/Classes/Menu.php - Nonce properly added to URL

Security Analysis

The changes properly address the reported vulnerabilities:

  1. CSRF Fix (GlobalSettingsHandler.php:24): Removed the conditional that exempted wpf_upload_image from nonce validation. Nonce is now validated for all routes.

  2. File Type Validation (GlobalSettingsHandler.php:100-103): Replaced trusting client-provided MIME type ($_FILES['file']['type']) with wp_check_filetype_and_ext() which inspects actual file content. Uses strict comparison (in_array(..., true)) for added security.

  3. Empty File Check (GlobalSettingsHandler.php:95-97): Added early validation to reject missing or invalid uploads.

  4. Nonce in URL (Menu.php:160): The nonce is now included in the image_upload_url query string for the frontend to use.

All error responses now consistently use wp_send_json_error().


Reviewed by minimax-m2.5-20260211 · 155,862 tokens

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.

1 participant