|
| 1 | +From f30373d5ac9c1af048f352ce32eaddc7c83a9156 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Sreenivasulu Malavathula < [email protected]> |
| 3 | +Date: Mon, 16 Jun 2025 16:28:52 -0500 |
| 4 | +Subject: [PATCH] Address CVE-2025-48938 |
| 5 | +Upstream Patch Reference: https://github.com/cli/go-gh/commit/a08820a.diff |
| 6 | + |
| 7 | +--- |
| 8 | + .../cli/go-gh/v2/pkg/browser/browser.go | 59 +++++++++++++++++++ |
| 9 | + 1 file changed, 59 insertions(+) |
| 10 | + |
| 11 | +diff --git a/vendor/github.com/cli/go-gh/v2/pkg/browser/browser.go b/vendor/github.com/cli/go-gh/v2/pkg/browser/browser.go |
| 12 | +index 4d56710..d17951a 100644 |
| 13 | +--- a/vendor/github.com/cli/go-gh/v2/pkg/browser/browser.go |
| 14 | ++++ b/vendor/github.com/cli/go-gh/v2/pkg/browser/browser.go |
| 15 | +@@ -2,7 +2,9 @@ |
| 16 | + package browser |
| 17 | + |
| 18 | + import ( |
| 19 | ++ "fmt" |
| 20 | + "io" |
| 21 | ++ "net/url" |
| 22 | + "os" |
| 23 | + "os/exec" |
| 24 | + |
| 25 | +@@ -45,9 +47,20 @@ func (b *Browser) Browse(url string) error { |
| 26 | + } |
| 27 | + |
| 28 | + func (b *Browser) browse(url string, env []string) error { |
| 29 | ++ // Ensure the URL is supported including the scheme, |
| 30 | ++ // overwrite `url` for use within the function. |
| 31 | ++ urlParsed, err := isPossibleProtocol(url) |
| 32 | ++ if err != nil { |
| 33 | ++ return err |
| 34 | ++ } |
| 35 | ++ |
| 36 | ++ url = urlParsed.String() |
| 37 | ++ |
| 38 | ++ // Use default `gh` browsing module for opening URL if not customized. |
| 39 | + if b.launcher == "" { |
| 40 | + return cliBrowser.OpenURL(url) |
| 41 | + } |
| 42 | ++ |
| 43 | + launcherArgs, err := shlex.Split(b.launcher) |
| 44 | + if err != nil { |
| 45 | + return err |
| 46 | +@@ -78,3 +91,49 @@ func resolveLauncher() string { |
| 47 | + } |
| 48 | + return os.Getenv("BROWSER") |
| 49 | + } |
| 50 | ++ |
| 51 | ++func isSupportedScheme(scheme string) bool { |
| 52 | ++ switch scheme { |
| 53 | ++ case "http", "https", "vscode", "vscode-insiders": |
| 54 | ++ return true |
| 55 | ++ default: |
| 56 | ++ return false |
| 57 | ++ } |
| 58 | ++} |
| 59 | ++ |
| 60 | ++func isPossibleProtocol(u string) (*url.URL, error) { |
| 61 | ++ // Parse URL for known supported schemes before handling unknown cases. |
| 62 | ++ urlParsed, err := url.Parse(u) |
| 63 | ++ if err != nil { |
| 64 | ++ return nil, fmt.Errorf("opening unparsable URL is unsupported: %s", u) |
| 65 | ++ } |
| 66 | ++ |
| 67 | ++ if isSupportedScheme(urlParsed.Scheme) { |
| 68 | ++ return urlParsed, nil |
| 69 | ++ } |
| 70 | ++ |
| 71 | ++ // Disallow any unrecognized URL schemes if explicitly present. |
| 72 | ++ if urlParsed.Scheme != "" { |
| 73 | ++ return nil, fmt.Errorf("opening unsupport URL scheme: %s", u) |
| 74 | ++ } |
| 75 | ++ |
| 76 | ++ // Disallow URLs that match existing files or directories on the filesystem |
| 77 | ++ // as these could be executables or executed by the launcher browser due to |
| 78 | ++ // the file extension and/or associated application. |
| 79 | ++ // |
| 80 | ++ // Symlinks should not be resolved in order to avoid broken links or other |
| 81 | ++ // vulnerabilities trying to resolve them. |
| 82 | ++ if fileInfo, _ := os.Lstat(u); fileInfo != nil { |
| 83 | ++ return nil, fmt.Errorf("opening files or directories is unsupported: %s", u) |
| 84 | ++ } |
| 85 | ++ |
| 86 | ++ // Disallow URLs that match executables found in the user path. |
| 87 | ++ exec, _ := safeexec.LookPath(u) |
| 88 | ++ if exec != "" { |
| 89 | ++ return nil, fmt.Errorf("opening executables is unsupported: %s", u) |
| 90 | ++ } |
| 91 | ++ |
| 92 | ++ // Otherwise, assume HTTP URL using `https` to ensure secure browsing. |
| 93 | ++ urlParsed.Scheme = "https" |
| 94 | ++ return urlParsed, nil |
| 95 | ++} |
| 96 | +-- |
| 97 | +2.45.2 |
| 98 | + |
0 commit comments