Skip to content

fix: keep extra manifest paths portable#39

Closed
young5lee wants to merge 1 commit intoiHildy:mainfrom
young5lee:fix/portable-extra-manifest
Closed

fix: keep extra manifest paths portable#39
young5lee wants to merge 1 commit intoiHildy:mainfrom
young5lee:fix/portable-extra-manifest

Conversation

@young5lee
Copy link

Problem

When using extraConfigPaths / extraSecretPaths, sync-push writes extra-manifest.json with absolute sourcePath values (because paths are normalized via path.resolve()/home expansion).

Across machines/OSes this causes churn (/home/... vs /Users/...) and can lead to extras being skipped on pull (allowlist mismatch), then removed on the next push.

Fix

  • Store sourcePath in extra-manifest.json using a portable ~ form when the path is under the user's home directory.
  • Keep the allowlist normalized/absolute for matching.
  • Expand ~ when copying/stat-ing extra paths so runtime behavior stays correct.

Tests

  • Added coverage for portable sourcePath behavior in src/sync/paths.test.ts.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @young5lee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where extra-manifest.json stored absolute paths for extra configurations and secrets, leading to inconsistencies and potential failures across different environments. The solution introduces a mechanism to store home directory paths in a portable tilde-prefixed format within the manifest, while ensuring that these paths are correctly resolved to their absolute form during file system operations. This change improves cross-platform compatibility and reduces unnecessary churn in the manifest file.

Highlights

  • Portable Path Storage: Modified the extra-manifest.json to store sourcePath values using a portable tilde (~) form when paths are located within the user's home directory. This prevents churn across different machines and operating systems.
  • Runtime Path Expansion: Ensured that ~ prefixed paths are correctly expanded to their absolute form during runtime operations, such as copying files, checking path existence, and stat-ing files, to maintain correct functionality.
  • Allowlist Consistency: Maintained the allowlist of extra paths in a normalized and absolute format for accurate matching, separating it from the portable storage format.
  • New Test Coverage: Added new test cases to src/sync/paths.test.ts to validate the behavior of portable sourcePath storage and ensure paths outside the home directory remain absolute.
Changelog
  • src/sync/apply.ts
    • Imported the expandHome utility function.
    • Updated localPath resolution to use expandHome and path.resolve for entry.sourcePath.
    • Modified file system operations (pathExists, fs.stat, copyDirRecursive, copyFileWithMode) to use the newly resolved actualSourcePath.
  • src/sync/paths.test.ts
    • Added a test case to verify that extra manifest sourcePath values are stored using portable home paths (e.g., ~/.config/opencode/custom.json).
    • Added a test case to confirm that extra manifest sourcePath values remain absolute when outside the home directory (e.g., /etc/hosts).
  • src/sync/paths.ts
    • Introduced a new collapseHome function to convert absolute paths under the home directory into a tilde-prefixed format.
    • Modified buildExtraPathPlan to use collapseHome when generating portablePaths for extra.entries.
    • Ensured that the allowlist continues to use normalizePath to maintain absolute paths for matching purposes.
Activity
  • No specific activity (comments, reviews) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of non-portable paths in extra-manifest.json by introducing a ~-based home directory representation for paths. However, a high-severity path traversal vulnerability was identified in applyExtraPaths. This vulnerability arises because the repoPath from the repository's manifest is trusted without validation, which could allow a malicious repository to exfiltrate arbitrary files from a user's machine. It is recommended to validate that all paths from the manifest are relative and stay within the expected repository boundaries. Additionally, there is one suggestion to improve code clarity in src/sync/paths.ts.

? entry.repoPath
: path.join(plan.repoRoot, entry.repoPath);
const localPath = entry.sourcePath;
const localPath = path.resolve(expandHome(entry.sourcePath, plan.homeDir));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The applyExtraPaths function trusts the repoPath value from the extra-manifest.json file 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/shadow or SSH keys) into the sync directory. A subsequent sync-push would then upload these sensitive files to the repository, leading to data exfiltration. Additionally, the mode property from the manifest is used in chmod without validation, allowing an attacker to change permissions of allowlisted files.

Comment on lines +353 to 355
const allowlist = portablePaths.map((entry) =>
normalizePath(entry, locations.xdg.homeDir, platform)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved clarity, consider generating the allowlist directly from rawPaths. This would make the data flow more direct, as rawPaths would be the single source for both the runtime allowlist of absolute paths and the portablePaths for the manifest. This change improves readability without affecting functionality.

Suggested change
const allowlist = portablePaths.map((entry) =>
normalizePath(entry, locations.xdg.homeDir, platform)
);
const allowlist = rawPaths.map((entry) =>
normalizePath(entry, locations.xdg.homeDir, platform)
);

@young5lee young5lee closed this by deleting the head repository Mar 1, 2026
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.

1 participant