mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Update and rename UnsafecsrfComparison.java to csrfComparison.java
This commit is contained in:
committed by
Chris Smowton
parent
c6c67b907b
commit
39e07cbc9c
@@ -1,21 +0,0 @@
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
public boolean validateCsrfTokenInRequest(HttpServletRequest request) {
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals(CSRF-TOKEN){
|
||||
csrfCookieValue = cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (compareCsrfTokens(csrfCookieValue)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean compareCsrfTokens(String csrfTokenInCookie) {
|
||||
if(csrfTokenInCookie == null || !csrfTokenInCookie.equals(request.getHeader("X-CSRF-TOKEN"))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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(
|
||||
csrfTokenInCookie.getBytes(StandardCharsets.UTF_8),
|
||||
csrfTokenInRequest.getBytes(StandardCharsets.UTF_8))) { // GOOD
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user