security: add path traversal guard to git-diff-service#57
Merged
Conversation
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
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>
This was referenced Apr 21, 2026
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>
This was referenced Apr 29, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add path traversal guard to
git-diff-service.tsto prevent reading files outside the git root via../../segments in file paths.Problem
readFileContentandgetAnnotatedFileusedpath.join(root, filePath)which does not prevent../traversal - an attacker-controlledfilePathcould escape the repository root and read arbitrary files on disk.Fix
path.joinwithpath.resolve(collapses../segments)startsWith(path.resolve(root))check after resolution'Path traversal detected'if the resolved path escapes the git rootreadFileContent, and two fallback paths ingetAnnotatedFilePart of #54