File tree Expand file tree Collapse file tree
java/ql/src/experimental/Security/CWE/CWE-208 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import javax .servlet .http .HttpServletRequest ;
2- import javax .servlet .http .Cookie ;
32import java .nio .charset .StandardCharsets ;
43import java .security .MessageDigest ;
54
6- public boolean validateCsrfTokenInRequest (HttpServletRequest request ) {
7- if (cookies != null ) {
8- for (Cookie cookie : cookies ) {
9- if (cookie .getName ().equals (CSRF -TOKEN ){
10- csrfCookieValue = cookie .getValue ();
11- }
12- }
13- }
14- if (UnsafecsrfComparison (csrfCookieValue )) { // BAD
15- return true ;
16- }
17- }
5+
186private boolean UnsafecsrfComparison (String csrfTokenInCookie ) {
197 if (csrfTokenInCookie == null || !csrfTokenInCookie .equals (request .getHeader ("X-CSRF-TOKEN" ))) { // BAD
208 return false ;
219 }
2210}
2311
24-
25-
26- public boolean validateCsrfTokenInRequest (HttpServletRequest request ) {
27- if (cookies != null ) {
28- for (Cookie cookie : cookies ) {
29- if (cookie .getName ().equals (CSRF -TOKEN ){
30- csrfCookieValue = cookie .getValue ();
31- }
32- }
33- }
34- if (safecsrfComparison (csrfCookieValue )) { // GOOD
35- return true ;
36- }
37- }
12+
3813private boolean safecsrfComparison (String csrfTokenInCookie ) {
3914 String csrfTokenInRequest = request .getHeader ("X-CSRF-TOKEN" );
4015 if (csrfTokenInRequest == null || !MessageDigest .isEqual (
You can’t perform that action at this time.
0 commit comments