Skip to content

Commit e0b0cf9

Browse files
committed
fix(security): Timing Attack Vulnerability
A timing attack vulnerability exists in the SCRAM Java implementation. The issue arises because Arrays.equals was used to compare secret values such as client proofs and server signatures. Since Arrays.equals performs a short-circuit comparison, the execution time varies depending on how many leading bytes match. This behavior could allow an attacker to perform a timing side-channel attack and potentially infer sensitive authentication material. All users relying on SCRAM authentication are impacted. This vulnerability has been patched by replacing Arrays.equals with MessageDigest.isEqual, which ensures constant-time comparison.
1 parent fa443aa commit e0b0cf9

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

checks/forbiddenapis.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
java.util.Arrays#equals(byte[],byte[]) @ Replace with java.security.MessageDigest#isEqual(byte[],byte[])

scram-common/src/main/java/com/ongres/scram/common/ScramFunctions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import static java.nio.charset.StandardCharsets.UTF_8;
99

10+
import java.security.MessageDigest;
1011
import java.security.SecureRandom;
11-
import java.util.Arrays;
1212

1313
import com.ongres.scram.common.util.Preconditions;
1414
import org.jetbrains.annotations.NotNull;
@@ -190,8 +190,7 @@ public static boolean verifyClientProof(
190190
byte[] clientSignature = clientSignature(scramMechanism, storedKey, authMessage);
191191
byte[] clientKey = CryptoUtil.xor(clientSignature, clientProof);
192192
byte[] computedStoredKey = hash(scramMechanism, clientKey);
193-
194-
return Arrays.equals(storedKey, computedStoredKey);
193+
return MessageDigest.isEqual(storedKey, computedStoredKey);
195194
}
196195

197196
/**
@@ -205,7 +204,8 @@ public static boolean verifyClientProof(
205204
*/
206205
public static boolean verifyServerSignature(
207206
ScramMechanism scramMechanism, byte[] serverKey, String authMessage, byte[] serverSignature) {
208-
return Arrays.equals(serverSignature(scramMechanism, serverKey, authMessage), serverSignature);
207+
byte[] computedServerSignature = serverSignature(scramMechanism, serverKey, authMessage);
208+
return MessageDigest.isEqual(serverSignature, computedServerSignature);
209209
}
210210

211211
/**

scram-parent/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@
530530
<!-- don't allow System.out or System.err: -->
531531
<bundledSignature>jdk-system-out</bundledSignature>
532532
</bundledSignatures>
533+
<signaturesFiles>
534+
<signaturesFile>${checks.location}/forbiddenapis.txt</signaturesFile>
535+
</signaturesFiles>
533536
</configuration>
534537
<executions>
535538
<execution>

0 commit comments

Comments
 (0)