CVE-2026-17495
Patch Available.
This Vulnerability has been fixed in the Never-Ending Support (NES) version offered by HeroDevs.
Overview
Moment.js is a JavaScript library for parsing, validating, manipulating, and formatting dates. It runs in browsers and in Node.js, where it loads its locale files on demand.
A path traversal vulnerability (CVE-2026-17495) has been identified in the locale loading of Moment.js, which allows attackers to make moment.locale() load a file from an attacker-controlled path when an application passes it a crafted non-string value. This is a further bypass of the locale name validation added in 2.29.2 for CVE-2022-24785.
Per OWASP: A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the web root folder. By manipulating variables that reference files with "dot-dot-slash (../)" sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system including application source code or configuration and critical system files.
This issue affects Moment.js versions 2.29.2 and greater, prior to 2.31.0, when used server-side in Node.js.
Details
Module Info
- Product: Moment.js
- Affected packages:
moment - Affected versions: >=2.29.2 <2.31.0
- GitHub repository: https://github.com/moment/moment
- Published packages: https://www.npmjs.com/package/moment
- Package manager: npm
- Fixed in:
- OSS Moment.js 2.31.0
- NES for Moment.js v2.30.3
Vulnerability Info
This Medium-severity vulnerability is found in the moment package in versions 2.29.2 through 2.30.1 of Moment.js.
When Moment.js runs under CommonJS and is asked for a locale it has not loaded yet, loadLocale() builds a module path from the locale name and passes it to require(). To stop that path from leaving the locale directory, isLocaleNameSane() is supposed to reject any name that looks like a filesystem path:
function isLocaleNameSane(name) {
// Prevent names that look like filesystem paths, i.e contain '/' or '\'
// Ensure name is available and function returns boolean
return !!(name && name.match('^[^/\\\\]*$'));
}
function loadLocale(name) {
// ...
if (
locales[name] === undefined &&
typeof module !== 'undefined' &&
module &&
module.exports &&
isLocaleNameSane(name)
) {
try {
oldLocale = globalLocale._abbr;
aliasedRequire = require;
aliasedRequire('./locale/' + name);
// ...
The check assumes name is a string. It never verifies the type, so a crafted non-string value can pass isLocaleNameSane() even though the string that './locale/' + name produces contains traversal sequences. require() then loads a module from outside the locale directory, and any code in that module runs inside the application. Plain string input is not affected, because the check correctly rejects strings that contain / or \.
An attacker would need an application that passes attacker-influenced, non-string input, such as a value taken from a parsed request body, to moment.locale() in Node.js, and a file they can get loaded at the traversed path. Browser builds do not load locales with require() and are not affected.
Mitigation
Moment.js is a legacy project in maintenance mode, and only its latest release receives fixes. For more information see here.
Users of the affected components should apply one of the following mitigations:
- Upgrade affected applications to Moment.js 2.31.0 or later, or migrate them away from Moment.js.
- Leverage a commercial support partner like HeroDevs for post-EOL security support.
Credits
- zolbooo (finder)
