Skip to content

Commit

Permalink
Merge pull request #4668 from jasonex7/fix-4547
Browse files Browse the repository at this point in the history
Fixes #4547 - ELFlash ArrayIndexOutOfBoundsException on invalid Cookie value
  • Loading branch information
juneau001 authored Feb 17, 2020
2 parents 054ed4f + 7144ebc commit edfc644
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public String decrypt(String value) throws InvalidKeyException {

try {
byte[] iv = new byte[16];

if (bytes.length < iv.length) {
throw new InvalidKeyException("Invalid characters in decrypted value");
}

System.arraycopy(bytes, 0, iv, 0, iv.length);
IvParameterSpec ivspec = new IvParameterSpec(iv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.sun.faces.util;

import java.security.InvalidKeyException;
import javax.xml.bind.DatatypeConverter;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;


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

}

@Test(expected = InvalidKeyException.class)
public void testDecryptValueWithoutIvBytes() throws InvalidKeyException {
ByteArrayGuardAESCTR sut = new ByteArrayGuardAESCTR();

String value = "noIV";
byte[] bytes = DatatypeConverter.parseBase64Binary(value);
assertTrue(bytes.length < 16);

sut.decrypt(value);
}

}

0 comments on commit edfc644

Please sign in to comment.