Executive brief
moment.js is a popular JavaScript library for parsing, validating, and formatting dates and times, widely used in web applications and Node.js servers. A path traversal vulnerability allows attackers to read arbitrary files from the server by injecting specially crafted locale strings (e.g., using "../" sequences). This impacts applications that allow users to specify locale names without proper validation.
Technical details
The vulnerability is a path traversal flaw (CWE-22, CWE-27) in moment.js locale loading functionality. When a user-controlled string is passed to the locale-switching function, the library constructs file paths without properly sanitizing "../" sequences, allowing directory traversal attacks. An attacker can read arbitrary files on the server by crafting a malicious locale string such as "../../etc/passwd". The attack requires the application to accept user input for locale selection and pass it directly to moment.js. This is fixed in version 2.29.2; users of versions 1.0.1 through 2.29.1 should upgrade or sanitize locale input.
Affected products
- moment.js moment 1.0.1 through 2.29.1
Timeline
- 2022-04-04: disclosed: Publicly disclosed via GHSA-8hfj-j24r-96c4
- 2022-04-04: patched: Fixed in version 2.29.2