Skip to main content

CVE-2022-24785: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') in moment moment

Medium
Published: Mon Apr 04 2022 (04/04/2022, 00:00:00 UTC)
Source: CVE
Vendor/Project: moment
Product: moment

Description

Moment.js is a JavaScript date library for parsing, validating, manipulating, and formatting dates. A path traversal vulnerability impacts npm (server) users of Moment.js between versions 1.0.1 and 2.29.1, especially if a user-provided locale string is directly used to switch moment locale. This problem is patched in 2.29.2, and the patch can be applied to all affected versions. As a workaround, sanitize the user-provided locale name before passing it to Moment.js.

AI-Powered Analysis

AILast updated: 06/23/2025, 11:51:07 UTC

Technical Analysis

CVE-2022-24785 is a path traversal vulnerability identified in Moment.js, a widely used JavaScript library for date parsing, validation, manipulation, and formatting. The vulnerability affects server-side npm users of Moment.js versions from 1.0.1 up to but not including 2.29.2. The core issue arises when a user-supplied locale string is directly used to switch the locale in Moment.js without proper sanitization. This improper limitation of pathname (CWE-22) allows an attacker to craft malicious input that can traverse directories outside the intended locale directory. By exploiting this, an attacker could potentially access or manipulate files on the server that are outside the restricted directory, leading to unauthorized information disclosure or modification of files. The vulnerability is categorized under CWE-22 and CWE-27, indicating improper pathname restrictions and path traversal issues. The problem was patched in version 2.29.2, and the recommended mitigation includes sanitizing user-provided locale strings before passing them to Moment.js. There are no known exploits in the wild as of the published date, and no CVSS score is assigned. The vulnerability primarily impacts server-side applications that dynamically switch locales based on user input without validation, which is a common pattern in internationalized web applications.

Potential Impact

For European organizations, especially those operating web applications or services that utilize Moment.js on the server side for date localization, this vulnerability poses a risk of unauthorized file access or modification. Exploitation could lead to exposure of sensitive configuration files, user data, or other critical resources residing on the server. This could compromise confidentiality and integrity of data, potentially leading to further attacks such as privilege escalation or persistent backdoors. Given the widespread use of Moment.js in web development, organizations with multilingual or localized services are particularly at risk if they accept locale parameters from users without proper sanitization. The impact is heightened in sectors with strict data protection requirements, such as finance, healthcare, and government, where unauthorized data access can lead to regulatory penalties and reputational damage. However, since exploitation requires the application to use user-supplied locale strings directly and no known exploits exist, the immediate risk is moderate but should not be underestimated.

Mitigation Recommendations

1. Upgrade all Moment.js dependencies to version 2.29.2 or later, where the vulnerability is patched. 2. Implement strict input validation and sanitization on all user-supplied locale parameters before passing them to Moment.js. This includes whitelisting allowed locale strings and rejecting or escaping any input containing path traversal characters such as '../' or absolute path indicators. 3. Review server-side code to ensure that locale switching does not rely on unsanitized user input. 4. Employ runtime application self-protection (RASP) or web application firewalls (WAF) with rules to detect and block path traversal attempts targeting locale parameters. 5. Conduct code audits and penetration testing focusing on localization features to identify any residual path traversal risks. 6. Monitor logs for unusual file access patterns or errors related to locale loading that could indicate attempted exploitation. 7. Educate development teams about secure handling of user input in localization contexts to prevent similar vulnerabilities.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-02-10T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9843c4522896dcbf2b57

Added to database: 5/21/2025, 9:09:23 AM

Last enriched: 6/23/2025, 11:51:07 AM

Last updated: 8/11/2025, 10:27:40 PM

Views: 15

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats