Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/StoreApi
File: Authentication.php
<?php
[0] Fix | Delete
declare( strict_types=1 );
[1] Fix | Delete
namespace Automattic\WooCommerce\StoreApi;
[2] Fix | Delete
[3] Fix | Delete
use Automattic\WooCommerce\StoreApi\Utilities\RateLimits;
[4] Fix | Delete
use Automattic\WooCommerce\StoreApi\Utilities\CartTokenUtils;
[5] Fix | Delete
use Automattic\WooCommerce\Utilities\FeaturesUtil;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Authentication class.
[9] Fix | Delete
*/
[10] Fix | Delete
class Authentication {
[11] Fix | Delete
/**
[12] Fix | Delete
* Hook into WP lifecycle events. This is hooked by the StoreAPI class on `rest_api_init`.
[13] Fix | Delete
*/
[14] Fix | Delete
public function init() {
[15] Fix | Delete
if ( ! $this->is_request_to_store_api() ) {
[16] Fix | Delete
return;
[17] Fix | Delete
}
[18] Fix | Delete
add_filter( 'rest_authentication_errors', array( $this, 'check_authentication' ) );
[19] Fix | Delete
add_filter( 'rest_authentication_errors', array( $this, 'opt_in_checkout_endpoint' ), 9, 1 );
[20] Fix | Delete
add_action( 'set_logged_in_cookie', array( $this, 'set_logged_in_cookie' ) );
[21] Fix | Delete
add_filter( 'rest_pre_serve_request', array( $this, 'send_cors_headers' ), 10, 4 );
[22] Fix | Delete
add_filter( 'rest_allowed_cors_headers', array( $this, 'allowed_cors_headers' ) );
[23] Fix | Delete
add_filter( 'rest_exposed_cors_headers', array( $this, 'exposed_cors_headers' ) );
[24] Fix | Delete
[25] Fix | Delete
// Remove the default CORS headers--we will add our own.
[26] Fix | Delete
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Add allowed cors headers for store API headers.
[31] Fix | Delete
*
[32] Fix | Delete
* @param array $allowed_headers Allowed headers.
[33] Fix | Delete
* @return array
[34] Fix | Delete
*/
[35] Fix | Delete
public function allowed_cors_headers( $allowed_headers ) {
[36] Fix | Delete
$allowed_headers[] = 'Cart-Token';
[37] Fix | Delete
$allowed_headers[] = 'Nonce';
[38] Fix | Delete
return $allowed_headers;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Use the Store API session handler when a valid Cart-Token is present.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 10.6.0
[45] Fix | Delete
* @param string $handler Session handler class name.
[46] Fix | Delete
* @return string
[47] Fix | Delete
*/
[48] Fix | Delete
public function maybe_use_store_api_session_handler( $handler ): string {
[49] Fix | Delete
if ( ! WC()->is_store_api_request() && ! $this->has_store_api_route_as_get_parameter() ) {
[50] Fix | Delete
return $handler;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$cart_token = wc_clean( wp_unslash( $_SERVER['HTTP_CART_TOKEN'] ?? '' ) );
[54] Fix | Delete
$cart_token = is_string( $cart_token ) ? $cart_token : '';
[55] Fix | Delete
if ( $cart_token && CartTokenUtils::validate_cart_token( $cart_token ) ) {
[56] Fix | Delete
return SessionHandler::class;
[57] Fix | Delete
}
[58] Fix | Delete
return $handler;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Expose Store API headers in CORS responses.
[63] Fix | Delete
* We're explicitly exposing the Cart-Token, not the nonce. Only one of them is needed.
[64] Fix | Delete
*
[65] Fix | Delete
* @param array $exposed_headers Exposed headers.
[66] Fix | Delete
* @return array
[67] Fix | Delete
*/
[68] Fix | Delete
public function exposed_cors_headers( $exposed_headers ) {
[69] Fix | Delete
$exposed_headers[] = 'Cart-Token';
[70] Fix | Delete
return $exposed_headers;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Add CORS headers to a response object.
[75] Fix | Delete
*
[76] Fix | Delete
* These checks prevent access to the Store API from non-allowed origins. By default, the WordPress REST API allows
[77] Fix | Delete
* access from any origin. Because some Store API routes return PII, we need to add our own CORS headers.
[78] Fix | Delete
*
[79] Fix | Delete
* Allowed origins can be changed using the WordPress `allowed_http_origins` or `allowed_http_origin` filters if
[80] Fix | Delete
* access needs to be granted to other domains.
[81] Fix | Delete
*
[82] Fix | Delete
* Users of valid Cart Tokens are also allowed access from any origin.
[83] Fix | Delete
*
[84] Fix | Delete
* @param bool $served Whether the request has already been served.
[85] Fix | Delete
* @param \WP_REST_Response $result The response object.
[86] Fix | Delete
* @param \WP_REST_Request $request The request object.
[87] Fix | Delete
* @param \WP_REST_Server $server The REST server instance.
[88] Fix | Delete
* @return bool
[89] Fix | Delete
*/
[90] Fix | Delete
public function send_cors_headers( $served, $result, $request, $server ) {
[91] Fix | Delete
$origin = get_http_origin();
[92] Fix | Delete
[93] Fix | Delete
if ( 'null' !== $origin ) {
[94] Fix | Delete
$origin = esc_url_raw( $origin );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// Send standard CORS headers.
[98] Fix | Delete
$server->send_header( 'Access-Control-Allow-Methods', 'OPTIONS, GET, POST, PUT, PATCH, DELETE' );
[99] Fix | Delete
$server->send_header( 'Access-Control-Allow-Credentials', 'true' );
[100] Fix | Delete
$server->send_header( 'Vary', 'Origin', false );
[101] Fix | Delete
[102] Fix | Delete
// Allow preflight requests, certain http origins, and any origin if a cart token is present. Preflight requests
[103] Fix | Delete
// are allowed because we'll be unable to validate cart token headers at that point.
[104] Fix | Delete
if ( $this->is_preflight() || CartTokenUtils::validate_cart_token( $this->get_cart_token( $request ) ) || is_allowed_http_origin( $origin ) ) {
[105] Fix | Delete
$server->send_header( 'Access-Control-Allow-Origin', $origin );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
// Exit early during preflight requests. This is so someone cannot access API data by sending an OPTIONS request
[109] Fix | Delete
// with preflight headers and a _GET property to override the method.
[110] Fix | Delete
if ( $this->is_preflight() ) {
[111] Fix | Delete
exit;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return $served;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Checks if the request has a store API route as a GET `rest_route` parameter.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 10.6.0
[121] Fix | Delete
* @return bool
[122] Fix | Delete
*/
[123] Fix | Delete
protected function has_store_api_route_as_get_parameter(): bool {
[124] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Store API
[125] Fix | Delete
if ( ! isset( $_GET['rest_route'] ) || ! is_string( $_GET['rest_route'] ) ) {
[126] Fix | Delete
return false;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Store API context check.
[130] Fix | Delete
$rest_route = rawurldecode( esc_url_raw( wp_unslash( $_GET['rest_route'] ) ) );
[131] Fix | Delete
return 0 === strpos( $rest_route, '/wc/store/' );
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Is the request a preflight request? Checks the request method
[136] Fix | Delete
*
[137] Fix | Delete
* @return boolean
[138] Fix | Delete
*/
[139] Fix | Delete
protected function is_preflight() {
[140] Fix | Delete
return isset( $_SERVER['REQUEST_METHOD'], $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'], $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'], $_SERVER['HTTP_ORIGIN'] ) && 'OPTIONS' === $_SERVER['REQUEST_METHOD'];
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Gets the cart token from the request header.
[145] Fix | Delete
*
[146] Fix | Delete
* @param \WP_REST_Request $request The REST request instance.
[147] Fix | Delete
* @return string
[148] Fix | Delete
*/
[149] Fix | Delete
protected function get_cart_token( \WP_REST_Request $request ) {
[150] Fix | Delete
return wc_clean( wp_unslash( $request->get_header( 'Cart-Token' ) ?? '' ) );
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* The Store API does not require authentication.
[155] Fix | Delete
*
[156] Fix | Delete
* @param \WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not.
[157] Fix | Delete
* @return \WP_Error|null|bool
[158] Fix | Delete
*/
[159] Fix | Delete
public function check_authentication( $result ) {
[160] Fix | Delete
// Enable Rate Limiting for logged-in users without 'edit posts' capability.
[161] Fix | Delete
if ( ! current_user_can( 'edit_posts' ) ) {
[162] Fix | Delete
$result = $this->apply_rate_limiting( $result );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
// Pass through errors from other authentication methods used before this one.
[166] Fix | Delete
return ! empty( $result ) ? $result : true;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* When the login cookies are set, they are not available until the next page reload. For the Store API, specifically
[171] Fix | Delete
* for returning updated nonces, we need this to be available immediately.
[172] Fix | Delete
*
[173] Fix | Delete
* @param string $logged_in_cookie The value for the logged in cookie.
[174] Fix | Delete
*/
[175] Fix | Delete
public function set_logged_in_cookie( $logged_in_cookie ) {
[176] Fix | Delete
if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
[177] Fix | Delete
return;
[178] Fix | Delete
}
[179] Fix | Delete
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Opt in to rate limiting for the checkout endpoint.
[184] Fix | Delete
*
[185] Fix | Delete
* @param \WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not.
[186] Fix | Delete
* @return \WP_Error|null|bool
[187] Fix | Delete
*/
[188] Fix | Delete
public function opt_in_checkout_endpoint( $result ) {
[189] Fix | Delete
if (
[190] Fix | Delete
FeaturesUtil::feature_is_enabled( 'rate_limit_checkout' )
[191] Fix | Delete
&& $this->is_request_to_store_api()
[192] Fix | Delete
&& preg_match( '#/wc/store(?:/v\d+)?/checkout#', $GLOBALS['wp']->query_vars['rest_route'] )
[193] Fix | Delete
&& $this->is_only_post_request()
[194] Fix | Delete
) {
[195] Fix | Delete
add_filter(
[196] Fix | Delete
'woocommerce_store_api_rate_limit_options',
[197] Fix | Delete
function ( $options ) {
[198] Fix | Delete
$options['enabled'] = true;
[199] Fix | Delete
$options['limit'] = 3;
[200] Fix | Delete
$options['seconds'] = 60;
[201] Fix | Delete
return $options;
[202] Fix | Delete
},
[203] Fix | Delete
1,
[204] Fix | Delete
1
[205] Fix | Delete
);
[206] Fix | Delete
}
[207] Fix | Delete
return $result;
[208] Fix | Delete
}
[209] Fix | Delete
/**
[210] Fix | Delete
* Applies Rate Limiting to the request, and passes through any errors from other authentication methods used before this one.
[211] Fix | Delete
*
[212] Fix | Delete
* @param \WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not.
[213] Fix | Delete
* @return \WP_Error|null|bool
[214] Fix | Delete
*/
[215] Fix | Delete
protected function apply_rate_limiting( $result ) {
[216] Fix | Delete
$rate_limiting_options = RateLimits::get_options();
[217] Fix | Delete
[218] Fix | Delete
if ( $rate_limiting_options->enabled ) {
[219] Fix | Delete
$action_id = 'store_api_request_' . self::get_rate_limiting_id( $rate_limiting_options->proxy_support );
[220] Fix | Delete
[221] Fix | Delete
$retry = RateLimits::is_exceeded_retry_after( $action_id );
[222] Fix | Delete
$server = rest_get_server();
[223] Fix | Delete
$server->send_header( 'RateLimit-Limit', $rate_limiting_options->limit );
[224] Fix | Delete
[225] Fix | Delete
if ( false !== $retry ) {
[226] Fix | Delete
$server->send_header( 'RateLimit-Remaining', 0 );
[227] Fix | Delete
$server->send_header( 'RateLimit-Retry-After', $retry );
[228] Fix | Delete
$server->send_header( 'RateLimit-Reset', time() + $retry );
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Fires when the rate limit is exceeded.
[232] Fix | Delete
*
[233] Fix | Delete
* @param string $ip_address The IP address of the request.
[234] Fix | Delete
* @param string $action_id The grouping identifier to the request.
[235] Fix | Delete
*
[236] Fix | Delete
* @since 8.9.0
[237] Fix | Delete
* @since 9.8.0 Added $action_id parameter.
[238] Fix | Delete
*/
[239] Fix | Delete
do_action(
[240] Fix | Delete
'woocommerce_store_api_rate_limit_exceeded',
[241] Fix | Delete
self::get_ip_address( $rate_limiting_options->proxy_support ),
[242] Fix | Delete
$action_id
[243] Fix | Delete
);
[244] Fix | Delete
[245] Fix | Delete
return new \WP_Error(
[246] Fix | Delete
'rate_limit_exceeded',
[247] Fix | Delete
sprintf(
[248] Fix | Delete
'Too many requests. Please wait %d seconds before trying again.',
[249] Fix | Delete
$retry
[250] Fix | Delete
),
[251] Fix | Delete
array( 'status' => 400 )
[252] Fix | Delete
);
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
$rate_limit = RateLimits::update_rate_limit( $action_id );
[256] Fix | Delete
$server->send_header( 'RateLimit-Remaining', $rate_limit->remaining );
[257] Fix | Delete
$server->send_header( 'RateLimit-Reset', $rate_limit->reset );
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
return $result;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Generates the request grouping identifier for the rate limiting.
[265] Fix | Delete
*
[266] Fix | Delete
* @param bool $proxy_support Rate Limiting proxy support.
[267] Fix | Delete
*
[268] Fix | Delete
* @return string
[269] Fix | Delete
*/
[270] Fix | Delete
protected static function get_rate_limiting_id( bool $proxy_support ): string {
[271] Fix | Delete
[272] Fix | Delete
if ( is_user_logged_in() ) {
[273] Fix | Delete
$id = (string) get_current_user_id();
[274] Fix | Delete
} else {
[275] Fix | Delete
$id = md5( self::get_ip_address( $proxy_support ) );
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
/**
[279] Fix | Delete
* Filters the rate limiting identifier.
[280] Fix | Delete
*
[281] Fix | Delete
* @param string $id The rate limiting identifier.
[282] Fix | Delete
*
[283] Fix | Delete
* @since 9.8.0
[284] Fix | Delete
*/
[285] Fix | Delete
$id = apply_filters( 'woocommerce_store_api_rate_limit_id', $id );
[286] Fix | Delete
[287] Fix | Delete
return sanitize_key( $id );
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
/**
[291] Fix | Delete
* Check if is request to the Store API.
[292] Fix | Delete
*
[293] Fix | Delete
* @return bool
[294] Fix | Delete
*/
[295] Fix | Delete
protected function is_request_to_store_api() {
[296] Fix | Delete
if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
[297] Fix | Delete
return false;
[298] Fix | Delete
}
[299] Fix | Delete
return 0 === strpos( $GLOBALS['wp']->query_vars['rest_route'], '/wc/store/' );
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
/**
[303] Fix | Delete
* Returns true only for POST requests that are NOT overridden to another method
[304] Fix | Delete
* via the X-HTTP-Method-Override header (used by wp.apiFetch for PUT/DELETE).
[305] Fix | Delete
*
[306] Fix | Delete
* @see https://github.com/wordpress/gutenberg/blob/trunk/packages/api-fetch/src/middlewares/http-v1.ts#L21-L43
[307] Fix | Delete
*
[308] Fix | Delete
* @return bool
[309] Fix | Delete
*/
[310] Fix | Delete
private function is_only_post_request() {
[311] Fix | Delete
// Check that REQUEST_METHOD is POST.
[312] Fix | Delete
if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
[313] Fix | Delete
return false;
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
// Check X-HTTP-Method-Override header if it exists and is not empty - it must also be POST.
[317] Fix | Delete
if ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
[318] Fix | Delete
$method_override = strtoupper( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) );
[319] Fix | Delete
if ( '' !== $method_override && 'POST' !== $method_override ) {
[320] Fix | Delete
return false;
[321] Fix | Delete
}
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
return true;
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
/**
[328] Fix | Delete
* Get current user IP Address.
[329] Fix | Delete
*
[330] Fix | Delete
* X_REAL_IP and CLIENT_IP are custom implementations designed to facilitate obtaining a user's ip through proxies, load balancers etc.
[331] Fix | Delete
*
[332] Fix | Delete
* _FORWARDED_FOR (XFF) request header is a de-facto standard header for identifying the originating IP address of a client connecting to a web server through a proxy server.
[333] Fix | Delete
* Note for X_FORWARDED_FOR, Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2.
[334] Fix | Delete
* Make sure we always only send through the first IP in the list which should always be the client IP.
[335] Fix | Delete
* Documentation at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
[336] Fix | Delete
*
[337] Fix | Delete
* Forwarded request header contains information that may be added by reverse proxy servers (load balancers, CDNs, and so on).
[338] Fix | Delete
* Documentation at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
[339] Fix | Delete
* Full RFC at https://datatracker.ietf.org/doc/html/rfc7239
[340] Fix | Delete
*
[341] Fix | Delete
* @param boolean $proxy_support Enables/disables proxy support.
[342] Fix | Delete
*
[343] Fix | Delete
* @return string
[344] Fix | Delete
*/
[345] Fix | Delete
protected static function get_ip_address( bool $proxy_support = false ) {
[346] Fix | Delete
[347] Fix | Delete
if ( ! $proxy_support ) {
[348] Fix | Delete
return self::validate_ip( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ?? 'unresolved_ip' ) ) );
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
if ( array_key_exists( 'HTTP_X_REAL_IP', $_SERVER ) ) {
[352] Fix | Delete
return self::validate_ip( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ) );
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
if ( array_key_exists( 'HTTP_CLIENT_IP', $_SERVER ) ) {
[356] Fix | Delete
return self::validate_ip( sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ) );
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
if ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER ) ) {
[360] Fix | Delete
$ips = explode( ',', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) );
[361] Fix | Delete
if ( is_array( $ips ) && ! empty( $ips ) ) {
[362] Fix | Delete
return self::validate_ip( trim( $ips[0] ) );
[363] Fix | Delete
}
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
if ( array_key_exists( 'HTTP_FORWARDED', $_SERVER ) ) {
[367] Fix | Delete
// Using regex instead of explode() for a smaller code footprint.
[368] Fix | Delete
// Expected format: Forwarded: for=192.0.2.60;proto=http;by=203.0.113.43,for="[2001:db8:cafe::17]:4711"...
[369] Fix | Delete
preg_match(
[370] Fix | Delete
'/(?<=for\=)[^;,]*/i', // We catch everything on the first "for" entry, and validate later.
[371] Fix | Delete
sanitize_text_field( wp_unslash( $_SERVER['HTTP_FORWARDED'] ) ),
[372] Fix | Delete
$matches
[373] Fix | Delete
);
[374] Fix | Delete
[375] Fix | Delete
if ( strpos( $matches[0] ?? '', '"[' ) !== false ) { // Detect for ipv6, eg "[ipv6]:port".
[376] Fix | Delete
preg_match(
[377] Fix | Delete
'/(?<=\[).*(?=\])/i', // We catch only the ipv6 and overwrite $matches.
[378] Fix | Delete
$matches[0],
[379] Fix | Delete
$matches
[380] Fix | Delete
);
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
if ( ! empty( $matches ) ) {
[384] Fix | Delete
return self::validate_ip( trim( $matches[0] ) );
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
return '0.0.0.0';
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/**
[392] Fix | Delete
* Uses filter_var() to validate and return ipv4 and ipv6 addresses
[393] Fix | Delete
* Will return 0.0.0.0 if the ip is not valid. This is done to group and still rate limit invalid ips.
[394] Fix | Delete
*
[395] Fix | Delete
* @param string $ip ipv4 or ipv6 ip string.
[396] Fix | Delete
*
[397] Fix | Delete
* @return string
[398] Fix | Delete
*/
[399] Fix | Delete
protected static function validate_ip( $ip ) {
[400] Fix | Delete
$ip = filter_var(
[401] Fix | Delete
$ip,
[402] Fix | Delete
FILTER_VALIDATE_IP,
[403] Fix | Delete
array( FILTER_FLAG_NO_RES_RANGE, FILTER_FLAG_IPV6 )
[404] Fix | Delete
);
[405] Fix | Delete
[406] Fix | Delete
return $ip ?: '0.0.0.0';
[407] Fix | Delete
}
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function