@devries-cameron20 / t3code-1 / commits / e72a0c772c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): Linux .deb no longer installs files any local user can overwrite (#28351)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 3, 2026 at 07:12 UTC e72a0c772c59f6cf04f627bf7cd73a8d5ef6e1e2
4 files changed +75 -1
knip.jsonc
+2 -1
@@ -20,7 +20,7 @@
20 // Knip loads its preprocessor through a CLI option; native verification and
21 // worktree setup (from t3.json) run directly. release-desktop.yml bundles the
22 // Windows verify script with esbuild through a path knip does not trace,
23 - // electron-builder loads the macOS signer by path, and mobile-e2e.ts runs
23 + // electron-builder loads the macOS signer and the Linux afterPack hook by path, and mobile-e2e.ts runs
24 // agent-device's CLI by path, and mobile-behavior.ts spawns its runner by path.
25 // release-desktop.yml runs the desktop launch check through xvfb-run, which knip
26 // does not trace.
@@ -28,6 +28,7 @@
28 // These fixture scripts are injected into a browser page by path.
29 "fixtures/*/*.js",
30 "knip-schemas.ts",
31 + "linux-after-pack.ts",
32 "mobile-behavior/run.ts",
33 "mobile-native-client.ts",
34 "setup-worktree.ts",
scripts/build-desktop-artifact.ts
+1
@@ -2890,6 +2890,7 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
2890 buildConfig.toolsets = { appimage: "1.0.3" };
2891 const path = yield* Path.Path;
2892 const repoRoot = yield* RepoRoot;
2893 + buildConfig.afterPack = path.join(repoRoot, "scripts/linux-after-pack.ts");
2894 buildConfig.linux = {
2895 target: target === "AppImage" ? [target, "deb"] : [target],
2896 executableName: "t3code",
scripts/linux-after-pack.test.ts new
+43
@@ -0,0 +1,43 @@
1 +// @effect-diagnostics nodeBuiltinImport:off - Applies real file modes in a temporary app folder.
2 +import * as HostProcess from "@t3tools/shared/HostProcess";
3 +import * as NodeFSP from "node:fs/promises";
4 +import * as NodeOS from "node:os";
5 +import * as NodePath from "node:path";
6 +import { describe, expect, it } from "vite-plus/test";
7 +
8 +import { removeSharedWriteAccess } from "./linux-after-pack.ts";
9 +
10 +describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("removeSharedWriteAccess", () => {
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-"));
13 + try {
14 + const appOutDir = NodePath.join(root, "app");
15 + const modes = {
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],
21 + } as const;
22 + await NodeFSP.mkdir(NodePath.join(appOutDir, "resources"), { recursive: true });
23 + await NodeFSP.mkdir(NodePath.join(root, "outside"));
24 + for (const [file, [before]] of Object.entries(modes)) {
25 + await NodeFSP.writeFile(NodePath.join(root, file), "");
26 + await NodeFSP.chmod(NodePath.join(root, file), before);
27 + }
28 + await NodeFSP.chmod(NodePath.join(appOutDir, "resources"), 0o777);
29 + await NodeFSP.symlink("../outside", NodePath.join(appOutDir, "linked-dir"));
30 +
31 + await removeSharedWriteAccess(appOutDir);
32 +
33 + for (const [file, [, after]] of Object.entries(modes)) {
34 + const { mode } = await NodeFSP.stat(NodePath.join(root, file));
35 + expect([file, mode & 0o7777]).toEqual([file, after]);
36 + }
37 + const { mode: resourcesMode } = await NodeFSP.stat(NodePath.join(appOutDir, "resources"));
38 + expect(resourcesMode & 0o7777).toBe(0o755);
39 + } finally {
40 + await NodeFSP.rm(root, { recursive: true, force: true });
41 + }
42 + });
43 +});
scripts/linux-after-pack.ts new
+29
@@ -0,0 +1,29 @@
1 +// @effect-diagnostics nodeBuiltinImport:off
2 +import * as NodeFSP from "node:fs/promises";
3 +import * as NodeModule from "node:module";
4 +import * as NodePath from "node:path";
5 +
6 +const prepareServerCompileCache: (context: AfterPackContext) => Promise<void> =
7 + NodeModule.createRequire(import.meta.url)("./prepare-server-compile-cache.cjs");
8 +
9 +interface AfterPackContext {
10 + readonly appOutDir: string;
11 +}
12 +
13 +// Electron's Linux zips can ship world-writable files (44.10.0 has 0777 binaries), and
14 +// electron-builder copies zip modes verbatim into the .deb and AppImage.
15 +export default async function afterPack(context: AfterPackContext): Promise<void> {
16 + await prepareServerCompileCache(context);
17 + await removeSharedWriteAccess(context.appOutDir);
18 +}
19 +
20 +// Walks by hand: recursive readdir follows directory symlinks out of the app folder.
21 +export async function removeSharedWriteAccess(path: string): Promise<void> {
22 + const stats = await NodeFSP.lstat(path);
23 + if (stats.isSymbolicLink()) return;
24 + if (stats.mode & 0o022) await NodeFSP.chmod(path, stats.mode & 0o7755);
25 + if (!stats.isDirectory()) return;
26 + for (const entry of await NodeFSP.readdir(path)) {
27 + await removeSharedWriteAccess(NodePath.join(path, entry));
28 + }
29 +}