Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions doc/api/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,29 @@ added: v0.11.2
* `path` {string}
* Returns: {boolean}

The `path.isAbsolute()` method determines if `path` is an absolute path.
The `path.isAbsolute()` method determines if the literal `path` is absolute.
Therefore, it’s not safe for mitigating path traversals without normalizing it.

```js
// Normalizing the subpath mitigates traversing above the mount directory
const subpath = '/foo/../..'
if (!path.isAbsolute(path.normalize(subpath))) {
throw 'FORBIDDEN'
}
const myPath = path.join(MOUNT_DIR, subpath)
Comment thread
ericfortis marked this conversation as resolved.
Outdated
```


If the given `path` is a zero-length string, `false` will be returned.

For example, on POSIX:
On POSIX:
Comment thread
ericfortis marked this conversation as resolved.
Outdated

```js
path.isAbsolute('/foo/bar'); // true
path.isAbsolute('/baz/..'); // true
path.isAbsolute('qux/'); // false
path.isAbsolute('.'); // false
path.isAbsolute('/foo/bar'); // true
path.isAbsolute('/baz/..'); // true
path.isAbsolute('/baz/../..'); // true
path.isAbsolute('qux/'); // false
path.isAbsolute('.'); // false
```

On Windows:
Expand Down