File tree Expand file tree Collapse file tree 1 file changed +2
-27
lines changed
java/ql/src/experimental/Security/CWE/CWE-208 Expand file tree Collapse file tree 1 file changed +2
-27
lines changed Original file line number Diff line number Diff line change 1
1
import javax .servlet .http .HttpServletRequest ;
2
- import javax .servlet .http .Cookie ;
3
2
import java .nio .charset .StandardCharsets ;
4
3
import java .security .MessageDigest ;
5
4
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
+
18
6
private boolean UnsafecsrfComparison (String csrfTokenInCookie ) {
19
7
if (csrfTokenInCookie == null || !csrfTokenInCookie .equals (request .getHeader ("X-CSRF-TOKEN" ))) { // BAD
20
8
return false ;
21
9
}
22
10
}
23
11
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
+
38
13
private boolean safecsrfComparison (String csrfTokenInCookie ) {
39
14
String csrfTokenInRequest = request .getHeader ("X-CSRF-TOKEN" );
40
15
if (csrfTokenInRequest == null || !MessageDigest .isEqual (
You can’t perform that action at this time.
0 commit comments