Repository navigation
Closed
Labels
bugSomething isn't workinggh-authrelating to the gh auth commandhelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic
Description
Description
When attempting to authenticate to a GitHub Enterprise Server using the gh auth login command, providing an invalid or malformed hostname causes the CLI to panic due to an unhandled error in the URL parsing process. This behavior is observed when an extra space or invalid characters are present in the hostname.
Steps to Reproduce
- Run the gh auth login command.
- Select "GitHub Enterprise Server" as the account type.
- Provide a malformed hostname, e.g., mouismail-0ff7c314037fe1e88.ghe-test.org .
- Proceed with the login steps.
Expected Behavior
The CLI should handle the invalid hostname gracefully by either:
- Trimming the input to remove any extraneous spaces.
- Providing a clear error message indicating the invalid hostname.
Actual Behavior:
The CLI panics with the following error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x101a04e10]
goroutine 1 [running]:
github.com/cli/oauth.GitHubHost({0x14000b12500?, 0x29?})
github.com/cli/oauth@v1.0.1/oauth.go:32 +0x30
github.com/cli/cli/v2/internal/authflow.AuthFlow({0x14000666450, 0x29}, 0x1400044ba20, {0x0, 0x0}, {0x14000b5c4e0, 0x1, 0x100d9901c?}, 0x1, {0x103221860, ...})
github.com/cli/cli/v2/internal/authflow/flow.go:52 +0x2bc
...Proposed Solution:
- Trim Input:
Ensure that any hostname input is trimmed of leading and trailing whitespace before processing. - Handle Parsing Errors:
Modify theGitHubHostfunction to return an error if the URL parsing fails and handle this error appropriately. - Deprecate Faulty Functions:
Introduce a new function (e.g.,NewHostorParseGitHubHost) that adheres to idiomatic Go error handling, and mark the oldGitHubHostfunction as deprecated.
Relevant Code Snippets:
- Current implementation in
oauth.go:func GitHubHost(hostURL string) *Host { u, _ := url.Parse(hostURL) return &Host{ DeviceCodeURL: fmt.Sprintf("%s://%s/login/device/code", u.Scheme, u.Host), AuthorizeURL: fmt.Sprintf("%s://%s/login/oauth/authorize", u.Scheme, u.Host), } }
Proposed implementation
func NewHost(hostURL string) (*Host, error) {
u, err := url.Parse(strings.TrimSpace(hostURL))
if err != nil {
return nil, err
}
return &Host{
DeviceCodeURL: fmt.Sprintf("%s://%s/login/device/code", u.Scheme, u.Host),
AuthorizeURL: fmt.Sprintf("%s://%s/login/oauth/authorize", u.Scheme, u.Host),
}, nil
}Environment
- GitHub CLI version: 2.50.0 (2024-05-29)
- OS: MacOS
Resources
Metadata
Metadata
Labels
bugSomething isn't workinggh-authrelating to the gh auth commandhelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic
Activity
williammartin commentedon Jun 24, 2024
I've moved this from
cli/oauthto make it more discoverable for maintainers and users in the future.I have created cli/oauth#62 for the adjustments in
cli/oauth.williammartin commentedon Jun 24, 2024
I have labelled this
help wantedbut I know that @mouismail is working on it.mouismail commentedon Jun 24, 2024
@williammartin I am working on it yes.
mouismail commentedon Jun 25, 2024
The PR: cli/oauth#63
BagToad commentedon Oct 7, 2024
👋 @mouismail, a polite bump on our review comments on the PR. We have this on our board and are looking to help get it across the finish line 😁 ❤
mouismail commentedon Oct 7, 2024
👋🏼 @BagToad I will give it a look this week, sorry for the delay 🤒
mouismail commentedon Oct 7, 2024
done.