]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Avoid loading path-looking locales from fs
authorIskren Chernev <me@iskren.info>
Sun, 27 Mar 2022 11:46:47 +0000 (14:46 +0300)
committerIskren Chernev <me@iskren.info>
Sun, 27 Mar 2022 12:28:21 +0000 (15:28 +0300)
src/lib/locale/locales.js

index 0d082327545c67c3f872b348aab64d8397d896e1..b329b83b3a335a696a81b6a0c858cd81e31fc42e 100644 (file)
@@ -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;