Skip to content

Add built-in root bounded File System APIs #65146

Description

@qurafi

What is the problem this feature will solve?

The current FS API does not have limits on what paths are accessed. Most of the time we works with FS operations that are bounded to certain folders like the current package's root. However, a bad code or even a malicious user-input can lead to unintended operations or security risks.

What is the feature you are proposing to solve the problem?

Provide an API like Go's os.Root.

An example API would looks like this:

const root = process.cwd()
const fs = new fs.Root(root)

fs.readFileSync("../out/of/bound/path") // Error out of bound file operation

fs.readFileSync("./misdirectedlink") // Error -> symlinks are checked against root

fs.rmSync(path.join(root, "../bad_path"), {force: true, recursive: true}); // wipes unintended files should throw error

What alternatives have you considered?

There's currently a 3rd party package @openclaw/fs-safe. but I think it should have been built-in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status
    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions