Skip to content

Allow serialise/deserialise only specific classes - whitelisting #1866

Closed

Description

@lukaszlenart

As discussed in #1296 it would be good to allow define a whitelist with allowed classes that can be serialised/deserialised. This gives more control to the users and allows avoid any possible RCE attacks.

Activity

  1. cowtowncoder commented on Jan 3, 2018

    @cowtowncoder
    Member

    I suspect that a simple "provide a white-list of all classes" approach is impractical for most users: there are plenty of types already in JDK. But perhaps ability to specify a class/class-name validator (serialization / deserialization) validation, similar to:

    FasterXML/jackson3-dev#21

    would make sense?
    In fact, perhaps that issue could be generalized to apply to all cases, not just polymorphic handling.
    Come to think of this it seems unlikely that applying it for all values, even with explicit types defined (as property type or annotation) or passed (as target type argument), would cause problems.

    EDIT: implemented as #2195, included in 2.10.0.

  2. lukaszlenart commented on Jan 3, 2018

    @lukaszlenart
    Author

    I think any of these will work, giving users an ability to control if a given class can be serialised/deserialised allows to build a whitelist anyway :)

  3. cowtowncoder commented on Jan 3, 2018

    @cowtowncoder
    Member

    True. And one more thought I had: if the check is only made when a new "POJO" (de)serializer is needed, it would not even apply to "standard" types, for which (de)serializer is already found.
    This would mean, for example, that Enums are fine, arrays (element handlers are separate), numbers and so on. The only (?) possible concern would be tag types like Iterator.

    So whatever validator was used could perhaps have couple of different methods, called at different points. Maybe some of these:

    1. Class name (String) to Class lookup: could even block this just in case a security flaw only required loading of the class
    2. Use of Class for polymorphic case (could block or change)
    3. Actual use for serializer/deserializer access (before any lookups) -- applies to each and every type
    4. Use for "POJO" (aka bean) (de)serializer: only applicable if no standard impl (enum, array, Map, Collection, reference; well-known JDK types; 3rd party types via modules) found

    For security purposes, (4) probably really covers most if not all cases. And then user would only need to whitelist actual POJOs, and even those could be annotation based (i.e. user or 3rd party lib/framework defines tag annotation(s) to use, validator can look for that).

  4. lukaszlenart commented on Jan 4, 2018

    @lukaszlenart
    Author

    nice 💯

  5. added
    3.xIssues to be only tackled for Jackson 3.x, not 2.x
    on Jan 11, 2018
  6. artem-smotrakov commented on Apr 10, 2019

    @artem-smotrakov
    Contributor

    @cowtowncoder If I understand correctly this issue (implementing whitelisting) is targeted only to 3.x, and the implementation of the whitelist depends on #2195. I have two questions:

    1. Is there any plan to backport it to 2.x? I think it would be good to have whitelisting in 2.x as well.
    2. Do you need any help with this issue, or Add abstraction PolymorphicTypeValidator, for limiting subtypes allowed by default typing, @JsonTypeInfo #2195? I can offer some help.
  7. cowtowncoder commented on Apr 18, 2019

    @cowtowncoder
    Member

    Implementation of #2195 is targeted for 2.10; I originally was thinking 3.x but I think it can't really wait that far.

    I appreciate your offer to help, but unfortunately limit I have is time, not idea of how to implement this. So I don't think this is something that I can effectively parallelize until I get something working.
    However, as soon as I have some pieces scoped I could definitely use help in validating my design and feedback like improvement suggestions.

  8. cowtowncoder commented on May 2, 2019

    @cowtowncoder
    Member

    @lukaszlenart @artem-smotrakov just a quick note: finally implemented most of #2195 so looking for feedback soon. I am reasonably content at design but hoping others to poke holes in it.

  9. lukaszlenart commented on May 6, 2019

    @lukaszlenart
    Author

    Nice, thanks a lot @cowtowncoder :) Is this already included in a released version?

  10. cowtowncoder commented on May 6, 2019

    @cowtowncoder
    Member

    @lukaszlenart No, it's still work-in-progress. It will be in 2.10.0; being API addition won't be backported.
    But hoping to get the first pre-release (2.10.0.pr1) out within May 2019.

  11. lukaszlenart commented on May 7, 2019

    @lukaszlenart
    Author

    Great!

  12. bmaxwell commented on Oct 7, 2019

    @bmaxwell

    Is there any ETA on this? It looks like there is going to be a continuous stream of CVEs to blacklist classes. The codehaus jackson added a whitelist which protects against any new classes from needing to be blacklisted and also lets the applications know and allow the classes to be deserialized.

  13. cowtowncoder commented on Oct 7, 2019

    @cowtowncoder
    Member

    @bmaxwell This was implemented via #2195 included in 2.10.0 (which was released 1 week ago) so closing this as dup. Overview of new features, including this one at

    https://medium.com/@cowtowncoder/jackson-2-10-features-cd880674d8a2

    but I hope to find time to blog about Safe Default Typing feature in bit more detail.

  14. added
    duplicateDuplicate of an existing (usually earlier) issue
    and removed
    3.xIssues to be only tackled for Jackson 3.x, not 2.x
    on Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateDuplicate of an existing (usually earlier) issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions