Repository navigation
fix(source-control): read SCP-style remotes on IPv6 hosts #31917
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?
Changes from all commits
a096bc7
321238b
e5d15a2
8a9c10f
9932987
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ export function repositoryPathFromRemoteUrl(url: string | null): string | null { | |
| } | ||
|
|
||
| const match = | ||
| /^(?:[^@/\s]+@[^:/\s]+:|[^@:/\\\s]{2,}:(?!:)|(?:ssh|https?|git):\/\/[^/]+\/)((?:[^/\s]+\/)+[^/\s]+?)(?:\.git)?\/?$/iu.exec( | ||
| /^(?:[^@/\s]+@(?:\[[^\]@/\s]+\]|[^:/\s[\]]+):|(?:\[[^\]@/\\\s]+\]|[^@:/\\\s[\]]{2,}):(?!:)|(?:ssh|https?|git):\/\/[^/]+\/)((?:[^/\s]+\/)+[^/\s]+?)(?:\.git)?\/?$/iu.exec( | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject nested brackets in bracketed hosts.
|
||
| trimmed, | ||
| ); | ||
| const path = match?.[1]?.trim() ?? ""; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -522,7 +522,7 @@ export function isChangeRequestInProjectRepository( | |
| ); | ||
| } | ||
|
|
||
| const SCP_REMOTE = /^[a-zA-Z0-9._-]+@([^:/]+):/; | ||
| const SCP_REMOTE = /^[a-zA-Z0-9._-]+@(\[[^\]@/\s]+\]|[^:/[\]]+):/; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject invalid bracketed hosts.
|
||
|
|
||
| /** Null when the remote names no host, such as a local path. */ | ||
| export function parseGitRemoteHost(remoteUrl: string): GitRemoteHost | null { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject invalid bracketed hosts in
userlessScpRemoteHost.[::zz]:team/project.gitmatches the new pattern, souserlessScpRemoteHostreturns[::zz].parseGitRemoteHostkeeps that host when itsnew URLnormalization fails, so it returns a remote.gitHubApiHostForRemotethen callsnew URLon that host without a guard and throws. Before this change, the same input matched no pattern and resolved to no host.Validate the bracketed host before returning it, so an invalid remote resolves to no host.
Suggested fix
export function userlessScpRemoteHost(remoteUrl: string): string | null { - return USERLESS_SCP_SSH_REMOTE_PATTERN.exec(remoteUrl.trim())?.[1] ?? null; + const host = USERLESS_SCP_SSH_REMOTE_PATTERN.exec(remoteUrl.trim())?.[1] ?? null; + if (host === null || !host.startsWith("[")) return host; + try { + new URL(`https://${host}`); + } catch { + return null; + } + return host; }