diff --git a/api.wordpress.org/public_html/translations/core/1.0/index.php b/api.wordpress.org/public_html/translations/core/1.0/index.php index e639ed9216..0333319a2b 100644 --- a/api.wordpress.org/public_html/translations/core/1.0/index.php +++ b/api.wordpress.org/public_html/translations/core/1.0/index.php @@ -1,4 +1,14 @@ array( + 'regexp' => '/^[0-9][a-z0-9._-]{0,99}\z/i', + ), + ) + ); if ( empty( $version ) || ! is_string( $version ) || ! is_numeric( $version[0] ) ) { - header( $_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request' ); + http_response_code( 400 ); die( '?version= must be a valid WordPress version' ); } @@ -23,7 +42,7 @@ header( 'Access-Control-Allow-Origin: *' ); header( 'Access-Control-Expose-Headers: X-Translations-Count' ); header( 'X-Translations-Count:' . count( $translations ) ); -if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] ) { +if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'HEAD' === $_SERVER['REQUEST_METHOD'] ) { exit; } @@ -32,4 +51,3 @@ echo json_encode( array( 'translations' => $translations ) ); exit; - diff --git a/api.wordpress.org/public_html/translations/plugins/1.0/index.php b/api.wordpress.org/public_html/translations/plugins/1.0/index.php index e840f47706..6998ac96ea 100644 --- a/api.wordpress.org/public_html/translations/plugins/1.0/index.php +++ b/api.wordpress.org/public_html/translations/plugins/1.0/index.php @@ -1,4 +1,14 @@ array( + 'regexp' => '/^[a-z0-9._-]{1,100}\z/i', + ), + ) +) : ''; +$version = isset( $_REQUEST['version'] ) ? filter_var( + $_REQUEST['version'], + FILTER_VALIDATE_REGEXP, + array( + 'options' => array( + 'regexp' => '/^[a-z0-9._-]{1,100}\z/i', + ), + ) +) : null; + +if ( isset( $_REQUEST['slug'] ) && ! is_string( $slug ) ) { + http_response_code( 400 ); + die( '?slug= invalid.' ); +} -foreach ( [ 'slug', 'version' ] as $field ) { - if ( $$field && ! is_string( $$field ) ) { - header( $_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request' ); - die( "?{$field}= invalid." ); - } +if ( isset( $_REQUEST['version'] ) && ! is_string( $version ) ) { + http_response_code( 400 ); + die( '?version= invalid.' ); } $translations = find_all_translations_for_type_and_domain( 'plugin', $slug, $version ); @@ -24,4 +54,3 @@ echo json_encode( array( 'translations' => $translations ) ); exit; - diff --git a/api.wordpress.org/public_html/translations/themes/1.0/index.php b/api.wordpress.org/public_html/translations/themes/1.0/index.php index f23a748eb8..30f9cc7f9d 100644 --- a/api.wordpress.org/public_html/translations/themes/1.0/index.php +++ b/api.wordpress.org/public_html/translations/themes/1.0/index.php @@ -1,4 +1,14 @@ array( + 'regexp' => '/^[a-z0-9._-]{1,100}\z/i', + ), + ) +) : ''; +$version = isset( $_REQUEST['version'] ) ? filter_var( + $_REQUEST['version'], + FILTER_VALIDATE_REGEXP, + array( + 'options' => array( + 'regexp' => '/^[a-z0-9._-]{1,100}\z/i', + ), + ) +) : null; + +if ( isset( $_REQUEST['slug'] ) && ! is_string( $slug ) ) { + http_response_code( 400 ); + die( '?slug= invalid.' ); +} -foreach ( [ 'slug', 'version' ] as $field ) { - if ( $$field && ! is_string( $$field ) ) { - header( $_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request' ); - die( "?{$field}= invalid." ); - } +if ( isset( $_REQUEST['version'] ) && ! is_string( $version ) ) { + http_response_code( 400 ); + die( '?version= invalid.' ); } $translations = find_all_translations_for_type_and_domain( 'theme', $slug, $version ); @@ -24,4 +54,3 @@ echo json_encode( array( 'translations' => $translations ) ); exit; -