Skip to content

Beautiful Open-Source Form Builder

Add support for embeddable domains in response headers

JhumanJ1de52c384704
diff --git a/client/runtimeConfig.js b/client/runtimeConfig.js
index 23ae4b573..f3d285198 100644
--- a/client/runtimeConfig.js
+++ b/client/runtimeConfig.js
@@ -35,4 +35,6 @@ export default {
*/
apiSecret: process.env.NUXT_API_SECRET || '',
privateApiBase: process.env.NUXT_PRIVATE_API_BASE || null,
+ // Comma-separated list of domains allowed to embed the entire platform (server-only)
+ allowedEmbedDomains: process.env.NUXT_ALLOWED_EMBED_DOMAINS || process.env.NUXT_PUBLIC_ALLOWED_EMBED_DOMAINS || '',
}
diff --git a/client/server/plugins/embeddable.js b/client/server/plugins/embeddable.js
index 86c15d2a3..22b262521 100644
--- a/client/server/plugins/embeddable.js
+++ b/client/server/plugins/embeddable.js
@@ -1,10 +1,40 @@
+import { getDomain } from '~/lib/utils'
+
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook("render:response", (response, { event }) => {
const routePath = event.node?.req?.url || event.node?.req?.originalUrl
- // const routePath= event.context.params._
+ const config = useRuntimeConfig()
+
+ // Parse allowed domains from private config
+ const allowedDomains = config.allowedEmbedDomains
+ ? config.allowedEmbedDomains.split(',').map(domain => domain.trim()).filter(Boolean)
+ : []
+
+ // Normalize allowed domains to hostnames (supports plain host or full URL)
+ const normalizedAllowed = allowedDomains.map((d) => (getDomain(d) || '').toLowerCase()).filter(Boolean)
+
+ // Build frame-ancestors for non-form routes: only allowed domains + localhost variants
+ const ancestors = ["'self'",
+ 'http://localhost', 'https://localhost',
+ 'http://127.0.0.1', 'https://127.0.0.1',
+ 'http://0.0.0.0', 'https://0.0.0.0',
+ 'http://[::1]', 'https://[::1]'
+ ]
+ normalizedAllowed.forEach((host) => {
+ ancestors.push(`https://${host}`)
+ ancestors.push(`http://${host}`)
+ })
+
+ // Remove legacy header to control framing via CSP
+ delete response.headers["X-Frame-Options"]
+ delete response.headers["x-frame-options"]
+
if (routePath && !routePath.startsWith("/forms/")) {
- // Only allow embedding of forms
- response.headers["X-Frame-Options"] = "sameorigin"
+ // Restrict embedding to explicit allowlist + localhost variants
+ response.headers["Content-Security-Policy"] = `frame-ancestors ${ancestors.join(' ')};`
+ } else {
+ // Forms: embeddable anywhere, omit CSP directive
+ delete response.headers["Content-Security-Policy"]
}
delete response.headers["x-powered-by"]