File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
java/ql/src/experimental/Security/CWE/CWE-348 Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -30,15 +30,13 @@ public void bad2(HttpServletRequest request) {
30
30
@ GetMapping (value = "good1" )
31
31
@ ResponseBody
32
32
public String good1 (HttpServletRequest request ) {
33
- String remoteAddr = "" ;
34
- if (request != null ) {
35
- remoteAddr = request .getHeader ("X-FORWARDED-FOR" );
36
- remoteAddr = remoteAddr .split ("," )[remoteAddr .split ("," ).length - 1 ]; // good
37
- if (remoteAddr == null || "" .equals (remoteAddr )) {
38
- remoteAddr = request .getRemoteAddr ();
39
- }
33
+ String ip = request .getHeader ("X-FORWARDED-FOR" );
34
+ String [] parts = ip .split ("," );
35
+ // Good: if this application runs behind a reverse proxy it may append the real remote IP to the end of any client-supplied X-Forwarded-For header.
36
+ ip = parts [parts .length - 1 ];
37
+ if (!StringUtils .startsWith (ip , "192.168." )) {
38
+ new Exception ("ip illegal" );
40
39
}
41
- return remoteAddr ;
42
40
}
43
41
44
42
protected String getClientIP () {
@@ -48,4 +46,4 @@ protected String getClientIP() {
48
46
}
49
47
return xfHeader .split ("," )[0 ];
50
48
}
51
- }
49
+ }
You can’t perform that action at this time.
0 commit comments