Skip to content

Commit 6fbd6db

Browse files
committed
feat(core): validate AppImage execution when env vars are set [TRI-041] (#17)
1 parent 8259cd6 commit 6fbd6db

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.changes/validate-appimage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Validate the `std::env::current_exe` return value if `APPDIR` or `APPIMAGE` environment variables are set.

core/tauri-utils/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl PackageInfo {
3939

4040
/// Information about environment variables.
4141
#[derive(Debug, Clone)]
42+
#[non_exhaustive]
4243
pub struct Env {
4344
/// The APPIMAGE environment variable.
4445
#[cfg(target_os = "linux")]
@@ -51,12 +52,24 @@ pub struct Env {
5152
#[allow(clippy::derivable_impls)]
5253
impl Default for Env {
5354
fn default() -> Self {
54-
Self {
55+
let env = Self {
5556
#[cfg(target_os = "linux")]
5657
appimage: std::env::var_os("APPIMAGE"),
5758
#[cfg(target_os = "linux")]
5859
appdir: std::env::var_os("APPDIR"),
60+
};
61+
if env.appimage.is_some() || env.appdir.is_some() {
62+
// validate that we're actually running on an AppImage
63+
// an AppImage is mounted to `/tmp/.mount_${appPrefix}${hash}`
64+
// see https://github.com/AppImage/AppImageKit/blob/1681fd84dbe09c7d9b22e13cdb16ea601aa0ec47/src/runtime.c#L501
65+
if !std::env::current_exe()
66+
.map(|p| p.to_string_lossy().into_owned().starts_with("/tmp/.mount_"))
67+
.unwrap_or(true)
68+
{
69+
panic!("`APPDIR` or `APPIMAGE` environment variable found but this application was not detected as an AppImage; this might be a security issue.");
70+
}
5971
}
72+
env
6073
}
6174
}
6275

0 commit comments

Comments
 (0)