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