Skip to content

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

Closed

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.

Activity

  1. added a commit that references this issue on Apr 5, 2026
    c7b949a
  2. garrytan commented on Apr 9, 2026

    @garrytan
    Owner

    Addressed by #852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions