]> source.dussan.org Git - vaadin-framework.git/commitdiff
fix: use time-constant comparison for CSRF tokens (#12188) (#12196)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Wed, 3 Feb 2021 14:39:35 +0000 (16:39 +0200)
committerGitHub <noreply@github.com>
Wed, 3 Feb 2021 14:39:35 +0000 (16:39 +0200)
This hardens the framework against a theoretical timing attack based on
comparing how quickly a request with an invalid CSRF token is rejected.

Cherry-picked from: https://github.com/vaadin/flow/pull/9875

Authored-by: Tatu Lund <tatu@vaadin.com>
server/src/main/java/com/vaadin/server/VaadinService.java
uitest/src/test/java/com/vaadin/tests/VerifyBrowserVersionTest.java

index 31ddf7b8bafea1c619910991a2aaac9549a03604..45e71dace70f76709cb7bd78f087abd6fca75a20 100644 (file)
@@ -29,6 +29,8 @@ import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -1962,7 +1964,9 @@ public abstract class VaadinService implements Serializable {
                 .isXsrfProtectionEnabled()) {
             String sessionToken = session.getCsrfToken();
 
-            if (sessionToken == null || !sessionToken.equals(requestToken)) {
+            if (sessionToken == null || !MessageDigest.isEqual(
+                    sessionToken.getBytes(StandardCharsets.UTF_8),
+                    requestToken.getBytes(StandardCharsets.UTF_8))) {
                 return false;
             }
         }
index 87b428a15ad5c7ac994a833b3e355633f4c48f0b..4f90112990dcc4e90bd21ba96f0205368bf697b3 100644 (file)
@@ -25,7 +25,7 @@ public class VerifyBrowserVersionTest extends MultiBrowserTest {
             // Chrome version does not necessarily match the desired version
             // because of auto updates...
             browserIdentifier = getExpectedUserAgentString(
-                    getDesiredCapabilities()) + "87";
+                    getDesiredCapabilities()) + "88";
         } else if (BrowserUtil.isFirefox(getDesiredCapabilities())) {
             browserIdentifier = getExpectedUserAgentString(
                     getDesiredCapabilities()) + "81";