Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move decrypt into the try catch so we handle if bytes are not valid #4548

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions impl/src/main/java/com/sun/faces/context/flash/ELFlash.java
Original file line number Diff line number Diff line change
Expand Up @@ -1379,17 +1379,17 @@ void decode(FacesContext context, ELFlash flash, Cookie cookie) throws InvalidKe
String temp;
String value;

String urlDecodedValue = null;
String urlDecodedValue;

try {
urlDecodedValue = URLDecoder.decode(cookie.getValue(), "UTF-8");
} catch (UnsupportedEncodingException uee) {
urlDecodedValue = cookie.getValue();
}

value = guard.decrypt(urlDecodedValue);

try {
value = guard.decrypt(urlDecodedValue);

int i = value.indexOf("_");

// IMPORTANT: what was "next" when the cookie was
Expand Down Expand Up @@ -1442,15 +1442,16 @@ void decode(FacesContext context, ELFlash flash, Cookie cookie) throws InvalidKe
}
nextRequestFlashInfo.setFlashMap(flashMap);
}
} catch(InvalidKeyException e) {
throw e;
} catch (Throwable t) {
context.getAttributes().put(CONSTANTS.ForceSetMaxAgeZero, Boolean.TRUE);
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE,
"jsf.externalcontext.flash.bad.cookie",
new Object [] { value });
new Object [] { urlDecodedValue });
}
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public String encrypt(String value) {

public String decrypt(String value) throws InvalidKeyException {

byte[] bytes = DatatypeConverter.parseBase64Binary(value);;
byte[] bytes = DatatypeConverter.parseBase64Binary(value);

try {
byte[] iv = new byte[16];
Expand Down Expand Up @@ -214,4 +214,4 @@ private static byte[] concatBytes(byte[] array1, byte[] array2) {
return cBytes;
}

}
}