Changeset 15016
- Timestamp:
- 07/28/2026 09:04:15 PM (12 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/events/1.0/index.php
r14998 r15016 195 195 foreach ( $must_be_strings as $field ) { 196 196 if ( isset( $_GET[ $field ] ) && ! is_scalar( $_GET[ $field ] ) ) { 197 header( $_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400 ); 198 die( '{"error":"Bad request.","reason":"' . $field . ' must be of type string."}' ); 197 send_bad_request( $field . ' must be of type string.' ); 199 198 } 200 199 } 201 200 202 201 if ( ! empty( $_POST['location_data'] ) ) { 203 foreach ( $_POST['location_data'] as $field => $value ) { 202 // phpcs:ignore WordPress.Security -- Public unauthenticated endpoint; the value is only type-checked here, never used or output. 203 foreach ( $_POST['location_data'] as $value ) { 204 204 if ( ! is_scalar( $value ) ) { 205 header( $_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400 );206 die( '{"error":"Bad request.","reason":"' . $field . ' must be of type string."}' );205 // The key is omitted from the message because it is unsanitized request input. 206 send_bad_request( 'location_data values must be of type string.' ); 207 207 } 208 208 } 209 209 } 210 } 211 212 /** 213 * Send a 400 Bad Request response and halt. 214 * 215 * The `Content-Type` is set explicitly, because the header that `send_response()` sets is only 216 * reached on the success path, and PHP would otherwise default this body to `text/html`. 217 * 218 * `wp_json_encode()` is intentionally not used here; it is loaded by `bootstrap()`, which runs 219 * after the request is validated. 220 * 221 * @param string $reason The reason the request was rejected. Must not contain any unescaped 222 * request input. 223 */ 224 function send_bad_request( $reason ) { 225 $body = array( 226 'error' => 'Bad request.', 227 'reason' => $reason, 228 ); 229 230 http_response_code( 400 ); 231 header( 'Content-Type: application/json; charset=UTF-8' ); 232 header( 'X-Content-Type-Options: nosniff' ); 233 234 // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode -- No WP loaded. 235 die( json_encode( $body ) ); 210 236 } 211 237
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)