Skip to content

Fix cookie-import path validation bypass + hardcoded /tmp#852

Open
urbantech wants to merge 1 commit intogarrytan:mainfrom
urbantech:fix/707-708-path-validation-and-tmp
Open

Fix cookie-import path validation bypass + hardcoded /tmp#852
urbantech wants to merge 1 commit intogarrytan:mainfrom
urbantech:fix/707-708-path-validation-and-tmp

Conversation

@urbantech
Copy link
Copy Markdown

Summary

Two security/portability fixes in the browse cookie-import command.

#707 — Path validation bypass via relative paths

Before: Relative paths like ../../etc/shadow bypassed the safe-directory check because path.isAbsolute() gated the entire validation block. Only the .. pattern check ran for relative paths, but a relative path without .. (e.g., sensitive-file.json in an unexpected cwd) passed through completely.

After: Always path.resolve() to absolute, then resolve symlinks (matching validateOutputPath()), then check against SAFE_DIRECTORIES. No separate code paths for relative vs absolute.

#708 — Hardcoded /tmp in cookie-import-browser.ts

Before: openDbFromCopy() hardcoded /tmp/browse-cookies-.... On Windows, /tmp may not exist.

After: Uses path.join(os.tmpdir(), ...). The os module was already imported.

Test Plan

  • All 224 browse tests pass (bun test browse/test/)
  • Path validation tests: 29 pass
  • Cookie import tests: 22 pass
  • Traversal test updated to accept both error messages

Fixes #707, fixes #708

cookie-import (write-commands.ts):
- Always resolve to absolute path before safe-directory check (garrytan#707)
- Resolve symlinks (macOS /tmp → /private/tmp) matching validateOutputPath()
- Relative paths like '../../etc/shadow' now correctly blocked
- Removes separate path.isAbsolute gate that let relative paths skip validation

cookie-import-browser.ts:
- Replace hardcoded /tmp with os.tmpdir() for cross-platform support (garrytan#708)

Tests updated to accept either 'Path must be within' or 'Path traversal'
error message for traversal attempts. All 224 browse tests pass.

Fixes garrytan#707, fixes garrytan#708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-platform: hardcoded /tmp in cookie-import-browser.ts Security: path validation bypass via relative paths in write-commands.ts

1 participant