Skip to content

Commit 5210d93

Browse files
PR Batch Testerclaude
andcommitted
fix(desktop): afterPack never follows symlinks out of the app folder
Recursive readdir descends into directory symlinks, so a linked folder would have had its outside files chmodded. Walk the tree by hand and skip links. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent eccb332 commit 5210d93

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

‎scripts/linux-after-pack.test.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,36 @@ import { describe, expect, it } from "vite-plus/test";
88
import afterPack from "./linux-after-pack.ts";
99

1010
describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("linux afterPack", () => {
11-
it("removes group and other write access from the packed app", async () => {
12-
const appOutDir = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-after-pack-"));
11+
it("removes group and other write access from the packed app only", async () => {
12+
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-after-pack-"));
1313
try {
14+
const appOutDir = NodePath.join(root, "app");
1415
const modes = {
15-
t3code: [0o777, 0o755],
16-
"resources.pak": [0o666, 0o644],
17-
"chrome-sandbox": [0o4777, 0o4755],
18-
"resources/app.asar": [0o644, 0o644],
16+
"app/t3code": [0o777, 0o755],
17+
"app/resources.pak": [0o666, 0o644],
18+
"app/chrome-sandbox": [0o4777, 0o4755],
19+
"app/resources/app.asar": [0o644, 0o644],
20+
"outside/file": [0o666, 0o666],
1921
} as const;
20-
await NodeFSP.mkdir(NodePath.join(appOutDir, "resources"));
22+
await NodeFSP.mkdir(NodePath.join(appOutDir, "resources"), { recursive: true });
23+
await NodeFSP.mkdir(NodePath.join(root, "outside"));
2124
for (const [file, [before]] of Object.entries(modes)) {
22-
await NodeFSP.writeFile(NodePath.join(appOutDir, file), "");
23-
await NodeFSP.chmod(NodePath.join(appOutDir, file), before);
25+
await NodeFSP.writeFile(NodePath.join(root, file), "");
26+
await NodeFSP.chmod(NodePath.join(root, file), before);
2427
}
2528
await NodeFSP.chmod(NodePath.join(appOutDir, "resources"), 0o777);
26-
await NodeFSP.symlink("t3code", NodePath.join(appOutDir, "t3code-link"));
29+
await NodeFSP.symlink("../outside", NodePath.join(appOutDir, "linked-dir"));
2730

2831
await afterPack({ appOutDir });
2932

3033
for (const [file, [, after]] of Object.entries(modes)) {
31-
const { mode } = await NodeFSP.stat(NodePath.join(appOutDir, file));
34+
const { mode } = await NodeFSP.stat(NodePath.join(root, file));
3235
expect([file, mode & 0o7777]).toEqual([file, after]);
3336
}
3437
const { mode: resourcesMode } = await NodeFSP.stat(NodePath.join(appOutDir, "resources"));
3538
expect(resourcesMode & 0o7777).toBe(0o755);
3639
} finally {
37-
await NodeFSP.rm(appOutDir, { recursive: true, force: true });
40+
await NodeFSP.rm(root, { recursive: true, force: true });
3841
}
3942
});
4043
});

‎scripts/linux-after-pack.ts‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import * as NodePath from "node:path";
55
// Electron's Linux zips can ship world-writable files (44.10.0 has 0777 binaries), and
66
// electron-builder copies zip modes verbatim into the .deb and AppImage.
77
export default async function afterPack(context: { readonly appOutDir: string }): Promise<void> {
8-
const entries = await NodeFSP.readdir(context.appOutDir, {
9-
recursive: true,
10-
withFileTypes: true,
11-
});
12-
const paths = [
13-
context.appOutDir,
14-
...entries.map((entry) => NodePath.join(entry.parentPath, entry.name)),
15-
];
16-
for (const path of paths) {
17-
const stats = await NodeFSP.lstat(path);
18-
if (stats.isSymbolicLink() || (stats.mode & 0o022) === 0) continue;
19-
await NodeFSP.chmod(path, stats.mode & 0o7755);
8+
await removeSharedWriteAccess(context.appOutDir);
9+
}
10+
11+
// Walks by hand: recursive readdir follows directory symlinks out of the app folder.
12+
async function removeSharedWriteAccess(path: string): Promise<void> {
13+
const stats = await NodeFSP.lstat(path);
14+
if (stats.isSymbolicLink()) return;
15+
if (stats.mode & 0o022) await NodeFSP.chmod(path, stats.mode & 0o7755);
16+
if (!stats.isDirectory()) return;
17+
for (const entry of await NodeFSP.readdir(path)) {
18+
await removeSharedWriteAccess(NodePath.join(path, entry));
2019
}
2120
}

0 commit comments

Comments
 (0)