Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(security): add security headers (#1532)

Marc Klingen096abd4b128a
diff --git a/web/next.config.mjs b/web/next.config.mjs
index 168a694c39..5bc427fc86 100644
--- a/web/next.config.mjs
+++ b/web/next.config.mjs
@@ -6,6 +6,26 @@ await import("./src/env.mjs");
import { withSentryConfig } from "@sentry/nextjs";
import { env } from "./src/env.mjs";
+/**
+ * CSP headers
+ * img-src https to allow loading images from SSO providers
+ */
+const cspHeader = `
+ default-src 'self' https://ph.langfuse.com https://*.posthog.com wss://*.crisp.chat https://*.crisp.chat;
+ script-src 'self' https://*.crisp.chat https://challenges.cloudflare.com;
+ style-src 'self' 'unsafe-inline' https://*.crisp.chat;
+ img-src 'self' https: blob: data:;
+ font-src 'self' https://*.crisp.chat;
+ frame-src 'self' https://challenges.cloudflare.com;
+ worker-src 'self' blob:;
+ object-src 'none';
+ base-uri 'self';
+ form-action 'self';
+ frame-ancestors 'none';
+ block-all-mixed-content;
+ upgrade-insecure-requests;
+`;
+
/** @type {import("next").NextConfig} */
const nextConfig = {
transpilePackages: ["@langfuse/shared"],
@@ -32,27 +52,48 @@ const nextConfig = {
key: "x-frame-options",
value: "SAMEORIGIN",
},
+ {
+ key: 'X-Content-Type-Options',
+ value: 'nosniff'
+ },
+ {
+ key: 'Referrer-Policy',
+ value: 'strict-origin-when-cross-origin'
+ },
+ {
+ key: 'Permissions-Policy',
+ value: 'autoplay=*, fullscreen=*, microphone=*'
+ },
+ ],
+ },
+ {
+ source: '/:path((?!api).*)*',
+ headers: [
+ {
+ key: 'Content-Security-Policy',
+ value: cspHeader.replace(/\n/g, ''),
+ },
],
},
// Required to check authentication status from langfuse.com
...(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined
? [
- {
- source: "/api/auth/session",
- headers: [
- {
- key: "Access-Control-Allow-Origin",
- value: "https://langfuse.com",
- },
- { key: "Access-Control-Allow-Credentials", value: "true" },
- { key: "Access-Control-Allow-Methods", value: "GET,POST" },
- {
- key: "Access-Control-Allow-Headers",
- value: "Content-Type, Authorization",
- },
- ],
- },
- ]
+ {
+ source: "/api/auth/session",
+ headers: [
+ {
+ key: "Access-Control-Allow-Origin",
+ value: "https://langfuse.com",
+ },
+ { key: "Access-Control-Allow-Credentials", value: "true" },
+ { key: "Access-Control-Allow-Methods", value: "GET,POST" },
+ {
+ key: "Access-Control-Allow-Headers",
+ value: "Content-Type, Authorization",
+ },
+ ],
+ },
+ ]
: []),
];
},
diff --git a/web/package.json b/web/package.json
index bcdde60573..e91340f0c4 100644
--- a/web/package.json
+++ b/web/package.json
@@ -8,7 +8,7 @@
},
"scripts": {
"prebuild": "cp generated/openapi-client/openapi.yml public/openapi-client.yml && cp generated/openapi-server/openapi.yml public/openapi-server.yml",
- "build": "dotenv -e ../.env -- next build",
+ "build": "INLINE_RUNTIME_CHUNK=false dotenv -e ../.env -- next build",
"dev": "dotenv -e ../.env -- next dev",
"lint": "dotenv -e ../.env -- next lint",
"lint:fix": "dotenv -e ../.env -- next lint --fix",