Skip to content

Commit a0a1c58

Browse files
ahmed-farid-devsmowton
authored andcommitted
Create ComparingValueOfSensetiveHeader.java
1 parent aa488e5 commit a0a1c58

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

0 commit comments

Comments
 (0)