-
Notifications
You must be signed in to change notification settings - Fork 262
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
Fix security vulnerability regarding the Hibernate dependency. #461
Comments
A Template Injection was identified in cron-utils enabling attackers to inject arbitrary Java EL expressions, leading to unauthenticated Remote Code Execution (RCE) vulnerability. Remote Code Execution - JavaEL Injection Cron-Utils uses Java Bean Validation (JSR 380) custom constraint validators such as CronValidator. When building custom constraint violation error messages, it is important to understand that they support different types of interpolation, including Java EL expressions. Therefore if an attacker can inject arbitrary data in the error message template passed to ConstraintValidatorContext.buildConstraintViolationWithTemplate(), they will be able to run arbitrary Java code. Unfortunately, it is common that validated (and therefore, normally untrusted) bean properties flow into the custom error message. In this case CronValidator includes the Cron expression being validated in the custom constraint error validation message if an exception is thrown while parsing the expression:
|
Hi, Hibernate Validator lead here. So I have no idea if Hibernate Validator is the right thing for your usage, my personal opinion is that it might be too much infrastructure for a focused util library like yours. But as far as security is concerned, I thought that @pwntester had added the important information I gave to him to the message he is sending. @pwntester, I already asked once, could you make sure to provide all relevant information to the people you contact? Thanks! What you're doing is effectively unsafe but there are multiple ways to make it perfectly safe and still using HV:
Note that the default messages of a couple of built-in constraints will be broken if you choose this option over the first one (typically the *Min, *Max constraints that are using EL for their default message). My advice would be to also properly escape things as recommended in the first option anyway. I'm still thinking about a way to have a more secure default while keeping the *Min/*Max contraints working properly (and the Jakarta Bean Validation spec requires Jakarta EL support). It's not an easy one. I hope this clarifies things for you. |
Thanks for the feedback @gsmet |
Also, I'm far from being sure that Apache BVal is safer if you have javax.el around, which you still have in your pom. I had a quick look at the code and I think they automatically enable EL if it's in the classpath. |
as far as i know, their code to decide if EL expressions should be evaluated is this which seems to check only for the configuration property being enabled or the message being the default one |
I fail to see how changing the test impl makes Because first, HV is the most widely used implementation and second, even in Apache BVal, you can enable EL for custom constraint violation message, which can be done for very good reasons and a user might think all your constraints are safe because carefully audited. And in this case, having your What you need to do is escape There are better Hibernate Validator-specific way to do this but if you want to be compatible with all the implementations and be entirely safe, that's the only way to do it right now. |
@jmrozanec Do you know if this vulnerability is an issue in 6.0.6? Fossa filed this vulnerability but I don't see any related code in v6.0.6 so we are assuming that this is not an issue in that version. Would be great if you can confirm. |
As the original contributor of the validator, I'm confused about what was done to mitigate the problem, as well as how the code was deemed vulnerable in the first place. As far as I can tell, the change to swap out the test dependency does nothing for the runtime behaviour of this library. So I fail to see how this mitigates the risk. On the validity of the report: there is no user input for this constraint violation message. It's simply taking the message from the thrown exception and using it as the violation message. So the @pwntester @jmrozanec @gsmet am I wrong in my assessment here? |
|
I see, I completely missed that part (obviously). In that case, shouldn't this library still be considered vulnerable to the problem? Was the fix validated? |
I think the change to bval was considered a secure fix back then and we missed that it was a test dependency. I think its worth verifying it with the latest version. In the meantime, Hibernate has disabled EL evaluation by default on custom constraint error messages |
@pwntester is the current version considered safe, or there are any actions required on our side? |
Hibernate Validator lead here, 6.2 ( |
I just verified that if I upgrade my testcase to use 9.1.5 and keep the rest of the dependencies the same (hibernate-validator 6.1.6.Final), the application is still vulnerable:
So the vulnerability is now dependent on what validator version is used at runtime which is not ideal. @jmrozanec see the remediation section in this blog post |
From my perspective, there are 2 possible routes:
This library has no direct influence on the validator framework used, so we can only make sure the message is safe. |
@NielsDoucet perhaps the first option (not reflecting the expression back in the exception message) is a good choice? We would be grateful for a PR providing that fix. Is that possible? |
@jmrozanec This should fix it |
@pwntester thanks! 😄 That was fast! 🚀 |
that was easy too 😄 I guess we should issue a new advisory and CVE to let user know about the security issue in <9.1.5 |
@pwntester yes, please issue an advisory. We will release a new version over the weekend, so we ensure the fix can be incorporated ASAP by anyone. Thanks! 😄 |
I dont have permissions on this repo to create a security advisory. Please create one and invite me in and I will fill in the details |
I was thinking more about fixing it in the actual parser: https://github.com/jmrozanec/cron-utils/blob/master/src/main/java/com/cronutils/parser/CronParser.java#L131
could become
It would at least provide more feedback from the validator than a generic "something went wrong". |
Make tests a bit more resilient to exception message changes. fixes jmrozanec#461
@pwntester just created the security advisory and added you as a collaborator. I used the same description as for the previous one, only updating the library version for the mitigation. Can you check what else is required to finalize this? Thank you both for the help, and my apologies for the delay 😄 Thanks! |
No description provided.
The text was updated successfully, but these errors were encountered: