Skip to content

Commit 3d2e1b8

Browse files
committed
🛂 server: setup frontend secure headers
1 parent e102d13 commit 3d2e1b8

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@exactly/server": patch
3+
---
4+
5+
🛂 setup frontend secure headers

‎server/index.ts‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { serveStatic } from "@hono/node-server/serve-static";
55
import { captureException, close } from "@sentry/node";
66
import { isoBase64URL } from "@simplewebauthn/server/helpers";
77
import { Hono } from "hono";
8+
import { secureHeaders } from "hono/secure-headers";
89
import { trimTrailingSlash } from "hono/trailing-slash";
910
import type { UnofficialStatusCode } from "hono/utils/http-status";
1011

@@ -78,7 +79,52 @@ app.get("/.well-known/farcaster.json", (c) =>
7879
},
7980
}),
8081
);
81-
app.use(
82+
83+
const frontend = new Hono();
84+
frontend.use(
85+
secureHeaders({
86+
xFrameOptions: false,
87+
referrerPolicy: "strict-origin-when-cross-origin",
88+
reportingEndpoints: [
89+
{
90+
name: "sentry",
91+
url: `https://o1351734.ingest.us.sentry.io/api/4506186349674496/security/?sentry_key=ac8875331e4cecd67dd0a7519a36dfeb&sentry_environment=${
92+
{ "web.exactly.app": "production" }[domain] ?? "development"
93+
}`,
94+
},
95+
],
96+
contentSecurityPolicy: {
97+
defaultSrc: ["'self'"],
98+
fontSrc: ["'self'"],
99+
imgSrc: ["'self'", "data:", "https://avatars.githubusercontent.com"],
100+
styleSrc: ["'self'", "'unsafe-inline'"],
101+
scriptSrc: [
102+
"'self'",
103+
"'unsafe-inline'",
104+
"https://cdn.onesignal.com",
105+
"https://api.onesignal.com",
106+
"https://widget.intercom.io",
107+
"https://js.intercomcdn.com",
108+
],
109+
connectSrc: [
110+
"'self'",
111+
"https://li.quest",
112+
"https://*.g.alchemy.com",
113+
"https://assets.smold.app",
114+
"https://api.onesignal.com",
115+
"https://api-iam.intercom.io",
116+
"https://*.ingest.us.sentry.io",
117+
"https://raw.githubusercontent.com",
118+
"wss://nexus-websocket-a.intercom.io/",
119+
],
120+
frameAncestors: ["https://farcaster.xyz"],
121+
objectSrc: ["'none'"],
122+
baseUri: ["'none'"],
123+
reportTo: "sentry",
124+
},
125+
}),
126+
);
127+
frontend.use(
82128
serveStatic({
83129
root: "app",
84130
rewriteRequestPath: (path) => {
@@ -91,7 +137,7 @@ app.use(
91137
},
92138
}),
93139
);
94-
app.use(
140+
frontend.use(
95141
serveStatic({
96142
root: "app",
97143
rewriteRequestPath: (path) => {
@@ -104,6 +150,7 @@ app.use(
104150
},
105151
}),
106152
);
153+
app.route("/", frontend);
107154

108155
app.onError((error, c) => {
109156
captureException(error, { level: "error", tags: { unhandled: true } });

0 commit comments

Comments
 (0)