Edit File by line
/home/zeestwma/redstone.../wp-inclu...
File: http.php
* @param string $origin_arg Original origin string passed into is_allowed_http_origin function.
[500] Fix | Delete
*/
[501] Fix | Delete
return apply_filters( 'allowed_http_origin', $origin, $origin_arg );
[502] Fix | Delete
}
[503] Fix | Delete
[504] Fix | Delete
/**
[505] Fix | Delete
* Sends Access-Control-Allow-Origin and related headers if the current request
[506] Fix | Delete
* is from an allowed origin.
[507] Fix | Delete
*
[508] Fix | Delete
* If the request is an OPTIONS request, the script exits with either access
[509] Fix | Delete
* control headers sent, or a 403 response if the origin is not allowed. For
[510] Fix | Delete
* other request methods, you will receive a return value.
[511] Fix | Delete
*
[512] Fix | Delete
* @since 3.4.0
[513] Fix | Delete
*
[514] Fix | Delete
* @return string|false Returns the origin URL if headers are sent. Returns false
[515] Fix | Delete
* if headers are not sent.
[516] Fix | Delete
*/
[517] Fix | Delete
function send_origin_headers() {
[518] Fix | Delete
$origin = get_http_origin();
[519] Fix | Delete
[520] Fix | Delete
if ( is_allowed_http_origin( $origin ) ) {
[521] Fix | Delete
header( 'Access-Control-Allow-Origin: ' . $origin );
[522] Fix | Delete
header( 'Access-Control-Allow-Credentials: true' );
[523] Fix | Delete
if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
[524] Fix | Delete
exit;
[525] Fix | Delete
}
[526] Fix | Delete
return $origin;
[527] Fix | Delete
}
[528] Fix | Delete
[529] Fix | Delete
if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
[530] Fix | Delete
status_header( 403 );
[531] Fix | Delete
exit;
[532] Fix | Delete
}
[533] Fix | Delete
[534] Fix | Delete
return false;
[535] Fix | Delete
}
[536] Fix | Delete
[537] Fix | Delete
/**
[538] Fix | Delete
* Validates a URL as safe for use in the HTTP API.
[539] Fix | Delete
*
[540] Fix | Delete
* The only supported protocols are `http` and `https`.
[541] Fix | Delete
*
[542] Fix | Delete
* Examples of URLs that are considered unsafe:
[543] Fix | Delete
*
[544] Fix | Delete
* - `ftp://example.com/caniload.php` - Invalid protocol - only http and https are allowed.
[545] Fix | Delete
* - `http:///example.com/caniload.php` - Malformed URL.
[546] Fix | Delete
* - `http://user:pass@example.com/caniload.php` - Login information.
[547] Fix | Delete
* - `http://example.invalid/caniload.php` - Invalid hostname, as the IP cannot be looked up in DNS.
[548] Fix | Delete
*
[549] Fix | Delete
* Examples of URLs that are considered unsafe by default but can be allowed with filters:
[550] Fix | Delete
*
[551] Fix | Delete
* - `http://192.168.0.1/caniload.php` - IP address from LAN network.
[552] Fix | Delete
* This can be changed with the {@see 'http_request_host_is_external'} filter.
[553] Fix | Delete
* - `http://198.143.164.252:81/caniload.php` - By default, only ports 80, 443, and 8080 are allowed.
[554] Fix | Delete
* This can be changed with the {@see 'http_allowed_safe_ports'} filter.
[555] Fix | Delete
*
[556] Fix | Delete
* @since 3.5.2
[557] Fix | Delete
*
[558] Fix | Delete
* @param string $url Request URL.
[559] Fix | Delete
* @return string|false Returns false if the URL is not safe, or the original URL if it is safe.
[560] Fix | Delete
*/
[561] Fix | Delete
function wp_http_validate_url( $url ) {
[562] Fix | Delete
if ( ! is_string( $url ) || '' === $url || is_numeric( $url ) ) {
[563] Fix | Delete
return false;
[564] Fix | Delete
}
[565] Fix | Delete
[566] Fix | Delete
$original_url = $url;
[567] Fix | Delete
$url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) );
[568] Fix | Delete
if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) {
[569] Fix | Delete
return false;
[570] Fix | Delete
}
[571] Fix | Delete
[572] Fix | Delete
$parsed_url = parse_url( $url );
[573] Fix | Delete
if ( ! $parsed_url || empty( $parsed_url['host'] ) ) {
[574] Fix | Delete
return false;
[575] Fix | Delete
}
[576] Fix | Delete
[577] Fix | Delete
if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) {
[578] Fix | Delete
return false;
[579] Fix | Delete
}
[580] Fix | Delete
[581] Fix | Delete
if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) {
[582] Fix | Delete
return false;
[583] Fix | Delete
}
[584] Fix | Delete
[585] Fix | Delete
$parsed_home = parse_url( get_option( 'home' ) );
[586] Fix | Delete
$same_host = isset( $parsed_home['host'] ) && strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] );
[587] Fix | Delete
$host = trim( $parsed_url['host'], '.' );
[588] Fix | Delete
[589] Fix | Delete
if ( ! $same_host ) {
[590] Fix | Delete
if ( preg_match( '#^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$#', $host ) ) {
[591] Fix | Delete
$ip = $host;
[592] Fix | Delete
} else {
[593] Fix | Delete
$ip = gethostbyname( $host );
[594] Fix | Delete
if ( $ip === $host ) { // Error condition for gethostbyname().
[595] Fix | Delete
return false;
[596] Fix | Delete
}
[597] Fix | Delete
}
[598] Fix | Delete
if ( $ip ) {
[599] Fix | Delete
$parts = array_map( 'intval', explode( '.', $ip ) );
[600] Fix | Delete
if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0]
[601] Fix | Delete
|| ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
[602] Fix | Delete
|| ( 192 === $parts[0] && 168 === $parts[1] )
[603] Fix | Delete
) {
[604] Fix | Delete
// If host appears local, reject unless specifically allowed.
[605] Fix | Delete
/**
[606] Fix | Delete
* Checks if HTTP request is external or not.
[607] Fix | Delete
*
[608] Fix | Delete
* Allows to change and allow external requests for the HTTP request.
[609] Fix | Delete
*
[610] Fix | Delete
* @since 3.6.0
[611] Fix | Delete
*
[612] Fix | Delete
* @param bool $external Whether HTTP request is external or not.
[613] Fix | Delete
* @param string $host Host name of the requested URL.
[614] Fix | Delete
* @param string $url Requested URL.
[615] Fix | Delete
*/
[616] Fix | Delete
if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) {
[617] Fix | Delete
return false;
[618] Fix | Delete
}
[619] Fix | Delete
}
[620] Fix | Delete
}
[621] Fix | Delete
}
[622] Fix | Delete
[623] Fix | Delete
if ( empty( $parsed_url['port'] ) ) {
[624] Fix | Delete
return $url;
[625] Fix | Delete
}
[626] Fix | Delete
[627] Fix | Delete
$port = $parsed_url['port'];
[628] Fix | Delete
[629] Fix | Delete
/**
[630] Fix | Delete
* Controls the list of ports considered safe in HTTP API.
[631] Fix | Delete
*
[632] Fix | Delete
* Allows to change and allow external requests for the HTTP request.
[633] Fix | Delete
*
[634] Fix | Delete
* @since 5.9.0
[635] Fix | Delete
*
[636] Fix | Delete
* @param int[] $allowed_ports Array of integers for valid ports. Default allowed ports
[637] Fix | Delete
* are 80, 443, and 8080.
[638] Fix | Delete
* @param string $host Host name of the requested URL.
[639] Fix | Delete
* @param string $url Requested URL.
[640] Fix | Delete
*/
[641] Fix | Delete
$allowed_ports = apply_filters( 'http_allowed_safe_ports', array( 80, 443, 8080 ), $host, $url );
[642] Fix | Delete
if ( is_array( $allowed_ports ) && in_array( $port, $allowed_ports, true ) ) {
[643] Fix | Delete
return $url;
[644] Fix | Delete
}
[645] Fix | Delete
[646] Fix | Delete
if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) {
[647] Fix | Delete
return $url;
[648] Fix | Delete
}
[649] Fix | Delete
[650] Fix | Delete
return false;
[651] Fix | Delete
}
[652] Fix | Delete
[653] Fix | Delete
/**
[654] Fix | Delete
* Marks allowed redirect hosts safe for HTTP requests as well.
[655] Fix | Delete
*
[656] Fix | Delete
* Attached to the {@see 'http_request_host_is_external'} filter.
[657] Fix | Delete
*
[658] Fix | Delete
* @since 3.6.0
[659] Fix | Delete
*
[660] Fix | Delete
* @param bool $is_external
[661] Fix | Delete
* @param string $host
[662] Fix | Delete
* @return bool
[663] Fix | Delete
*/
[664] Fix | Delete
function allowed_http_request_hosts( $is_external, $host ) {
[665] Fix | Delete
if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) {
[666] Fix | Delete
$is_external = true;
[667] Fix | Delete
}
[668] Fix | Delete
return $is_external;
[669] Fix | Delete
}
[670] Fix | Delete
[671] Fix | Delete
/**
[672] Fix | Delete
* Adds any domain in a multisite installation for safe HTTP requests to the
[673] Fix | Delete
* allowed list.
[674] Fix | Delete
*
[675] Fix | Delete
* Attached to the {@see 'http_request_host_is_external'} filter.
[676] Fix | Delete
*
[677] Fix | Delete
* @since 3.6.0
[678] Fix | Delete
*
[679] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[680] Fix | Delete
*
[681] Fix | Delete
* @param bool $is_external
[682] Fix | Delete
* @param string $host
[683] Fix | Delete
* @return bool
[684] Fix | Delete
*/
[685] Fix | Delete
function ms_allowed_http_request_hosts( $is_external, $host ) {
[686] Fix | Delete
global $wpdb;
[687] Fix | Delete
static $queried = array();
[688] Fix | Delete
if ( $is_external ) {
[689] Fix | Delete
return $is_external;
[690] Fix | Delete
}
[691] Fix | Delete
if ( get_network()->domain === $host ) {
[692] Fix | Delete
return true;
[693] Fix | Delete
}
[694] Fix | Delete
if ( isset( $queried[ $host ] ) ) {
[695] Fix | Delete
return $queried[ $host ];
[696] Fix | Delete
}
[697] Fix | Delete
$queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) );
[698] Fix | Delete
return $queried[ $host ];
[699] Fix | Delete
}
[700] Fix | Delete
[701] Fix | Delete
/**
[702] Fix | Delete
* A wrapper for PHP's parse_url() function that handles consistency in the return values
[703] Fix | Delete
* across PHP versions.
[704] Fix | Delete
*
[705] Fix | Delete
* Across various PHP versions, schemeless URLs containing a ":" in the query
[706] Fix | Delete
* are being handled inconsistently. This function works around those differences.
[707] Fix | Delete
*
[708] Fix | Delete
* @since 4.4.0
[709] Fix | Delete
* @since 4.7.0 The `$component` parameter was added for parity with PHP's `parse_url()`.
[710] Fix | Delete
*
[711] Fix | Delete
* @link https://www.php.net/manual/en/function.parse-url.php
[712] Fix | Delete
*
[713] Fix | Delete
* @param string $url The URL to parse.
[714] Fix | Delete
* @param int $component The specific component to retrieve. Use one of the PHP
[715] Fix | Delete
* predefined constants to specify which one.
[716] Fix | Delete
* Defaults to -1 (= return all parts as an array).
[717] Fix | Delete
* @return mixed False on parse failure; Array of URL components on success;
[718] Fix | Delete
* When a specific component has been requested: null if the component
[719] Fix | Delete
* doesn't exist in the given URL; a string or - in the case of
[720] Fix | Delete
* PHP_URL_PORT - integer when it does. See parse_url()'s return values.
[721] Fix | Delete
*/
[722] Fix | Delete
function wp_parse_url( $url, $component = -1 ) {
[723] Fix | Delete
$to_unset = array();
[724] Fix | Delete
$url = (string) $url;
[725] Fix | Delete
[726] Fix | Delete
if ( str_starts_with( $url, '//' ) ) {
[727] Fix | Delete
$to_unset[] = 'scheme';
[728] Fix | Delete
$url = 'placeholder:' . $url;
[729] Fix | Delete
} elseif ( str_starts_with( $url, '/' ) ) {
[730] Fix | Delete
$to_unset[] = 'scheme';
[731] Fix | Delete
$to_unset[] = 'host';
[732] Fix | Delete
$url = 'placeholder://placeholder' . $url;
[733] Fix | Delete
}
[734] Fix | Delete
[735] Fix | Delete
$parts = parse_url( $url );
[736] Fix | Delete
[737] Fix | Delete
if ( false === $parts ) {
[738] Fix | Delete
// Parsing failure.
[739] Fix | Delete
return $parts;
[740] Fix | Delete
}
[741] Fix | Delete
[742] Fix | Delete
// Remove the placeholder values.
[743] Fix | Delete
foreach ( $to_unset as $key ) {
[744] Fix | Delete
unset( $parts[ $key ] );
[745] Fix | Delete
}
[746] Fix | Delete
[747] Fix | Delete
return _get_component_from_parsed_url_array( $parts, $component );
[748] Fix | Delete
}
[749] Fix | Delete
[750] Fix | Delete
/**
[751] Fix | Delete
* Retrieves a specific component from a parsed URL array.
[752] Fix | Delete
*
[753] Fix | Delete
* @internal
[754] Fix | Delete
*
[755] Fix | Delete
* @since 4.7.0
[756] Fix | Delete
* @access private
[757] Fix | Delete
*
[758] Fix | Delete
* @link https://www.php.net/manual/en/function.parse-url.php
[759] Fix | Delete
*
[760] Fix | Delete
* @param array|false $url_parts The parsed URL. Can be false if the URL failed to parse.
[761] Fix | Delete
* @param int $component The specific component to retrieve. Use one of the PHP
[762] Fix | Delete
* predefined constants to specify which one.
[763] Fix | Delete
* Defaults to -1 (= return all parts as an array).
[764] Fix | Delete
* @return mixed False on parse failure; Array of URL components on success;
[765] Fix | Delete
* When a specific component has been requested: null if the component
[766] Fix | Delete
* doesn't exist in the given URL; a string or - in the case of
[767] Fix | Delete
* PHP_URL_PORT - integer when it does. See parse_url()'s return values.
[768] Fix | Delete
*/
[769] Fix | Delete
function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) {
[770] Fix | Delete
if ( -1 === $component ) {
[771] Fix | Delete
return $url_parts;
[772] Fix | Delete
}
[773] Fix | Delete
[774] Fix | Delete
$key = _wp_translate_php_url_constant_to_key( $component );
[775] Fix | Delete
if ( false !== $key && is_array( $url_parts ) && isset( $url_parts[ $key ] ) ) {
[776] Fix | Delete
return $url_parts[ $key ];
[777] Fix | Delete
} else {
[778] Fix | Delete
return null;
[779] Fix | Delete
}
[780] Fix | Delete
}
[781] Fix | Delete
[782] Fix | Delete
/**
[783] Fix | Delete
* Translates a PHP_URL_* constant to the named array keys PHP uses.
[784] Fix | Delete
*
[785] Fix | Delete
* @internal
[786] Fix | Delete
*
[787] Fix | Delete
* @since 4.7.0
[788] Fix | Delete
* @access private
[789] Fix | Delete
*
[790] Fix | Delete
* @link https://www.php.net/manual/en/url.constants.php
[791] Fix | Delete
*
[792] Fix | Delete
* @param int $constant PHP_URL_* constant.
[793] Fix | Delete
* @return string|false The named key or false.
[794] Fix | Delete
*/
[795] Fix | Delete
function _wp_translate_php_url_constant_to_key( $constant ) {
[796] Fix | Delete
$translation = array(
[797] Fix | Delete
PHP_URL_SCHEME => 'scheme',
[798] Fix | Delete
PHP_URL_HOST => 'host',
[799] Fix | Delete
PHP_URL_PORT => 'port',
[800] Fix | Delete
PHP_URL_USER => 'user',
[801] Fix | Delete
PHP_URL_PASS => 'pass',
[802] Fix | Delete
PHP_URL_PATH => 'path',
[803] Fix | Delete
PHP_URL_QUERY => 'query',
[804] Fix | Delete
PHP_URL_FRAGMENT => 'fragment',
[805] Fix | Delete
);
[806] Fix | Delete
[807] Fix | Delete
if ( isset( $translation[ $constant ] ) ) {
[808] Fix | Delete
return $translation[ $constant ];
[809] Fix | Delete
} else {
[810] Fix | Delete
return false;
[811] Fix | Delete
}
[812] Fix | Delete
}
[813] Fix | Delete
[814] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function