Skip to content

Commit e3e8b78

Browse files
committed
fix(server): require file access for app path icons
1 parent 6d41901 commit e3e8b78

5 files changed

Lines changed: 42 additions & 32 deletions

File tree

‎apps/server/src/auth/RpcAuthorization.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,14 @@ it.effect("separates host file URLs from readable attachment URLs", () =>
412412
yield* client[WS_METHODS.assetsCreateUrl]({
413413
resource: { _tag: "attachment", attachmentId: "image" },
414414
});
415+
yield* client[WS_METHODS.assetsCreateUrl]({
416+
resource: { _tag: "native-app-icon", app: { _tag: "app-id", appId: "com.apple.calculator" } },
417+
});
415418
for (const resource of [
416419
{ _tag: "workspace-file", threadId: ThreadId.make("thread"), path: "file.txt" },
417420
{ _tag: "media-file", threadId: ThreadId.make("thread"), path: "/repo/image.png" },
418421
{ _tag: "draft-workspace-file", cwd: "/repo", path: "file.txt" },
422+
{ _tag: "native-app-icon", app: { _tag: "app-path", path: "/private/Secret.app" } },
419423
] as const) {
420424
expect(
421425
yield* client[WS_METHODS.assetsCreateUrl]({ resource }).pipe(Effect.flip),
@@ -424,7 +428,7 @@ it.effect("separates host file URLs from readable attachment URLs", () =>
424428
requiredPermission: AuthFilesystemReadScope,
425429
});
426430
}
427-
expect(handled).toBe(1);
431+
expect(handled).toBe(2);
428432
}).pipe(Effect.scoped),
429433
);
430434

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ const requiredScopesForRpcCall = (
265265
return [
266266
resource._tag === "workspace-file" ||
267267
resource._tag === "media-file" ||
268-
resource._tag === "draft-workspace-file"
268+
resource._tag === "draft-workspace-file" ||
269+
(resource._tag === "native-app-icon" && resource.app._tag === "app-path")
269270
? AuthFilesystemReadScope
270271
: AuthOrchestrationReadScope,
271272
];

‎apps/server/src/process/externalLauncher.test.ts‎

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,37 @@ const layerTest = (input: {
9595
);
9696
};
9797

98-
it.effect("opens home-relative app bundles using the server home directory", () =>
99-
Effect.gen(function* () {
100-
const fs = yield* FileSystem.FileSystem;
101-
const path = yield* Path.Path;
102-
const bin = yield* fs.makeTempDirectoryScoped({ prefix: "t3-app-open-" });
103-
yield* fs.writeFileString(path.join(bin, "open"), "#!/bin/sh\n");
104-
yield* fs.chmod(path.join(bin, "open"), 0o755);
105-
const spawned: ChildProcess.StandardCommand[] = [];
106-
yield* Effect.gen(function* () {
107-
const launcher = yield* ExternalLauncher.ExternalLauncher;
108-
for (const cwd of ["~/Applications/My App.app", "/Applications/My App.app"]) {
109-
yield* launcher.launchEditor({ editor: "file-manager", cwd });
110-
}
111-
}).pipe(
112-
Effect.provide(
113-
layerTest({
114-
platform: "darwin",
115-
env: { PATH: bin },
116-
onSpawn: (command) => spawned.push(command),
117-
}),
118-
),
119-
Effect.provideService(HostProcess.HomeDirectory, "/Users/server"),
120-
);
121-
assert.deepEqual(
122-
spawned.map((command) => command.args),
123-
[["/Users/server/Applications/My App.app"], ["/Applications/My App.app"]],
124-
);
125-
}).pipe(Effect.provide(NodeServices.layer)),
98+
// macOS command lookup cannot search a Windows drive-letter PATH.
99+
it.effect.skipIf(windowsHost)(
100+
"opens home-relative app bundles using the server home directory",
101+
() =>
102+
Effect.gen(function* () {
103+
const fs = yield* FileSystem.FileSystem;
104+
const path = yield* Path.Path;
105+
const bin = yield* fs.makeTempDirectoryScoped({ prefix: "t3-app-open-" });
106+
yield* fs.writeFileString(path.join(bin, "open"), "#!/bin/sh\n");
107+
yield* fs.chmod(path.join(bin, "open"), 0o755);
108+
const spawned: ChildProcess.StandardCommand[] = [];
109+
yield* Effect.gen(function* () {
110+
const launcher = yield* ExternalLauncher.ExternalLauncher;
111+
for (const cwd of ["~/Applications/My App.app", "/Applications/My App.app"]) {
112+
yield* launcher.launchEditor({ editor: "file-manager", cwd });
113+
}
114+
}).pipe(
115+
Effect.provide(
116+
layerTest({
117+
platform: "darwin",
118+
env: { PATH: bin },
119+
onSpawn: (command) => spawned.push(command),
120+
}),
121+
),
122+
Effect.provideService(HostProcess.HomeDirectory, "/Users/server"),
123+
);
124+
assert.deepEqual(
125+
spawned.map((command) => command.args),
126+
[["/Users/server/Applications/My App.app"], ["/Applications/My App.app"]],
127+
);
128+
}).pipe(Effect.provide(NodeServices.layer)),
126129
);
127130

128131
it.effect.skipIf(windowsHost)(

‎apps/web/src/assets/assetUrls.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function isFileResource(resource: AssetResource): boolean {
106106
return (
107107
resource._tag === "workspace-file" ||
108108
resource._tag === "media-file" ||
109-
resource._tag === "draft-workspace-file"
109+
resource._tag === "draft-workspace-file" ||
110+
(resource._tag === "native-app-icon" && resource.app._tag === "app-path")
110111
);
111112
}

‎packages/client-runtime/src/state/assets.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export function blockedAssetUrlState(
101101
fileAccess.canReadFiles ||
102102
(resource._tag !== "workspace-file" &&
103103
resource._tag !== "media-file" &&
104-
resource._tag !== "draft-workspace-file")
104+
resource._tag !== "draft-workspace-file" &&
105+
!(resource._tag === "native-app-icon" && resource.app._tag === "app-path"))
105106
) {
106107
return null;
107108
}

0 commit comments

Comments
 (0)