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

Added validation on Builder.build() to check if any matcher will #2533

Conversation

JoeBeeton
Copy link

allow basetype/subtype of Serializable or Object.class

If so an unchecked TypeMatchException is thrown.
This can be bypassed by using build_insecure() instead which has no such checks.
The aim of this change is to :
A : Make developers realise what they are doing has serious security implications and hopefully accomplish their requirements in a different way.
B : Make it easier for static code analysis to flag insecure usage of Jackson-Databind as those tools can assume that if a developer is calling
build_insecure() they are doing that because they are allowing all or alot of classes on the classpath to be deserialized.

…w basetype/subtype of Serializable or Object.class

If so an unchecked TypeMatchException is thrown.
This can be bypassed by using build_insecure() instead which has no such checks.
The aim of this change is to :
A : Make developers realise what they are doing has serious security implications and hopefully accomplish their requirements in a different way.
B : Make it easier for static code analysis to flag insecure usage of Jackson-Databind as those tools can assume that if a developer is calling
build_insecure() they are doing that because they are allowing all or alot of classes on the classpath to be deserialized.
* validates that each of the Matchers will not allow Serializable.class or Object.class.
* @throws InsecureTypeMatchException if an included Matcher will allow one or both of these classes through.
*/
private void validateTypeMatch() throws InsecureTypeMatchException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, no. If user explicitly adds insecure base type, that should not be blocked.

* so will leave your application open to vulnerabilities including remote code execution.
* @return the BasicPolymorphicTypeValidator.
*/
public BasicPolymorphicTypeValidator build_insecure() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build_insecure() is not following any naming convention, but in general I'll add my notes on why I don't think this is the way to go.

@cowtowncoder
Copy link
Member

First of all, thank you for proposing the patch.
Unfortunately I think this approach is bit more complex (and limiting) than what I am comfortable with.

Instead of checking things at build(), it would make more sense to verify it when attempting to add specific rule: and in this case only for specific 2 Unsafe classes. This would be done in Builder.allowIfBaseType(Class<?>).
I guess one can still use String / Pattern to work around that. Fine. I don't think Jackson needs to be nanny for developers -- if someone really wants to allow unsafe basetypes, let them. There are legit cases (internal code that does not accept external input), and it should be up to them to determine if they should do it or not.

There is also no need to check subtype filtering methods: class name / class passed would have to be gadget, not Object or Serializable.

But at the same time, there is then need to add something like allowIfUnsafeBaseType(Class) that will not throw exception.

On plus side, doing this would be bit simpler approach.

@cowtowncoder
Copy link
Member

Implemented slightly different solution, see #2587, to further improve safety. Closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants