File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
java/ql/test/experimental/query-tests/security/CWE-208 Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change
1
+ import javax .servlet .http .HttpServletRequest ;
2
+ import java .nio .charset .StandardCharsets ;
3
+ import java .security .MessageDigest ;
4
+
5
+
6
+ private boolean UnsafecsrfComparison (String csrfTokenInCookie ) {
7
+ if (csrfTokenInCookie == null || !csrfTokenInCookie .equals (request .getHeader ("X-CSRF-TOKEN" ))) { // BAD
8
+ return false ;
9
+ }
10
+ }
11
+
12
+
13
+ private boolean safecsrfComparison (String csrfTokenInCookie ) {
14
+ String csrfTokenInRequest = request .getHeader ("X-CSRF-TOKEN" );
15
+ if (csrfTokenInRequest == null || !MessageDigest .isEqual (
16
+ csrfTokenInCookie .getBytes (StandardCharsets .UTF_8 ),
17
+ csrfTokenInRequest .getBytes (StandardCharsets .UTF_8 ))) { // GOOD
18
+ return false ;
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments