Skip to content

Commit c18151e

Browse files
committed
Bad Requests: Silence pentester requests against profiles, junk in junk out, that's out it works.
git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14922 74240141-8908-4e6f-9713-ba540dce6ec7
1 parent 2cd43a8 commit c18151e

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,76 @@ function check_for_invalid_query_vars( $vars, $ref = '$public_query_vars' ) {
168168
}
169169
}, 9 );
170170

171+
/**
172+
* Detect invalid query parameters being passed in BuddyPress fields on requests that BuddyPress is intercepting.
173+
*
174+
* The component directory search forms (e.g. bp_directory_groups_search_form())
175+
* pass `$_REQUEST[ "{component}_search" ]` straight into stripslashes(), which
176+
* fatals when a scanner submits it as an array (e.g. `groups_search[]=the`).
177+
*/
178+
add_action( 'bp_template_redirect', function() {
179+
$expected_string_fields = [
180+
'members_search',
181+
'groups_search',
182+
'blogs_search',
183+
'activity_search',
184+
'forums_search',
185+
];
186+
187+
foreach ( $expected_string_fields as $field ) {
188+
if ( isset( $_REQUEST[ $field ] ) && ! is_scalar( $_REQUEST[ $field ] ) ) {
189+
die_bad_request( "non-scalar $field in buddypress \$_REQUEST" );
190+
}
191+
}
192+
}, -1 );
193+
194+
/**
195+
* Detect invalid input to the bp-classic (BP Default theme) directory AJAX handlers.
196+
*
197+
* The members/groups/blogs/forums directory filters and the activity loaders
198+
* pass these POST fields straight into string functions without type checks —
199+
* sanitize_title( $_POST['object'] ) and urldecode( $_POST['cookie'] ) — and
200+
* fatal when a vulnerability scanner submits them as arrays, e.g.
201+
* `object[]=groups` or `cookie[]=…`.
202+
*
203+
* @see bp_dtheme_object_template_loader(), bp_dtheme_ajax_querystring()
204+
*/
205+
add_action( 'admin_init', function() {
206+
// admin-ajax.php fires admin_init before the wp_ajax_{action} dispatch, so
207+
// this runs before bp_dtheme_object_template_loader() and friends.
208+
if ( ! wp_doing_ajax() || empty( $_REQUEST['action'] ) ) {
209+
return;
210+
}
211+
212+
$bp_classic_ajax_actions = [
213+
'blogs_filter',
214+
'forums_filter',
215+
'groups_filter',
216+
'members_filter',
217+
'activity_get_older_updates',
218+
'activity_widget_filter',
219+
];
220+
221+
if ( ! in_array( $_REQUEST['action'], $bp_classic_ajax_actions, true ) ) {
222+
return;
223+
}
224+
225+
$scalar_fields = [
226+
'object',
227+
'cookie',
228+
'filter',
229+
'scope',
230+
'page',
231+
'search_terms',
232+
];
233+
234+
foreach ( $scalar_fields as $field ) {
235+
if ( isset( $_POST[ $field ] ) && ! is_scalar( $_POST[ $field ] ) ) {
236+
die_bad_request( "non-scalar $field in bp-classic directory AJAX" );
237+
}
238+
}
239+
} );
240+
171241
/**
172242
* Detect badly formed XMLRPC requests.
173243
* pingback.ping is not a valid multicall target, blocking due to the excessive requests.

0 commit comments

Comments
 (0)