Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
doc: clarify path.isAbsolute doesn’t resolve paths
  • Loading branch information
ericfortis committed Mar 2, 2025
commit b68f49b105f8385faf70b145e64343434087af6e
14 changes: 2 additions & 12 deletions doc/api/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,11 @@ added: v0.11.2
* Returns: {boolean}

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)
```

Therefore, it’s not safe for mitigating path traversals.

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

On POSIX:
For example, on POSIX:

```js
path.isAbsolute('/foo/bar'); // true
Expand Down