Skip to content

Commit 9ec2472

Browse files
fix(server): other sites can no longer frame the web app
The static SPA handler sent no anti-framing headers, so a page that shares the session cookie's site could frame the app and steer a click onto a one-click action such as approving an agent sign-in on /connect-agent. HTML responses now send `Content-Security-Policy: frame-ancestors 'none'` and `X-Frame-Options: DENY`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent af9b4e4 commit 9ec2472

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎apps/server/src/http.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ it.layer(
399399
expect(response.status).toBe(200);
400400
expect(yield* response.text).toBe(nextHtml);
401401
expect(response.headers["cache-control"]).toBe("no-cache");
402+
expect(response.headers["content-security-policy"]).toBe("frame-ancestors 'none'");
403+
expect(response.headers["x-frame-options"]).toBe("DENY");
402404
expect(response.headers["etag"]).toBeUndefined();
403405
expect(response.headers["last-modified"]).toBeUndefined();
404406
}

‎apps/server/src/http.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ const streamStaticFile = (file: FileSystem.File, size: bigint) =>
564564
}),
565565
);
566566

567+
// The app can approve agents and start threads in one click, so no other site may frame it.
568+
const SPA_FRAME_HEADERS = {
569+
"Content-Security-Policy": "frame-ancestors 'none'",
570+
"X-Frame-Options": "DENY",
571+
};
572+
567573
const handleStaticAndDevRequest = Effect.fn("handleStaticAndDevRequest")(
568574
function* (immutableBuildAssets: ReadonlySet<string>) {
569575
const request = yield* HttpServerRequest.HttpServerRequest;
@@ -664,6 +670,7 @@ const handleStaticAndDevRequest = Effect.fn("handleStaticAndDevRequest")(
664670
};
665671
const headers: Record<string, string> = {
666672
"Cache-Control": cacheControl,
673+
...(isHtml ? SPA_FRAME_HEADERS : {}),
667674
...validators(fileInfo),
668675
};
669676
const etag = headers.ETag;
@@ -700,6 +707,7 @@ const handleStaticAndDevRequest = Effect.fn("handleStaticAndDevRequest")(
700707
return HttpServerResponse.uint8Array(bytes, {
701708
headers: {
702709
"Cache-Control": cacheControl,
710+
...(isHtml ? SPA_FRAME_HEADERS : {}),
703711
...validators({ ...info, size: ByteSize.bytes(bytes.byteLength) }),
704712
},
705713
contentType,

0 commit comments

Comments
 (0)