Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ function demoChatHtml(): string {
export async function createServer(port: number) {
const app = express();
const server = http.createServer(app);

// Workshop is a local control plane with UI actions that can launch local
// agents. Do not allow a remote page to frame the UI and drive those actions.
app.use((_req, res, next) => {
res.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
res.setHeader("X-Frame-Options", "DENY");
next();
});

const wss = new WebSocketServer({
server,
path: "/ws",
Expand Down
18 changes: 18 additions & 0 deletions tests/security-headers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { afterAll, describe, expect, test } from "bun:test";
import request from "supertest";
import { createServer } from "../src/server";

const { app, server } = await createServer(0);

afterAll(() => {
server.close();
});

describe("security headers", () => {
test("prevents hostile pages from framing the Workshop UI", async () => {
const response = await request(app).get("/health").expect(200);

expect(response.headers["content-security-policy"]).toBe("frame-ancestors 'none'");
expect(response.headers["x-frame-options"]).toBe("DENY");
});
});