Make WordPress Core

Opened 4 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#64599 closed defect (bug) (fixed)

Harden handling of PHP superglobals to prevent notices and potential data integrity issues

Reported by: vishalkakadiya's profile vishalkakadiya Owned by: westonruter's profile westonruter
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: Site Health Keywords: has-patch changes-requested
Focuses: Cc:

Description (last modified by westonruter)

WordPress core relies on several values from PHP superglobal variables. In some cases, these values are accessed directly without first verifying their existence or applying proper sanitization. This can lead to potential security data integrity concerns and PHP notices.

This pull request addresses a subset of these issues by adding appropriate existence checks and sanitization to ensure safer and more robust handling of superglobal data.

Change History (18)

This ticket was mentioned in PR #10870 on WordPress/wordpress-develop by @vishalkakadiya.


4 weeks ago
#1

  • Keywords has-patch added

### Detail

WordPress core relies on several values from PHP superglobal variables. In some cases, these values are accessed directly without first verifying their existence or applying proper sanitization. This can lead to potential security concerns and PHP notices.

This pull request addresses a subset of these issues by adding appropriate existence checks and sanitization to ensure safer and more robust handling of superglobal data.

#2 @mukesh27
4 weeks ago

  • Version trunk deleted

@vishalkakadiya commented on PR #10870:


4 weeks ago
#3

@sabernhardt I have reverted that suggested changes now.

#4 @mukesh27
4 weeks ago

  • Component changed from General to Site Health
  • Keywords changes-requested added
  • Milestone changed from Awaiting Review to 7.0

@vishalkakadiya Could you please address review feedback so we can process to commit.

#5 @vishalkakadiya
4 weeks ago

@mukesh27 I have addressed the feedback now. Thank you!

@westonruter commented on PR #10870:


4 weeks ago
#6

There's not actually any security hardening here, is there? The introduction of wp_unslash() simply prevents erroneous backslashes from showing up (as WP adds them to $_SERVER for back-compat reasons).

@vishalkakadiya commented on PR #10870:


3 weeks ago
#7

There's not actually any security hardening here, is there? The introduction of wp_unslash() simply prevents erroneous backslashes from showing up (as WP adds them to $_SERVER for back-compat reasons).

@westonruter Make sense, the ticket title may be confusing. But the goal is to sanitize the superglobal variables without directly using them in code. Do you have any suggestions/opinions on this?

@westonruter commented on PR #10870:


3 weeks ago
#8

The goal makes sense. It's more about data integrity, though.

#9 @westonruter
3 weeks ago

  • Description modified (diff)
  • Summary changed from Harden handling of PHP superglobals to prevent notices and potential security issues to Harden handling of PHP superglobals to prevent notices and potential data integrity issues

#10 @westonruter
3 weeks ago

  • Owner set to westonruter
  • Status changed from new to reviewing

#11 @westonruter
3 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 61606:

Site Health: Account for missing or slashed $_SERVER data in WP_Debug_Data.

Developed in https://github.com/WordPress/wordpress-develop/pull/10870

Follow-up to [56056], [45156], [44986]

Props vishalkakadiya, sabernhardt, peterwilsoncc, mukesh27, westonruter.
Fixes #64599.

#12 follow-up: @johnbillion
3 weeks ago

@vishalkakadiya What server configuration do you have that leads to REQUEST_TIME being missing from the $_SERVER superglobal please?

#13 @vishalkakadiya
3 weeks ago

@johnbillion Thanks for the question.

While $_SERVER['REQUEST_TIME'] is typically available in standard web server setups, it isn’t guaranteed across all environments. In particular, certain FastCGI/FPM configurations, proxied requests, CLI contexts (e.g., WP-CLI, cron, unit tests), or hardened server setups may not define it.

Since WordPress runs in a wide range of execution contexts, relying on $_SERVER['REQUEST_TIME'] without an existence check can potentially lead to undefined index notices in edge cases.

This change is intended as a small defensive hardening measure to ensure safer access to superglobals and improve robustness across diverse environments.

#14 @westonruter
3 weeks ago

@vishalkakadiya it seems to be available in the CLI context actually:

$ php -r 'var_dump($_SERVER["REQUEST_TIME"]);'
int(1770792603)

Have you found a specific PHP configuration where it is not available?

#15 @vishalkakadiya
3 weeks ago

@westonruter I haven't encountered a specific PHP configuration where REQUEST_TIME is missing.

This change is primarily part of a defensive coding approach — adding an existence check to guard against potential notices.

#16 in reply to: ↑ 12 @siliconforks
3 weeks ago

Replying to johnbillion:

What server configuration do you have that leads to REQUEST_TIME being missing from the $_SERVER superglobal please?

<?php
/*
Plugin Name: Very Bad Plugin
*/
unset( $_SERVER['REQUEST_TIME'] );

#17 @johnbillion
3 weeks ago

I think it's fine for this change to stay in now that it's in, and defensive programming certainly has value, but inventing hypothetical situations or configuration that's not actually seen in the wild isn't a great use of time when there are 8,000 open tickets that are better deserving of time from contributors.

Just something to bear in mind for the future. We don't need to work on hypothetical bugs when real ones remain unaddressed.

#18 @vishalkakadiya
3 weeks ago

@johnbillion Sure thing!

Note: See TracTickets for help on using tickets.