← All changes
|
jetpack_vendor/automattic/jetpack-waf/src/functions.php
+48
-0
13.5.2
→
16.3-beta
View file →
| @@ -69,4 +69,52 @@ | ||
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | return $return; |
| 72 | 72 | } |
| 73 | + | |
| 74 | +/** | |
| 75 | + * Polyfill for getallheaders, which is not available in all PHP environments. | |
| 76 | + * | |
| 77 | + * @link https://github.com/ralouphie/getallheaders | |
| 78 | + */ | |
| 79 | +if ( ! function_exists( 'getallheaders' ) ) { | |
| 80 | + /** | |
| 81 | + * Get all HTTP header key/values as an associative array for the current request. | |
| 82 | + * | |
| 83 | + * @return array The HTTP header key/value pairs. | |
| 84 | + */ | |
| 85 | + function getallheaders() { | |
| 86 | + // phpcs:disable WordPress.Security.ValidatedSanitizedInput | |
| 87 | + $headers = array(); | |
| 88 | + | |
| 89 | + $copy_server = array( | |
| 90 | + 'CONTENT_TYPE' => 'Content-Type', | |
| 91 | + 'CONTENT_LENGTH' => 'Content-Length', | |
| 92 | + 'CONTENT_MD5' => 'Content-Md5', | |
| 93 | + ); | |
| 94 | + | |
| 95 | + foreach ( $_SERVER as $key => $value ) { | |
| 96 | + if ( substr( $key, 0, 5 ) === 'HTTP_' ) { | |
| 97 | + $key = substr( $key, 5 ); | |
| 98 | + if ( ! isset( $copy_server[ $key ] ) || ! isset( $_SERVER[ $key ] ) ) { | |
| 99 | + $key = str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', $key ) ) ) ); | |
| 100 | + $headers[ $key ] = $value; | |
| 101 | + } | |
| 102 | + } elseif ( isset( $copy_server[ $key ] ) ) { | |
| 103 | + $headers[ $copy_server[ $key ] ] = $value; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + if ( ! isset( $headers['Authorization'] ) ) { | |
| 108 | + if ( isset( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ) ) { | |
| 109 | + $headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; | |
| 110 | + } elseif ( isset( $_SERVER['PHP_AUTH_USER'] ) ) { | |
| 111 | + $basic_pass = $_SERVER['PHP_AUTH_PW'] ?? ''; | |
| 112 | + $headers['Authorization'] = 'Basic ' . base64_encode( $_SERVER['PHP_AUTH_USER'] . ':' . $basic_pass ); | |
| 113 | + } elseif ( isset( $_SERVER['PHP_AUTH_DIGEST'] ) ) { | |
| 114 | + $headers['Authorization'] = $_SERVER['PHP_AUTH_DIGEST']; | |
| 115 | + } | |
| 116 | + } | |
| 117 | + | |
| 118 | + return $headers; | |
| 119 | + } | |
| 120 | +} | |