CVE-2018-3732 (published 2018-06-07T02:29Z)

resolve-path node module before 1.4.0 suffers from a Path Traversal vulnerability due to lack of validation of paths with certain special characters, which allows a malicious user to read content of any file with known path.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:P/I:N/A:N)
CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-22
cwe_name: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
description: The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
extended_description: 
            Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin" to access unexpected files. This is referred to as absolute path traversal.
         
         

Fix information:
repo_url: https://github.com/pillarjs/resolve-path
commit_details: repo_url: https://github.com/pillarjs/resolve-path
author: Douglas Christopher Wilson
author_date: 2018-02-13 12:21:56-05:00
msg: Fix resolving paths with certain special characters
repository: repo_url: https://github.com/pillarjs/resolve-path
repo_name: pillarjs/resolve-path
description: Resolve a relative path against a root path with validation
repo_language: JavaScript
owner: pillarjs
file_changes: filename: HISTORY.md
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,7 @@
 unreleased
 ==========
 
+  * Fix resolving paths with certain special characters
   * deps: http-errors@~1.6.2
     - Make `message` property enumerable for `HttpError`s
     - deps: depd@1.1.1

programming_language: Markdown
filename: index.js
change_type: ModificationType.MODIFY
diff: @@ -13,6 +13,7 @@
  */
 
 var createError = require('http-errors')
+var join = require('path').join
 var normalize = require('path').normalize
 var pathIsAbsolute = require('path-is-absolute')
 var resolve = require('path').resolve
@@ -82,9 +83,6 @@ function resolvePath (rootPath, relativePath) {
     throw createError(403)
   }
 
-  // resolve & normalize the root path
-  root = normalize(resolve(root) + sep)
-
-  // resolve the path
-  return resolve(root, path)
+  // join the relative path
+  return normalize(join(resolve(root), path))
 }

programming_language: JavaScript
filename: resolvePath.js
change_type: ModificationType.MODIFY
diff: @@ -31,6 +31,11 @@ describe('resolvePath(relativePath)', function () {
           normalize(join(process.cwd(), 'index.js')))
       })
 
+      it('should resolve relative with special characters', function () {
+        assert.equal(normalize(resolvePath('f:oo$bar')),
+          normalize(join(process.cwd(), './f:oo$bar')))
+      })
+
       it('should accept empty string', function () {
         assert.equal(normalize(resolvePath('')),
           normalize(process.cwd()))
@@ -89,6 +94,11 @@ describe('resolvePath(rootPath, relativePath)', function () {
           normalize(resolve(__dirname, 'index.js')))
       })
 
+      it('should resolve relative to rootPath with special characters', function () {
+        assert.equal(normalize(resolvePath(__dirname, 'f:oo$bar')),
+        normalize(resolve(__dirname, './f:oo$bar')))
+      })
+
       it('should accept relative path', function () {
         assert.equal(normalize(resolvePath(join(__dirname, '..'), 'index.js')),
           normalize(resolve(join(__dirname, '..'), 'index.js')))

programming_language: JavaScript