Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: add Content-Security-Policy env (#8752)

Shinji-Li925054091203
diff --git a/.env.example b/.env.example
index 735a996251a..0fb9ad8aa6e 100644
--- a/.env.example
+++ b/.env.example
@@ -4,6 +4,14 @@
# Specify your API Key selection method, currently supporting `random` and `turn`.
# API_KEY_SELECT_MODE=random
+########################################
+########### Security Settings ###########
+########################################
+
+# Control Content Security Policy headers
+# Set to '1' to enable X-Frame-Options and Content-Security-Policy headers
+# Default is '0' (enabled)
+# ENABLED_CSP=1
########################################
########## AI Provider Service #########
diff --git a/next.config.ts b/next.config.ts
index 45ce49c8659..c3a94dd54d2 100644
--- a/next.config.ts
+++ b/next.config.ts
@@ -9,6 +9,7 @@ const buildWithDocker = process.env.DOCKER === 'true';
const isDesktop = process.env.NEXT_PUBLIC_IS_DESKTOP_APP === '1';
const enableReactScan = !!process.env.REACT_SCAN_MONITOR_API_KEY;
const isUsePglite = process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite';
+const shouldUseCSP = process.env.ENABLED_CSP === '1';
// if you need to proxy the api endpoint to remote server
@@ -41,14 +42,29 @@ const nextConfig: NextConfig = {
webVitalsAttribution: ['CLS', 'LCP'],
},
async headers() {
+ const securityHeaders = [
+ {
+ key: 'x-robots-tag',
+ value: 'all',
+ },
+ ];
+
+ if (shouldUseCSP) {
+ securityHeaders.push(
+ {
+ key: 'X-Frame-Options',
+ value: 'DENY',
+ },
+ {
+ key: 'Content-Security-Policy',
+ value: "frame-ancestors 'none';",
+ },
+ );
+ }
+
return [
{
- headers: [
- {
- key: 'x-robots-tag',
- value: 'all',
- },
- ],
+ headers: securityHeaders,
source: '/:path*',
},
{