diff --git a/common/flatpak-run.c b/common/flatpak-run.c index f48f402a93..81ead1e601 100644 --- a/common/flatpak-run.c +++ b/common/flatpak-run.c @@ -1525,6 +1525,10 @@ static const ExportData default_exports[] = { {"XDG_DATA_DIRS", "/app/share:/usr/share"}, {"SHELL", "/bin/sh"}, {"TMPDIR", NULL}, /* Unset TMPDIR as it may not exist in the sandbox */ + /* We always use /run/user/UID, even if the user's XDG_RUNTIME_DIR + * outside the sandbox is somewhere else. Don't allow a different + * setting from outside the sandbox to overwrite this. */ + {"XDG_RUNTIME_DIR", NULL}, /* Some env vars are common enough and will affect the sandbox badly if set on the host. We clear these always. */ diff --git a/tests/test-run.sh b/tests/test-run.sh index 3c344df197..8852a44745 100644 --- a/tests/test-run.sh +++ b/tests/test-run.sh @@ -24,7 +24,7 @@ set -euo pipefail skip_without_bwrap skip_revokefs_without_fuse -echo "1..18" +echo "1..19" # Use stable rather than master as the branch so we can test that the run # command automatically finds the branch correctly @@ -74,6 +74,13 @@ assert_file_has_content hello_out '^Hello world, from a sandbox$' ok "hello" +mkdir xrd +XDG_RUNTIME_DIR="$(pwd)/xrd" run_sh org.test.Platform 'echo $XDG_RUNTIME_DIR' > value-in-sandbox +head value-in-sandbox >&2 +assert_file_has_content value-in-sandbox "^/run/user/$(id -u)\$" + +ok "XDG_RUNTIME_DIR not inherited" + run_sh org.test.Platform cat /.flatpak-info >runtime-fpi assert_file_has_content runtime-fpi "[Runtime]" assert_file_has_content runtime-fpi "^runtime=runtime/org\.test\.Platform/$ARCH/stable$"