CVE-2026-17495: moment vulnerable to Path Traversal via crafted non-string locale name
Impact
moment before 2.31.0 is vulnerable to path traversal in moment.locale(). When an application passes a non-string, attacker-influenced value to moment.locale(), a specially crafted object can bypass the locale name validation and cause moment to load a file from an attacker-controlled path. This is a further bypass of the validation added in 2.29.2 for CVE-2022-24785.
This affects server-side (npm) users only. Plain string input is not affected: the existing validation correctly rejects strings that contain path separators.
Patches
This issue is patched in moment 2.31.0.
Workarounds
Validate that any user-supplied input is a string before passing it to moment.locale().
Other sources
moment is a JavaScript date library for parsing, validating, manipulating, and formatting dates. In versions 2.29.2 through 2.30.1, a specially crafted non-string object passed to moment.locale() can bypass the locale-name path-traversal guard. The guard assumes the input is a string, so an object whose match() method satisfies the check while its toString() returns a traversal path reaches an internal require() call with attacker-controlled path segments. This is an incomplete fix for CVE-2022-24785 and primarily affects npm (server-side) users that pass user-provided input directly to moment.locale(). The issue is fixed in moment 2.31.0, and users should upgrade to 2.31.0 or later. As a workaround, validate that any user-supplied input is a string before passing it to moment.locale().
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/momentto a version that resolves this vulnerability.Fixed in 2.31.0 - Upgrade
Upgrade
momentto a version that resolves this vulnerability.Fixed in 2.31.0 - Compensating control
Validate that any user-supplied input is a string before passing it to moment.locale().
Event History
Frequently Asked Questions
Which deployments are most likely to be exposed?
The issue primarily affects server-side npm users that pass user-provided input directly to moment.locale(). The affected version range is 2.29.2 through 2.30.1.
What must an attacker provide to exploit this issue?
An attacker must be able to supply a specially crafted non-string object to moment.locale(). Its match() method must satisfy the locale-name guard while its toString() method returns a traversal path used by an internal require() call.
Are default uses of moment.locale() affected?
The provided information identifies exposure when user-provided input is passed directly to moment.locale(). It does not indicate that applications using only application-controlled locale values are affected.
What can be done if upgrading is not immediately possible?
Validate that any user-supplied value is a string before passing it to moment.locale(). Upgrade to moment 2.31.0 or later when possible.