GUACAMOLE-784: Tolerate port number within X-Forwarded-For header

Currently the Regex pares only Header with IPs only.
But some Cloud Services provide Header with “IP:Port” and they are not changeable.

A change in the Line 96 and 101 could may solve this topic.

BG
Sporeno

GUACAMOLE-784: Changed Quantifiers of Port extension in the IP-Regexs

GUACAMOLE-784: Changed IP-Regexs to accept also Ports with 5 Digits (Fix)

GUACAMOLE-784: Separated Port-Regex from IP-Regexes to avoid duplicated Code for IPv4 and IPv6

Created new Constant for Port matching Regex

GUACAMOLE-784: Change Comments according standard formatting for JavaDoc comments
GUACAMOLE-784: Tolerate port number within X-Forwarded-For header

Currently the Regex pares only Header with IPs only.
But some Cloud Services provide Header with “IP:Port” and they are not changeable.

A change in the Line 96 and 101 could may solve this topic.

BG
Sporeno

GUACAMOLE-784: Changed Quantifiers of Port extension in the IP-Regexs

GUACAMOLE-784: Tolerate port number within X-Forwarded-For header
This commit is contained in:
skr
2019-12-04 07:22:55 +01:00
parent fbcb04e670
commit 25ac5f06c1

View File

@@ -105,11 +105,16 @@ public class AuthenticationService {
*/ */
private static final String IP_ADDRESS_REGEX = "(" + IPV4_ADDRESS_REGEX + "|" + IPV6_ADDRESS_REGEX + ")"; private static final String IP_ADDRESS_REGEX = "(" + IPV4_ADDRESS_REGEX + "|" + IPV6_ADDRESS_REGEX + ")";
/**
* Regular expression which matches any Port Number.
*/
private static final String PORT_NUMBER_REGEX = "(:[0-9]{1,5})?";
/** /**
* Pattern which matches valid values of the de-facto standard * Pattern which matches valid values of the de-facto standard
* "X-Forwarded-For" header. * "X-Forwarded-For" header.
*/ */
private static final Pattern X_FORWARDED_FOR = Pattern.compile("^" + IP_ADDRESS_REGEX + "(, " + IP_ADDRESS_REGEX + ")*$"); private static final Pattern X_FORWARDED_FOR = Pattern.compile("^" + IP_ADDRESS_REGEX + PORT_NUMBER_REGEX + "(, " + IP_ADDRESS_REGEX + PORT_NUMBER_REGEX + ")*$");
/** /**
* Returns a formatted string containing an IP address, or list of IP * Returns a formatted string containing an IP address, or list of IP