forked from loft-sh/devpod
-
Notifications
You must be signed in to change notification settings - Fork 27
fix: sanitize AppImage environment before opening URLs #710
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package open | ||
|
|
||
| import ( | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| ) | ||
|
|
||
| // isAppImage reports whether the current process is running inside an AppImage. | ||
| func isAppImage() bool { | ||
| return os.Getenv("APPIMAGE") != "" | ||
| } | ||
|
|
||
| // openURLSanitized opens a URL using xdg-open with a sanitized environment | ||
| // to work around AppImage library conflicts. | ||
| // | ||
| // When running inside an AppImage, the AppRun script prepends the image's | ||
| // bundled library paths to LD_LIBRARY_PATH. Child processes like xdg-open | ||
| // and gio then load these bundled libraries instead of the system ones, | ||
| // causing symbol lookup errors (e.g. "undefined symbol: g_unix_mount_entry_get_options"). | ||
| // | ||
| // This is a well-known AppImage limitation: | ||
| // - https://github.com/AppImage/AppImageKit/issues/396 | ||
| // - https://github.com/AppImage/AppImageKit/issues/616 | ||
| // | ||
| // Tauri's AppImage builds also bundle their own xdg-open wrapper | ||
| // (APPIMAGE_BUNDLE_XDG_OPEN=1), which compounds the issue: | ||
| // - https://github.com/tauri-apps/tauri/issues/10617 | ||
| // - https://github.com/tauri-apps/plugins-workspace/pull/2103 | ||
| // | ||
| // The fix is to strip AppImage-injected environment variables before spawning | ||
| // xdg-open, and to use the system xdg-open by absolute path to bypass any | ||
| // bundled wrapper. | ||
| func openURLSanitized(url string) error { | ||
| // Use the system xdg-open to avoid Tauri's bundled wrapper. | ||
| xdgOpen := "/usr/bin/xdg-open" | ||
| if _, err := os.Stat(xdgOpen); err != nil { | ||
| xdgOpen = "xdg-open" | ||
| } | ||
|
|
||
| //nolint:gosec // xdgOpen is either "/usr/bin/xdg-open" or "xdg-open" | ||
| cmd := exec.Command(xdgOpen, url) | ||
| cmd.Env = sanitizedEnv() | ||
| return cmd.Run() | ||
| } | ||
|
|
||
| // sanitizedEnv returns a copy of the current environment with AppImage-injected | ||
| // variables removed or restored to their pre-AppImage values. | ||
| func sanitizedEnv() []string { | ||
| // Variables injected by AppImage's AppRun that cause library conflicts | ||
| // when inherited by system binaries. | ||
| strip := map[string]bool{ | ||
| "APPDIR": true, | ||
| "APPIMAGE": true, | ||
| "ARGV0": true, | ||
| "OWD": true, | ||
| "APPIMAGE_BUNDLE_XDG_OPEN": true, | ||
| } | ||
|
|
||
| var env []string | ||
| for _, kv := range os.Environ() { | ||
| key, _, _ := strings.Cut(kv, "=") | ||
| if strip[key] { | ||
| continue | ||
| } | ||
| env = append(env, kv) | ||
| } | ||
|
|
||
| // Restore LD_LIBRARY_PATH to its pre-AppImage value if saved, | ||
| // otherwise remove it entirely so system binaries use system libs. | ||
| env = removeEnvKey(env, "LD_LIBRARY_PATH") | ||
| if orig := os.Getenv("ORIG_LD_LIBRARY_PATH"); orig != "" { | ||
| env = append(env, "LD_LIBRARY_PATH="+orig) | ||
| } | ||
|
|
||
| // LD_PRELOAD may be set to an exec interception library (exec.so); | ||
| // remove it so system binaries aren't affected. | ||
| env = removeEnvKey(env, "LD_PRELOAD") | ||
|
|
||
| return env | ||
| } | ||
|
|
||
| func removeEnvKey(env []string, key string) []string { | ||
| prefix := key + "=" | ||
| result := env[:0:0] | ||
| for _, kv := range env { | ||
| if !strings.HasPrefix(kv, prefix) { | ||
| result = append(result, kv) | ||
| } | ||
| } | ||
| return result | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //go:build !linux | ||
|
|
||
| package open | ||
|
|
||
| import "errors" | ||
|
|
||
| func isAppImage() bool { | ||
| return false | ||
| } | ||
|
|
||
| func openURLSanitized(_ string) error { | ||
| return errors.New("openURLSanitized is only available on Linux") | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.