26
26
import java .io .OutputStream ;
27
27
import java .io .OutputStreamWriter ;
28
28
import java .io .Writer ;
29
+ import java .net .Inet6Address ;
29
30
import java .net .InetAddress ;
30
31
import java .net .UnknownHostException ;
31
32
import java .nio .charset .StandardCharsets ;
@@ -230,7 +231,15 @@ void registerLocalHostAddresses() {
230
231
localhostAddresses .add (address .getHostAddress ());
231
232
}
232
233
} catch (UnknownHostException ex ) {
233
- LOG .warn ("Unable to retrieve ipaddresses for localhost: {}" , ex .getMessage ());
234
+ LOG .warn ("Unable to retrieve ipaddresses (v4) for localhost: {}" , ex .getMessage ());
235
+ }
236
+
237
+ try {
238
+ for (InetAddress address : Inet6Address .getAllByName ("localhost" ) ){
239
+ localhostAddresses .add (address .getHostAddress ());
240
+ }
241
+ } catch (UnknownHostException ex ) {
242
+ LOG .warn ("Unable to retrieve ipaddresses (v6) for localhost: {}" , ex .getMessage ());
234
243
}
235
244
236
245
if (localhostAddresses .isEmpty ()) {
@@ -245,7 +254,9 @@ void registerLocalHostAddresses() {
245
254
* @return TRUE if request is from LOCALHOST otherwise FALSE
246
255
*/
247
256
boolean isFromLocalHost (HttpServletRequest request ) {
248
- return localhostAddresses .contains (request .getRemoteAddr ());
257
+ String remoteAddr = request .getRemoteAddr ();
258
+ remoteAddr = remoteAddr .startsWith ("[" ) ? remoteAddr .substring (1 , remoteAddr .length () - 1 ) : remoteAddr ;
259
+ return localhostAddresses .contains (remoteAddr );
249
260
}
250
261
251
262
/**
0 commit comments