Viewing 7 replies - 1 through 7 (of 7 total)
  • Known bug. Duplicate of this topic.

    dwinden

    Thread Starter Eidolon Night

    (@eidolon-night)

    The fix for that particular bug appears to already be in the latest version. I’m still having the issue.

    @eidolon Night

    As far as I can see that fixed get_ip() method is not included in the latest iTSec plugin release (5.0.1).
    There was a bit of new code added at the end so I’ll include the updated 5.0.1 fixed code in this topic:

    public static function get_ip() {
    
    	global $itsec_globals;
    
    	if ( isset( $itsec_globals['settings']['proxy_override'] ) && true === $itsec_globals['settings']['proxy_override'] ) {
    
    		return esc_sql( $_SERVER['REMOTE_ADDR'] );
    
    	}
    
    	//Just get the headers if we can or else use the SERVER global
    	if ( function_exists( 'apache_request_headers' ) ) {
    
    		$headers = apache_request_headers();
    
    	} else {
    
    		$headers = $_SERVER;
    
    	}
    
    	//Get the forwarded IP if it exists
    	if ( array_key_exists( 'X-Forwarded-For', $headers ) &&
    	(
    		filter_var( explode(', ', $headers['X-Forwarded-For'])[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ||
    		filter_var( explode(', ', $headers['X-Forwarded-For'])[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) )
    	) {
    
    		$the_ip = explode(', ', $headers['X-Forwarded-For'])[0];
    
    	} elseif (
    		array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) &&
    		(
    		filter_var( explode(', ', $headers['HTTP_X_FORWARDED_FOR'])[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ||
    		filter_var( explode(', ', $headers['HTTP_X_FORWARDED_FOR'])[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 )
    		)
    	) {
    
    		$the_ip = explode(', ', $headers['HTTP_X_FORWARDED_FOR'])[0];
    
    	} else if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
    
    		$the_ip = $_SERVER['REMOTE_ADDR'];
    
    	} else {
    		$the_ip = '';
    	}
    
    	return esc_sql( $the_ip );
    
    }

    Untested so use it at your own risk.

    dwinden

    @eidolon Night

    This is definately not fixed in the 5.0.1 release …
    If it was fixed you would not be having the issue as reported in this topic …

    dwinden

    @eidolon Night

    If you require no further assistance please mark the topic as ‘resolved’.

    dwinden

    Thread Starter Eidolon Night

    (@eidolon-night)

    I previously ran a diff and saw the change, but I might have mixed up my git branches. Please leave this open until I’ve had time to review. Thanks for the help BTW

    @eidolon Night

    Looks like the iTSec plugin 5.1.0 update released today fixes your IP issue with CloudFlare.

    According to the iTSec plugin 5.1.0 ChangeLog:

    Enhancement: Improved IP detection when proxy detection is active by processing the header set by CloudFlare.

    dwinden

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Issue detecting real IP when using CloudFlare’ is closed to new replies.