Skip to content

Commit 87df9d8

Browse files
committed
Fixes #4547 - ELFlash ArrayIndexOutOfBoundsException on invalid Cookie value
1 parent 054ed4f commit 87df9d8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

impl/src/main/java/com/sun/faces/util/ByteArrayGuardAESCTR.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public String decrypt(String value) throws InvalidKeyException {
130130

131131
try {
132132
byte[] iv = new byte[16];
133+
134+
if (bytes.length < iv.length) {
135+
throw new InvalidKeyException("Invalid characters in decrypted value");
136+
}
137+
133138
System.arraycopy(bytes, 0, iv, 0, iv.length);
134139
IvParameterSpec ivspec = new IvParameterSpec(iv);
135140

impl/src/test/java/com/sun/faces/util/ByteArrayGuardAESCTRTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
package com.sun.faces.util;
1818

19+
import java.security.InvalidKeyException;
20+
import javax.xml.bind.DatatypeConverter;
1921
import org.junit.Test;
2022

21-
import static org.junit.Assert.assertTrue;
2223
import static org.junit.Assert.assertEquals;
24+
import static org.junit.Assert.assertTrue;
2325

2426

2527
public class ByteArrayGuardAESCTRTest {
@@ -39,5 +41,16 @@ public void testSmallerSizeBytes() throws Exception {
3941

4042
}
4143

44+
@Test(expected = InvalidKeyException.class)
45+
public void testDecryptValueWithoutIvBytes() throws InvalidKeyException {
46+
ByteArrayGuardAESCTR sut = new ByteArrayGuardAESCTR();
47+
48+
String value = "noIV";
49+
byte[] bytes = DatatypeConverter.parseBase64Binary(value);
50+
assertTrue(bytes.length < 16);
51+
52+
sut.decrypt(value);
53+
}
54+
4255
}
4356

0 commit comments

Comments
 (0)