-
Notifications
You must be signed in to change notification settings - Fork 4
fix: keep extra manifest paths portable #39
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -126,6 +126,32 @@ export function expandHome(inputPath: string, homeDir: string): string { | |||||||||||||
| return inputPath; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function collapseHome( | ||||||||||||||
| inputPath: string, | ||||||||||||||
| homeDir: string, | ||||||||||||||
| platform: NodeJS.Platform = process.platform | ||||||||||||||
| ): string { | ||||||||||||||
| if (!inputPath) return inputPath; | ||||||||||||||
| if (!homeDir) return inputPath; | ||||||||||||||
|
|
||||||||||||||
| if (inputPath === '~' || inputPath.startsWith('~/')) return inputPath; | ||||||||||||||
|
|
||||||||||||||
| // Best-effort on POSIX platforms. | ||||||||||||||
| if (platform === 'win32') return inputPath; | ||||||||||||||
|
|
||||||||||||||
| const resolvedHome = path.resolve(homeDir); | ||||||||||||||
| const resolvedPath = path.resolve(inputPath); | ||||||||||||||
|
|
||||||||||||||
| if (resolvedPath === resolvedHome) return '~'; | ||||||||||||||
|
|
||||||||||||||
| const prefix = `${resolvedHome}${path.sep}`; | ||||||||||||||
| if (resolvedPath.startsWith(prefix)) { | ||||||||||||||
| return `~/${resolvedPath.slice(prefix.length)}`; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return inputPath; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function normalizePath( | ||||||||||||||
| inputPath: string, | ||||||||||||||
| homeDir: string, | ||||||||||||||
|
|
@@ -315,11 +341,20 @@ function buildExtraPathPlan( | |||||||||||||
| manifestPath: string, | ||||||||||||||
| platform: NodeJS.Platform | ||||||||||||||
| ): ExtraPathPlan { | ||||||||||||||
| const allowlist = (inputPaths ?? []).map((entry) => | ||||||||||||||
| // Keep sourcePath portable ("~/...") so the manifest and hashed filenames | ||||||||||||||
| // are stable across machines/OSes. Use a normalized allowlist for matching. | ||||||||||||||
| const rawPaths = (inputPaths ?? []).filter( | ||||||||||||||
| (entry) => typeof entry === 'string' && entry.length > 0 | ||||||||||||||
| ); | ||||||||||||||
| const portablePaths = rawPaths.map((entry) => | ||||||||||||||
| collapseHome(entry, locations.xdg.homeDir, platform) | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| const allowlist = portablePaths.map((entry) => | ||||||||||||||
| normalizePath(entry, locations.xdg.homeDir, platform) | ||||||||||||||
| ); | ||||||||||||||
|
Comment on lines
+353
to
355
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For improved clarity, consider generating the
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| const entries = allowlist.map((sourcePath) => ({ | ||||||||||||||
| const entries = portablePaths.map((sourcePath) => ({ | ||||||||||||||
| sourcePath, | ||||||||||||||
| repoPath: path.join(repoExtraDir, encodeExtraPath(sourcePath)), | ||||||||||||||
| })); | ||||||||||||||
|
|
||||||||||||||
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.
The
applyExtraPathsfunction trusts therepoPathvalue from theextra-manifest.jsonfile in the repository. If this value is an absolute path or contains path traversal sequences (e.g.,../../), it can point to arbitrary files on the user's system. Since this path is used as the source for a copy operation where the destination is an allowlisted local path, an attacker who controls the repository can trick the system into copying sensitive files (like/etc/shadowor SSH keys) into the sync directory. A subsequentsync-pushwould then upload these sensitive files to the repository, leading to data exfiltration. Additionally, themodeproperty from the manifest is used inchmodwithout validation, allowing an attacker to change permissions of allowlisted files.