function assertRealPathContained
Since 0.1.0
assertRealPathContained(
fs: Pick<IFileSystem, "realPath" | "stat">,
root: string,
target: string
): Promise<boolean>

Asserts that a target path is contained within a root by comparing canonical paths.

This function uses the filesystem's realPath capability to resolve symlinks and compare canonical paths, preventing symlink-based traversal attacks.

Parameters

fs: Pick<IFileSystem, "realPath" | "stat">

The filesystem to use for path resolution

root: string

The root directory (must be an absolute path)

target: string

The target path to check (must be an absolute path)

Return Type

Promise<boolean>

True if the target is contained within the root

Throws

Error

If the target is not contained within the root or cannot be resolved

Usage

import { assertRealPathContained } from "common/src/index.ts";