-
Notifications
You must be signed in to change notification settings - Fork 3
fix(core): harden workspace path containment #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@gh-symphony/cli": patch | ||
| --- | ||
|
|
||
| Harden workspace path validation against traversal and symlink escapes across platforms (hojinzs/github-symphony#528). |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { lstatSync, realpathSync } from "node:fs"; | ||
| import { basename, dirname, isAbsolute, join, relative } from "node:path"; | ||
|
|
||
| function realpathWithMissingTail(path: string): string | null { | ||
| let current = path; | ||
| const missingTail: string[] = []; | ||
|
|
||
| while (true) { | ||
| try { | ||
| return join(realpathSync(current), ...missingTail); | ||
| } catch (error) { | ||
| if ( | ||
| !(error instanceof Error && "code" in error && error.code === "ENOENT") | ||
| ) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| const parent = dirname(current); | ||
| if (parent === current) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| if (lstatSync(current).isSymbolicLink()) { | ||
| return null; | ||
| } | ||
| } catch (error) { | ||
| if ( | ||
| !(error instanceof Error && "code" in error && error.code === "ENOENT") | ||
| ) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| missingTail.unshift(basename(current)); | ||
| current = parent; | ||
| } | ||
| } | ||
|
|
||
| export function isPathWithinRoot( | ||
| root: string, | ||
| candidate: string, | ||
| allowRoot = true | ||
| ): boolean { | ||
| const realRoot = realpathWithMissingTail(root); | ||
| const realCandidate = realpathWithMissingTail(candidate); | ||
|
|
||
| if (!realRoot || !realCandidate) { | ||
| return false; | ||
| } | ||
|
|
||
| const rel = relative(realRoot, realCandidate); | ||
|
|
||
| return ( | ||
| (allowRoot && rel === "") || | ||
| (rel !== "" && !rel.startsWith("..") && !isAbsolute(rel)) | ||
| ); | ||
|
Comment on lines
+55
to
+58
|
||
| } | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit · low severity]
!rel.startsWith("..")는 이탈이 아닌 정상 이름도 오탐(false positive)으로 거부합니다.relative(root, root/"..config")는"..config"를 반환하는데, 이 값은startsWith("..")에 걸려 이탈로 판정됩니다. 실제로..config는 root 하위의 정상 디렉터리입니다. 로컬 스모크 테스트로 확인:resolveIssueWorkspaceDirectory에서는startsWith(".")reserved 검사에 먼저 걸려 가려지지만,resolveWorkspaceDirectory(safety.ts) 경로에는 그 방어막이 없습니다.!rel.startsWith(".."))을 그대로 따른 것이라 blocking 은 아닙니다.정밀하게 하려면 세그먼트 경계까지 확인하는 형태를 권장합니다:
선택 사항이며 후속 처리로 남겨도 무방합니다.
Generated by Claude Code