mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
Update csrfComparison.java
This commit is contained in:
committed by
Chris Smowton
parent
333130b2a4
commit
aa488e532f
@@ -1,40 +1,15 @@
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.Cookie;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public boolean validateCsrfTokenInRequest(HttpServletRequest request) {
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals(CSRF-TOKEN){
|
||||
csrfCookieValue = cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (UnsafecsrfComparison(csrfCookieValue)) { // BAD
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean UnsafecsrfComparison(String csrfTokenInCookie) {
|
||||
if(csrfTokenInCookie == null || !csrfTokenInCookie.equals(request.getHeader("X-CSRF-TOKEN"))) { // BAD
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean validateCsrfTokenInRequest(HttpServletRequest request) {
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals(CSRF-TOKEN){
|
||||
csrfCookieValue = cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (safecsrfComparison(csrfCookieValue)) { // GOOD
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean safecsrfComparison(String csrfTokenInCookie) {
|
||||
String csrfTokenInRequest = request.getHeader("X-CSRF-TOKEN");
|
||||
if (csrfTokenInRequest == null || !MessageDigest.isEqual(
|
||||
|
||||
Reference in New Issue
Block a user