Skip to content

Commit c8ba8fd

Browse files
committed
fix(desktop): the AppImage mount scrub classifies segments by their normalized path
A segment such as /tmp/.mount_cur/../.mount_old/usr/bin resolves into a stale mount, so compare the normalized path while keeping the segment verbatim in the output.
1 parent 2d4eec3 commit c8ba8fd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎apps/desktop/src/shell/appImageStaleMounts.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ describe("stripStaleAppImageMounts", () => {
4141
expect(result).not.toHaveProperty("LD_LIBRARY_PATH");
4242
});
4343

44+
it("classifies segments by their normalized path but keeps them verbatim", () => {
45+
const result = stripStaleAppImageMounts({
46+
APPDIR: CURRENT,
47+
PATH: `${CURRENT}/../.mount_old/usr/bin:${CURRENT}/usr/bin:${CURRENT}/usr/../bin`,
48+
});
49+
50+
expect(result.PATH).toBe(`${CURRENT}/usr/bin:${CURRENT}/usr/../bin`);
51+
});
52+
4453
it("matches mounts under a non-default TMPDIR", () => {
4554
const result = stripStaleAppImageMounts({
4655
APPDIR: "/var/tmp/.mount_cur",

‎apps/desktop/src/shell/appImageStaleMounts.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// @effect-diagnostics-next-line nodeBuiltinImport:off - Pure string normalization of env paths, no filesystem access.
2+
import * as NodePath from "node:path";
3+
14
// Search-path variables the AppImage runtime prepends its mount dir to.
25
const APPIMAGE_SEARCH_PATH_ENV_KEYS = ["PATH", "LD_LIBRARY_PATH", "XDG_DATA_DIRS"] as const;
36

@@ -13,14 +16,16 @@ const APPIMAGE_MOUNT_ROOT = /^(.*?\/\.mount_[^/]+)(?:\/|$)/;
1316
* Segments under the current APPDIR stay, as do all non-mount segments,
1417
* including empty ones (the loader and PATH lookup read them as the current
1518
* dir). A variable is deleted only when every segment was a stale mount.
19+
* Segments are classified by their normalized path, so `..` cannot hop from
20+
* the current mount into a stale one, but are kept verbatim.
1621
* Non-AppImage envs are returned as is.
1722
*
1823
* Can fold into the shared `appImageRuntimeEnv` helper once #16679 lands.
1924
*/
2025
export function stripStaleAppImageMounts(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
2126
if (env.APPIMAGE === undefined && env.APPDIR === undefined) return env;
2227

23-
const appDir = env.APPDIR?.replace(/\/+$/, "");
28+
const appDir = env.APPDIR && NodePath.posix.normalize(env.APPDIR).replace(/\/+$/, "");
2429
const scrubbed: NodeJS.ProcessEnv = { ...env };
2530
for (const key of APPIMAGE_SEARCH_PATH_ENV_KEYS) {
2631
const value = env[key];
@@ -30,7 +35,7 @@ export function stripStaleAppImageMounts(env: NodeJS.ProcessEnv): NodeJS.Process
3035
const separator = key === "LD_LIBRARY_PATH" ? /[:;]/ : ":";
3136
const segments = value.split(separator);
3237
const kept = segments.filter((segment) => {
33-
const mountRoot = APPIMAGE_MOUNT_ROOT.exec(segment)?.[1];
38+
const mountRoot = APPIMAGE_MOUNT_ROOT.exec(NodePath.posix.normalize(segment))?.[1];
3439
return mountRoot === undefined || mountRoot === appDir;
3540
});
3641
if (kept.length === segments.length) continue;

0 commit comments

Comments
 (0)