Skip to content

Commit 84f62a5

Browse files
committed
Do not try to resolve X-Forwarded-For header
The remote address is reported by HttpServletRequest. Configuration of this property is normally done via the application server. If this is somehow not possible, use XForwardedRequestWrapperFactory.
1 parent 35c86d3 commit 84f62a5

File tree

1 file changed

+4
-36
lines changed

1 file changed

+4
-36
lines changed

wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -140,48 +140,16 @@ private String getUserAgentStringLc()
140140
}
141141

142142
/**
143-
* When using ProxyPass, requestCycle().getHttpServletRequest(). getRemoteAddr() returns the IP
144-
* of the machine forwarding the request. In order to maintain the clients ip address, the
145-
* server places it in the <a
146-
* href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers">X-Forwarded-For</a>
147-
* Header.
148-
*
149-
* Proxies may also mask the original client IP with tokens like "hidden" or "unknown".
150-
* If so, the last proxy ip address is returned.
143+
* Returns the IP address from {@code HttpServletRequest.getRemoteAddr()}.
151144
*
152145
* @param requestCycle
153146
* the request cycle
154-
* @return remoteAddr IP address of the client, using the X-Forwarded-For header and defaulting
155-
* to: getHttpServletRequest().getRemoteAddr()
147+
* @return remoteAddr IP address of the client, using
148+
* {@code getHttpServletRequest().getRemoteAddr()}
156149
*/
157150
protected String getRemoteAddr(RequestCycle requestCycle)
158151
{
159152
ServletWebRequest request = (ServletWebRequest)requestCycle.getRequest();
160-
HttpServletRequest req = request.getContainerRequest();
161-
String remoteAddr = request.getHeader("X-Forwarded-For");
162-
163-
if (remoteAddr != null)
164-
{
165-
if (remoteAddr.contains(","))
166-
{
167-
// sometimes the header is of form client ip,proxy 1 ip,proxy 2 ip,...,proxy n ip,
168-
// we just want the client
169-
remoteAddr = Strings.split(remoteAddr, ',')[0].trim();
170-
}
171-
try
172-
{
173-
// If ip4/6 address string handed over, simply does pattern validation.
174-
InetAddress.getByName(remoteAddr);
175-
}
176-
catch (UnknownHostException e)
177-
{
178-
remoteAddr = req.getRemoteAddr();
179-
}
180-
}
181-
else
182-
{
183-
remoteAddr = req.getRemoteAddr();
184-
}
185-
return remoteAddr;
153+
return request.getContainerRequest().getRemoteAddr();
186154
}
187155
}

0 commit comments

Comments
 (0)