Skip to content

fix(auth): ensure absolute paths for auth file handling#2269

Merged
LTbinglingfeng merged 1 commit intodevfrom
auth-fix
Mar 22, 2026
Merged

fix(auth): ensure absolute paths for auth file handling#2269
LTbinglingfeng merged 1 commit intodevfrom
auth-fix

Conversation

@LTbinglingfeng
Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 focuses on improving the robustness of authentication file handling by ensuring that all file paths are treated as absolute paths. This change addresses potential security concerns and ensures consistent behavior across different environments.

Highlights

  • Path Handling: Ensures that file paths are properly handled as absolute paths within the authentication logic.
  • Security: Prevents potential issues arising from relative paths, enhancing the reliability of authentication file operations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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
Copy Markdown
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 correctly ensures that paths are absolute before being used to calculate a relative path, which is a good fix. I've identified some opportunities for improvement, including code duplication and a redundant function call. My review comments provide specific suggestions to enhance the code's maintainability.

Comment on lines +742 to +747
path = filepath.Clean(path)
if !filepath.IsAbs(path) {
if abs, errAbs := filepath.Abs(path); errAbs == nil {
path = abs
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This logic to ensure a path is absolute is duplicated for authDir on lines 755-760. To improve maintainability and reduce code duplication, consider extracting this logic into a helper function.

For example:

func toAbs(p string) string {
    p = filepath.Clean(p)
    if !filepath.IsAbs(p) {
        if abs, err := filepath.Abs(p); err == nil {
            return abs
        }
    }
    return p
}

With such a helper, this block and the one for authDir could be simplified to a single function call.

authDir = resolvedAuthDir
}
if authDir != "" {
authDir = filepath.Clean(authDir)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The util.ResolveAuthDir function called on line 751 already returns a cleaned path, making this call to filepath.Clean redundant. You can safely remove this line.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5331d51f27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 750 to 754
authDir := strings.TrimSpace(h.cfg.AuthDir)
if resolvedAuthDir, errResolve := util.ResolveAuthDir(authDir); errResolve == nil && resolvedAuthDir != "" {
authDir = resolvedAuthDir
}
if authDir != "" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep auth ID generation aligned with raw store base dirs

This starts canonicalizing cfg.AuthDir inside authIDForPath, but the store-backed IDs are still derived from the raw config value (sdk/auth/filestore.go:260-271, internal/store/gitstore.go:452-460) and the SDK/service startup path I checked (sdk/cliproxy/service.go:493-505) never calls ResolveAuthDir. In embedded/server setups that pass AuthDir as ~/... or another non-canonical form, the same auth file will now load from the store under one ID and be updated/deleted through management under a different ID, which leaves stale entries behind or creates duplicates instead of updating the existing auth.

Useful? React with 👍 / 👎.

@LTbinglingfeng LTbinglingfeng merged commit db335ac into dev Mar 22, 2026
2 checks passed
@hkfires hkfires deleted the auth-fix branch March 23, 2026 00:57
Adamcf123 pushed a commit to Adamcf123/CLIProxyAPI that referenced this pull request Mar 24, 2026
fix(auth): ensure absolute paths for auth file handling
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