Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .changeset/whole-needles-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 7 additions & 0 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ export function createApp({
maxHoldConnections = DEFAULT_MAX_HOLD_CONNECTIONS,
}: AppOptions) {
const app = new Hono();
// `?key=` bootstraps cookie auth, so never let a board URL disclose that
// credential to another origin through an outbound Referer header. Set this
// before auth so denied and public routes carry the same policy.
app.use("*", (c, next) => {
c.header("Referrer-Policy", "no-referrer");
return next();
});
const bus = new EventBus();
if (onEvent) {
bus.subscribe((event) => {
Expand Down
14 changes: 14 additions & 0 deletions test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,20 @@ test("auth token guards mutating routes when configured", async () => {
assert.equal(viaCookie.status, 200);
});

test("Referrer-Policy protects public, denied, and authenticated board responses", async () => {
const app = makeApp("secret");
const responses = await Promise.all([
app.request("/guide"),
app.request("/"),
app.request("/?key=secret"),
app.request("/api/sessions"),
]);

for (const response of responses) {
assert.equal(response.headers.get("referrer-policy"), "no-referrer");
}
});

async function readSseUntil(res: Response, needle: string, abort?: () => void): Promise<string> {
assert.ok(res.body);
const reader = res.body.getReader();
Expand Down
1 change: 1 addition & 0 deletions test/workerIntegration.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ test(
assert.equal(rendered.status, 200);
assert.match(await rendered.text(), /worker-marker/);
assert.equal(rendered.headers.get("content-security-policy"), "sandbox allow-scripts");
assert.equal(rendered.headers.get("referrer-policy"), "no-referrer");
assert.equal(rendered.headers.get("x-content-type-options"), "nosniff");
assert.match(rendered.headers.get("cache-control") ?? "", /immutable/);

Expand Down
Loading