Skip to content

Commit ca1f77a

Browse files
committed
Bad Requests: Avoid PHP Warnings & Fatals from invalid input in year, monthnum and day fields.
This includes: - `E_WARNING: Array to string conversion in wp-includes/post.php:6072` - `Uncaught TypeError: urldecode(): Argument #1 ($string) must be of type string, array given in wp-includes/post.php:6083` See https://core.trac.wordpress.org/ticket/62828 git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14416 74240141-8908-4e6f-9713-ba540dce6ec7
1 parent d6ad551 commit ca1f77a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

wordpress.org/public_html/wp-content/mu-plugins/pub/wporg-bad-request.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@
4040
check_for_invalid_query_vars( $wp->query_vars, '$public_query_vars' );
4141
}, 0 );
4242

43+
/**
44+
* Detect invalid query parameters being passed in Core query fields, before the 'request' action.
45+
* Generally causing warnings & fatals in `wp_resolve_numeric_slug_conflicts()`.
46+
*/
47+
add_filter( 'do_parse_request', function( $process ) {
48+
if ( $process ) {
49+
// See https://github.com/WordPress/wordpress-develop/blob/50fb4086b7afbfa012c5d1f2eeff79b1bae3b00e/src/wp-includes/rewrite.php#L400-L407
50+
$wp_resolve_numeric_slug_conflict_fields = [
51+
'year',
52+
'monthnum',
53+
'day'
54+
];
55+
56+
foreach ( $wp_resolve_numeric_slug_conflict_fields as $field ) {
57+
if ( isset( $_REQUEST[ $field ] ) && ! is_scalar( $_REQUEST[ $field ] ) ) {
58+
die_bad_request( "non-scalar $field in do_parse_request" );
59+
}
60+
}
61+
}
62+
63+
return $process;
64+
}, 1001 );
65+
4366
/**
4467
* Check a set of internal query variables against the WordPress WP_Query values to detect invalid input.
4568
*/

0 commit comments

Comments
 (0)