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 #113

Closed

Conversation

debricked[bot]
Copy link

@debricked debricked bot commented Aug 8, 2022

CVE–2022–31129

Vulnerable dependency:     moment (npm)    2.27.0

Vulnerability details

Description

Uncontrolled Resource Consumption

The software does not properly control the allocation and maintenance of a limited resource thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources.

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
    [SECURITY] Fedora 35 Update: python-notebook-6.4.0-4.fc35 - package-announce - Fedora Mailing-Lists
    [SECURITY] Fedora 36 Update: python-notebook-6.4.11-3.fc36 - package-announce - Fedora Mailing-Lists

 

Related information

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

 

@AramAlsabti
Copy link
Contributor

Fixed in a801c3c

@ramogens ramogens deleted the debricked-fix-CVE_2022_31129-43ffd861d2a9fa24 branch November 14, 2023 13:26
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

3 participants