File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " tauri " : patch
3+ ---
4+
5+ Validate the ` std::env::current_exe ` return value if ` APPDIR ` or ` APPIMAGE ` environment variables are set.
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ impl PackageInfo {
3939
4040/// Information about environment variables.
4141#[ derive( Debug , Clone ) ]
42+ #[ non_exhaustive]
4243pub struct Env {
4344 /// The APPIMAGE environment variable.
4445 #[ cfg( target_os = "linux" ) ]
@@ -51,12 +52,24 @@ pub struct Env {
5152#[ allow( clippy:: derivable_impls) ]
5253impl 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
You can’t perform that action at this time.
0 commit comments