Skip to content

security: add path traversal guard to git-diff-service#57

Merged
InbarR merged 1 commit into
InbarR:mainfrom
yoziv:security/yoziv/fix-diff-path-traversal
Apr 21, 2026
Merged

security: add path traversal guard to git-diff-service#57
InbarR merged 1 commit into
InbarR:mainfrom
yoziv:security/yoziv/fix-diff-path-traversal

Conversation

@yoziv
Copy link
Copy Markdown
Contributor

@yoziv yoziv commented Apr 19, 2026

Summary

Add path traversal guard to git-diff-service.ts to prevent reading files outside the git root via ../../ segments in file paths.

Problem

readFileContent and getAnnotatedFile used path.join(root, filePath) which does not prevent ../ traversal - an attacker-controlled filePath could escape the repository root and read arbitrary files on disk.

Fix

  • Replace path.join with path.resolve (collapses ../ segments)
  • Add startsWith(path.resolve(root)) check after resolution
  • Throw 'Path traversal detected' if the resolved path escapes the git root
  • Applied to all 3 call sites: readFileContent, and two fallback paths in getAnnotatedFile

Part of #54

path.join(root, filePath) could escape the git root when filePath contains ../ segments. Now uses path.resolve and verifies the result stays within the git root.

Part of InbarR#54

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@InbarR InbarR merged commit 90e0e91 into InbarR:main Apr 21, 2026
6 checks passed
InbarR pushed a commit that referenced this pull request Apr 21, 2026
Follow-up to #57. Two issues with the original startsWith check:

1. startsWith alone is vulnerable to sibling-dir bypass: if root is
   `/home/user`, a crafted path resolving to `/home/user-evil/secret`
   would pass `startsWith('/home/user')`. Fixed by requiring either
   exact equality with the resolved root OR startsWith(root + path.sep).

2. readFileContent() was not covered by #57 — it still used path.join
   with no check. Added the same guard there.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
yoziv added a commit to yoziv/tmax that referenced this pull request Apr 29, 2026
Pure-function tests (run without Electron packaging):
- PR InbarR#53/InbarR#56: extractLinkFromHtml + unwrapSafelinks (16 tests)
  Extracted to src/renderer/utils/link-extract.ts, shared by
  TerminalPanel.tsx and DetachedApp.tsx (deduplication)
- PR InbarR#57: path traversal guard (10 tests)
  Extracted to src/main/utils/security-guards.ts
- PR InbarR#58: OPEN_PATH extension blocklist (28 tests)
- PR InbarR#60: WSL distro name validation (9 tests)

E2E tests (require npm run package):
- PR InbarR#75: session rename propagates to pane title
- PR InbarR#13: minimum pane size enforcement
- PR InbarR#14: DEC focus sequence injection on pane switch
- PR InbarR#9: ShortcutsHelp escape in capture phase
- PR InbarR#10: pane title doesn't overlap terminal content
- PR InbarR#8: shifted key character in Ctrl+Shift+/ binding

Also extracts duplicated link-extract functions from
TerminalPanel.tsx and DetachedApp.tsx into a shared utility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
InbarR pushed a commit that referenced this pull request May 2, 2026
Pure-function tests (run without Electron packaging):
- PR #53/#56: extractLinkFromHtml + unwrapSafelinks (16 tests)
  Extracted to src/renderer/utils/link-extract.ts, shared by
  TerminalPanel.tsx and DetachedApp.tsx (deduplication)
- PR #57: path traversal guard (10 tests)
  Extracted to src/main/utils/security-guards.ts
- PR #58: OPEN_PATH extension blocklist (28 tests)
- PR #60: WSL distro name validation (9 tests)

E2E tests (require npm run package):
- PR #75: session rename propagates to pane title
- PR #13: minimum pane size enforcement
- PR #14: DEC focus sequence injection on pane switch
- PR #9: ShortcutsHelp escape in capture phase
- PR #10: pane title doesn't overlap terminal content
- PR #8: shifted key character in Ctrl+Shift+/ binding

Also extracts duplicated link-extract functions from
TerminalPanel.tsx and DetachedApp.tsx into a shared utility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants