Skip to content

Commit 24ab522

Browse files
committed
fix(server): require file access for HTML tool previews
1 parent 5708996 commit 24ab522

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DEFAULT_SERVER_SETTINGS,
88
ProviderInstanceId,
99
ThreadId,
10+
TurnItemId,
1011
AuthOrchestrationOperateScope,
1112
ORCHESTRATION_V2_WS_METHODS,
1213
AuthOrchestrationReadScope,
@@ -472,6 +473,12 @@ it.effect("separates host file URLs from readable attachment URLs", () =>
472473
{ _tag: "workspace-file", threadId: ThreadId.make("thread"), path: "file.txt" },
473474
{ _tag: "media-file", threadId: ThreadId.make("thread"), path: "/repo/image.png" },
474475
{ _tag: "draft-workspace-file", cwd: "/repo", path: "file.txt" },
476+
{
477+
_tag: "tool-input-html",
478+
threadId: ThreadId.make("thread"),
479+
itemId: TurnItemId.make("html"),
480+
revision: "completed",
481+
},
475482
] as const) {
476483
expect(
477484
yield* client[WS_METHODS.assetsCreateUrl]({ resource }).pipe(Effect.flip),
@@ -484,6 +491,54 @@ it.effect("separates host file URLs from readable attachment URLs", () =>
484491
}).pipe(Effect.scoped),
485492
);
486493

494+
it.effect("requires both thread and host-file access for HTML tool previews", () =>
495+
Effect.gen(function* () {
496+
const group = WsRpcGroup.omit(
497+
...[...WsRpcGroup.requests.keys()].filter(
498+
(
499+
tag,
500+
): tag is Exclude<keyof typeof RPC_REQUIRED_SCOPES, typeof WS_METHODS.assetsCreateUrl> =>
501+
tag !== WS_METHODS.assetsCreateUrl,
502+
),
503+
);
504+
const resource = {
505+
_tag: "tool-input-html" as const,
506+
threadId: ThreadId.make("thread"),
507+
itemId: TurnItemId.make("html"),
508+
revision: "completed",
509+
};
510+
let handled = 0;
511+
for (const scopes of [
512+
[AuthFilesystemReadScope],
513+
[AuthOrchestrationReadScope, AuthFilesystemReadScope],
514+
]) {
515+
const client = yield* RpcTest.makeClient(group).pipe(
516+
Effect.provide(
517+
Layer.mergeAll(
518+
group.toLayerHandler(WS_METHODS.assetsCreateUrl, () =>
519+
Effect.sync(() => {
520+
handled++;
521+
return { relativeUrl: "/api/assets/html", expiresAt: 1 };
522+
}),
523+
),
524+
RpcAuthorization.layer(scopes),
525+
),
526+
),
527+
);
528+
if (scopes.length === 1) {
529+
expect(
530+
yield* client[WS_METHODS.assetsCreateUrl]({ resource }).pipe(Effect.flip),
531+
).toMatchObject({ requiredPermission: AuthOrchestrationReadScope });
532+
} else {
533+
expect(yield* client[WS_METHODS.assetsCreateUrl]({ resource })).toMatchObject({
534+
relativeUrl: "/api/assets/html",
535+
});
536+
}
537+
}
538+
expect(handled).toBe(1);
539+
}).pipe(Effect.scoped),
540+
);
541+
487542
it.effect("denies manual cleanup before the handler without settings permission", () =>
488543
Effect.gen(function* () {
489544
const group = WsRpcGroup.omit(

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ const requiredScopesForRpcCall = (
253253
}
254254
if (method === WS_METHODS.assetsCreateUrl) {
255255
const { resource } = Schema.decodeUnknownSync(AssetCreateUrlInput)(payload);
256+
if (resource._tag === "tool-input-html") {
257+
return [AuthOrchestrationReadScope, AuthFilesystemReadScope];
258+
}
256259
return [
257260
resource._tag === "workspace-file" ||
258261
resource._tag === "media-file" ||

0 commit comments

Comments
 (0)