Potential fix for code scanning alert no. 1: Incomplete regular expression for hostnames#116
Merged
Conversation
…ssion for hostnames Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR tightens GitHub remote parsing in the local git-repo detection path by making the hostname match literal, which is intended to prevent non-GitHub hosts from being accepted as github.com remotes.
Changes:
- Escapes the dot in the
parseGithubRemotehostname regex so it matches onlygithub.com. - Keeps the existing HTTPS and SCP-style SSH remote parsing flow unchanged otherwise.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // git@github.com:mroth/bump.git | ||
| func parseGithubRemote(remoteURL string) (owner, repo string, ok bool) { | ||
| re := regexp.MustCompile(`^(?:https://|git@)github.com[:/](.*)/(.*?)(?:\.git$|$)`) | ||
| re := regexp.MustCompile(`^(?:https://|git@)github\.com[:/](.*)/(.*?)(?:\.git$|$)`) |
Contributor
There was a problem hiding this comment.
Added two negative test cases in commit 5708a67:
nearMiss_HTTPS_dotReplaced:https://githubXcom/mroth/bump.git→wantOk: falsenearMiss_SSH_dotReplaced:git@githubXcom:mroth/bump.git→wantOk: false
These would have matched before the dot was escaped and will now fail CI if the literal \. is ever reverted.
Agent-Logs-Url: https://github.com/mroth/bump/sessions/5418106b-c2a5-4f1c-a03c-69d7394d03ee Co-authored-by: mroth <40650+mroth@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Potential fix for https://github.com/mroth/bump/security/code-scanning/1
The best fix is to make the hostname literal in the regex by escaping the dot in
github.com.In
git.go, inparseGithubRemote(line 80 in the provided snippet), replace:github.comwithgithub\.comThis keeps existing behavior (matching HTTPS and SSH GitHub remotes and extracting owner/repo) while removing unintended host matches. No new methods, imports, or dependencies are required.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.