Skip to content

Optimize UntypedObjectDeserializer wrt recursion [CVE-2020-36518]Β #2816

Closed

Description

@cowtowncoder

EDIT: related to to CVE-2020-36518 (see https://nvd.nist.gov/vuln/detail/CVE-2020-36518)

EDIT: Fix included in

EDIT: included as one of Snyk's "top-10 vulns of 2022" CVEs -- see https://go.snyk.io/snyk-top-10-open-source-vulnerabilities-dwn-typ.html


Current implementation UntypedObjectDeserializer is relatively expensive for deeply nested Object and Array values as it uses recursion even for "vanilla" case (one where there are no custom List/array or Map deserializers).
In practical terms it is possible to exhaust typical modest JVM memory with documents having about ten thousand levels of nestings, due to size of call stack from recursive calls.

NOTE: specifically this ONLY APPLIES if the target type is "untyped" or generic Collection<Object> / Map<String, Object> -- it DOES NOT APPLY to cases where target is POJO (except if POJO itself has "untyped" property or properties).

Similar issue was already solved wrt JsonNode (see #3397), included in 2.13.0; this might show a way to approach this problem: by replacing simple recursion with iteration, either completely or at some inner levels.

Also note that it may ultimately be necessary to have lower-level constraints for streaming parser too, see: FasterXML/jackson-core#637

Ideally it should be:

  1. Possible to handle at least tens of thousands of levels of nesting (100k should be processable with 256M heap, say)
  2. Have streaming level limits that -- by default -- block documents with more than limit we deem safe (less than 100k -- perhaps 10k or something, to be determined).

This issue is specifically about (1) as (2) is about jackson-core.

Activity

  1. added a commit that references this issue on Aug 13, 2020
  2. cowtowncoder commented on Aug 13, 2020

    @cowtowncoder
    MemberAuthor

    Looks like nesting of about 2000 works, 3000 fails, with default settings for both Arrays and Objects.

  3. added a commit that references this issue on Aug 13, 2020
  4. cowtowncoder commented on Aug 23, 2020

    @cowtowncoder
    MemberAuthor

    Tagging as "performance" (since resource consumption of call stack causes the exception). Also added similar test for JsonNode. Hoping to eventually tackle for these types but realistically support from streaming parser (jackson-core) is probably needed (will file separate ticket) for more general complexity limits for input documents.

  5. added
    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issue
    on Feb 20, 2021
  6. added
    most-wantedTag to indicate that there is heavy user +1'ing action (5 or more)
    and removed on Jul 15, 2021
  7. cowtowncoder commented on Feb 10, 2022

    @cowtowncoder
    MemberAuthor

    FWTW, similar issues does NOT affect JsonNode, as of Jackson 2.13.0 and later on.
    Should have created separate issue to point to, but iterate version of JsonNodeDeserializer was merged in at around March 2021.
    Would be great to achieve the same here for 2.14.

    Could start with UntypedObjectDeserializer.Vanilla first, see if generalizable to full case (should be).

  8. meier-th commented on Mar 12, 2022

    @meier-th

    @cowtowncoder , could you please clarify if the same fix is planned to be backported to the versions 2.12.x and 2.11.x of Jackson?

  9. cowtowncoder commented on Mar 13, 2022

    @cowtowncoder
    MemberAuthor

    EDIT: fix actually backported, see initial Description (now Edited as well) for details.


    @meier-th Very unlikely that I would try to backport this to anything prior to 2.14.0. The new implementation probably has non-trivial chance of regression and this functionality is widely used. Note that no implementation yet exists, but I fully intend to work on this to try to get it done for 2.14.0 (or someone else could beat me to it).

  10. 95 remaining items

  11. yhs0092 commented on Apr 11, 2022

    @yhs0092

    Hi, is this a typo mistake? I find the bom version of 2.12 mentioned above is 2.12.6.1.20220326, but in the release notes it's 2.12.6.20220326.

    image

  12. MaximilianTews commented on Apr 13, 2022

    @MaximilianTews
    Contributor

    Hi @cowtowncoder, any way to determine if one is affected or not?
    You write that UntypedObjectDeserializer needs to be used in combination with Collection / Map<String, Object> - at least this is what I understand.
    I scanned my code and we are not using UntypedObjectDeserializer, however, it might be used by other jackson-databind code that we use. Could you please clarify how to determine if one is affected by this CVE?

  13. jtnord commented on Apr 14, 2022

    @jtnord

    @cowtowncoder

    2.12.6.1: (see https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.12)
    use with jackson-bom version 2.12.6.1.20220326

    the version for the bom here looks incorrect, should be 2.12.6.20220326 ?

    https://github.com/FasterXML/jackson-bom/tree/jackson-bom-2.12.6.20220326

  14. added a commit that references this issue on Apr 14, 2022
  15. added a commit that references this issue on May 31, 2022
  16. MaximilianTews commented on Jun 2, 2022

    @MaximilianTews
    Contributor

    Hi @cowtowncoder, could you please clarify what methods are affected by this vulnerability? I am specifically interested if ObjectMapper.readTree and ObjectMapper.readValue are affected?

  17. yawkat commented on Jun 2, 2022

    @yawkat
    Member

    readTree is not affected, readValue is affected if you use untyped fields somewhere in the object graph youre deserializing

  18. cowtowncoder commented on Jun 2, 2022

    @cowtowncoder
    MemberAuthor

    @MaximilianTews see #2816 for more information. This is just a rewrite of that fix.

    And @yawkat is correct: readTree() is not affected. readValue() MAY be affected BUT ONLY if the nominal type is or includes target type of java.lang.Object. Term "untyped" in Jackson context means java.lang.Object as binding target type (either explicitly, or via raw types, ? type parameter and so on).

  19. added a commit that references this issue on Jun 13, 2022
  20. added a commit that references this issue on Jun 14, 2022
  21. modified the milestones: 2.13.2.1, 2.13.3 on Nov 15, 2022
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

    CVEIssues related to public CVEs (security vuln reports)most-wantedTag to indicate that there is heavy user +1'ing action (5 or more)performanceIssue related to performance problems or enhancements

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions