Skip to content

Security: path validation bypass via relative paths in write-commands.ts #707

@robertoecf

Description

@robertoecf

Hey — found this during a code review on our project where we vendor gstack.

File: browse/src/write-commands.ts:303

The path validation does strict boundary checks for absolute paths but falls back to a simple includes('..') for relative paths. That's easy to bypass.

Cleaner approach — always resolve first, then check:

const resolved = path.resolve(filePath);
const safeDirs = [TEMP_DIR, process.cwd()];
if (!safeDirs.some(dir => isPathWithin(resolved, dir))) {
  throw new Error("Path must be within: " + safeDirs.join(", "));
}

Happy to PR this if you want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions