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

Fix CVE–2022–31129 #400

Merged
merged 2 commits into from Jul 18, 2022

Conversation

debricked[bot]
Copy link
Contributor

@debricked debricked bot commented Jul 18, 2022

CVE–2022–31129

Vulnerable dependency:     moment (npm)    2.29.3

Vulnerability details

Description

NVD

moment is a JavaScript date library for parsing, validating, manipulating, and formatting dates. Affected versions of moment were found to use an inefficient parsing algorithm. Specifically using string-to-date parsing in moment (more specifically rfc2822 parsing, which is tried by default) has quadratic (N^2) complexity on specific inputs. Users may notice a noticeable slowdown is observed with inputs above 10k characters. Users who pass user-provided strings without sanity length checks to moment constructor are vulnerable to (Re)DoS attacks. The problem is patched in 2.29.4, the patch can be applied to all affected versions with minimal tweaking. Users are advised to upgrade. Users unable to upgrade should consider limiting date lengths accepted from user input.

GitHub

Inefficient Regular Expression Complexity in moment

Impact

  • using string-to-date parsing in moment (more specifically rfc2822 parsing, which is tried by default) has quadratic (N^2) complexity on specific inputs
  • noticeable slowdown is observed with inputs above 10k characters
  • users who pass user-provided strings without sanity length checks to moment constructor are vulnerable to (Re)DoS attacks

Patches

The problem is patched in 2.29.4, the patch can be applied to all affected versions with minimal tweaking.

Workarounds

In general, given the proliferation of ReDoS attacks, it makes sense to limit the length of the user input to something sane, like 200 characters or less. I haven't seen legitimate cases of date-time strings longer than that, so all moment users who do pass a user-originating string to constructor are encouraged to apply such a rudimentary filter, that would help with this but also most future ReDoS vulnerabilities.

References

There is an excellent writeup of the issue here: moment/moment#6015 (comment)

Details

The issue is rooted in the code that removes legacy comments (stuff inside parenthesis) from strings during rfc2822 parsing. moment("(".repeat(500000)) will take a few minutes to process, which is unacceptable.

CVSS details - 7.5

 

CVSS3 metrics
Attack Vector Network
Attack Complexity Low
Privileges Required None
User interaction None
Scope Unchanged
Confidentiality None
Integrity None
Availability High
References

    NVD - CVE-2022-31129
    Inefficient Regular Expression Complexity in moment · CVE-2022-31129 · GitHub Advisory Database · GitHub
    [bugfix] Fix redos in preprocessRFC2822 regex (#6015) · moment/moment@9a3b589 · GitHub
    [bugfix] Fix redos in preprocessRFC2822 regex by vovikhangcdv · Pull Request #6015 · moment/moment · GitHub
    Inefficient Regular Expression Complexity in moment · Advisory · moment/moment · GitHub
    Regular Expression Denial of Service (ReDoS) vulnerability found in moment
    moment/from-string.js at develop · moment/moment · GitHub
    Found a possible security concern · Issue #6014 · moment/moment · GitHub
    GitHub - moment/moment: Parse, validate, manipulate, and display dates in javascript.
    THIRD PARTY

 

Related information

📌 Remember! Check the changes to ensure they don't introduce any breaking changes.
📚 Read more about the CVE

 

@ghost
Copy link

ghost commented Jul 18, 2022

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@suculent suculent merged commit f6ebd0a into thinx-staging Jul 18, 2022
@suculent suculent deleted the debricked-fix-CVE_2022_31129-7d32d538c9658feb branch November 9, 2023 15:49
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

1 participant