Headline
CVE-2022-24785: [bugfix] Avoid loading path-looking locales from fs · moment/moment@4211bfc
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.
@@ -62,6 +62,11 @@ function chooseLocale(names) {
return globalLocale;
}
function isLocaleNameSane(name) {
// Prevent names that look like filesystem paths, i.e contain ‘/’ or ‘\’
return name.match(‘^[^/\\\\]*$’) != null;
}
function loadLocale(name) {
var oldLocale = null,
aliasedRequire;
@@ -70,7 +75,8 @@ function loadLocale(name) {
locales[name] === undefined &&
typeof module !== ‘undefined’ &&
module &&
module.exports
module.exports &&
isLocaleNameSane(name)
) {
try {
oldLocale = globalLocale._abbr;