-
Notifications
You must be signed in to change notification settings - Fork 113
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
Conversation
invalid base 64 Signed-off-by: Cody Lerum <cody.lerum@gmail.com>
Reviewed code and ran standard test suite. However, please provide tests for this repair, as it is a standard practice to provide a test and I want to ensure that it doesn't break anything. Thanks for the contribution, it is appreciated! |
Hi, when are you going to merge this fix into master? It's fixed a half of year and nothing in production. It's real problem with not valid cookie value, application using mojarra is unusable. Thanks so much. |
@juneau001 do you have a similar test you could point me at to replicate? I'm not familiar with the whole suite and project layout to really know where to look. |
Guys, is it really safe, that function decrypt of class ByteArrayGuardAESCTR doesn't check the input? There is not any null check, length check of parameter value, then there is a copy of array which requests the 16 bytes. and thats the problem. You should catch NullPointerException and ArrayIndexOutOfBoundExcetion too. The invalid csfcfc cookie can be e.g:
Here is my fix code: /**
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* FIX, HACK what you want but we must solve invalid csfcfc cookie value which is stored in browser where run our web app in previous version.
* https://github.com/eclipse-ee4j/mojarra/pull/4548
* CAUSE is upgrade mojarra from 2.2 to 2.3
* DISADVANTAGE of this fix is missing login message after redirect from login page.
* @param req
*/
private void fixFlashCookieUgly(HttpServletRequest req) {
if (req.getCookies() != null) {
for (int i = 0; i < req.getCookies().length; i++) {
Cookie c = req.getCookies()[i];
if ("csfcfc".equals(c.getName())) {
if (c.getValue() == null || c.getValue().length() < 21) {
//set dummy value which will cause InvalidKeyException in com.sun.faces.context.flash.ByteArrayGuardAESCTR.java(152)
c.setValue("AAAABBBBCCCCDDDDEEEEFFB");
}
}
}
}
} |
@codylerum I will look into making a quick test for this one. I appreciate the contribution. @vonnai Thanks for the follow up, I appreciate the information. |
I've just open PR #4668, which, in my opinion, is a better a approach to resolve this issue because it deals with class ByteArrayGuardAESCTR which is propagating an unnecessary unchecked exception when cookie value doesn't has IV (Initialization Vector) bytes, instead it should propagate a checked exception indicating the value is not valid. |
I will take a look a the PR, thanks. |
Handled via #4668 |
This place the ByteArrayGuardAESCTR.decrypt inside the existing try catch so that general errors such as the follow are properly caught and the cookie is reported as bad. This still allows the InvalidKeyException to propagate up to it's specific catch handling.
See: #4547 and https://github.com/javaserverfaces/mojarra/issues/4386