-
Notifications
You must be signed in to change notification settings - Fork 1
Improved Usernames / Organization / Groups Path Matching in credentials #4
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
base: main
Are you sure you want to change the base?
Conversation
The old version only supported host verification. When combined with useHttpPath, it could only check a single-level path for usernames, organizations, or groups, not the full path.
If the first line matched the host or the first-level path, those credentials were returned, even if a later line specified a more precise path.
Example:
https://USERNAME:TOKEN1@gitlab.com/group/subgroup1/project.git
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
https://USERNAME:TOKEN3@gitlab.com/group/subgroup2/
https://USERNAME:TOKEN4@gitlab.com/group/
For the repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Without useHttpPath: Only the host, protocol, and HTTP username (if specified) are checked. It returns TOKEN1.
With useHttpPath (old version), only the first-level path was checked, even though the rest of the path did not match. In this case, it’s the same as above, so it returns TOKEN1.
Now, The system checks if the path configured in the credentials is the beginning of the requested path.
For the same repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Without useHttpPath: Behavior remains unchanged (returns TOKEN1).
With useHttpPath (new version): It can now match the full path or a partial path, regardless of the number of username/organization/group levels. Since the full path of the first line doesn’t match the request, it continues to the second line, which does match. It returns TOKEN2.
Notes:
The third line provides global credentials for other projects under /group/subgroup2/.
The fourth line provides global credentials for other projects under /group/.
Important:
The order of lines in the credentials file matters. More specific paths should be listed before broader ones.
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
|
Claude Sonnet 4.5: I'll review this PR by first examining the original code and then the patch changes.Now let me review this PR according to Git's official documentation on credential storage. PR Review: git-credential-readonly Pull Request #4This PR contains two commits that make changes to the credential matching logic. Let me analyze each according to Git's credential storage documentation. Commit 1: Ignore comments in credentialsChanges: Adds support for comment lines (starting with Analysis: Verdict: ❌ This violates the Git credential storage format specification. While the feature might be convenient, it makes the credential file incompatible with the standard Recommendation: If you want to add this feature, document clearly that files with comments will not work with standard Commit 2: Improved path matchingChanges: Simplifies path matching from checking only the first-level path component to using Analysis: The original code had complex logic to extract and match only the first path component (username/org). The new code uses prefix matching, which means:
According to Git's documentation, when using Issues identified:
Verdict: Recommendations:
Overall RecommendationDo not merge as-is. Both commits introduce behavior that deviates from Git's standard credential storage format and matching logic in ways that could cause compatibility issues or security concerns. Consider:
|
User description
The old version only supported host verification. When combined with useHttpPath, it could only check a single-level path for usernames, organizations, or groups, not the full path.
If the first line matched the host or the first-level path, those credentials were returned, even if a later line specified a more precise path.
Example:
https://USERNAME:TOKEN1@gitlab.com/group/subgroup1/project.git
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
https://USERNAME:TOKEN3@gitlab.com/group/subgroup2/
https://USERNAME:TOKEN4@gitlab.com/group/
For the repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Now, The system checks if the path configured in the credentials is the beginning of the requested path.
For the same repository:
https://USERNAME:TOKEN2@gitlab.com/group/subgroup2/project2.git
Notes:
The third line provides global credentials for other projects under /group/subgroup2/.
The fourth line provides global credentials for other projects under /group/.
Important:
The order of lines in the credentials file matters. More specific paths should be listed before broader ones.
I hope this doesn’t alter the originally intended behavior.
If the pull request is accepted, I think we’ll need to update the end of the documentation.
PR Type
Enhancement, Bug fix
Description
Improved path matching to support full paths instead of single-level
Now checks if configured path is prefix of requested path
Added support for ignoring comments in credentials file
Simplified path matching logic with
strings.HasPrefixDiagram Walkthrough
File Walkthrough
main.go
Simplify path matching and add comment filteringmain.go
strings.HasPrefixfor fullpath comparison
strings.Cutand separatehandling branches
#or//incredentials file