How to setup csp and global headers with tanstack start? #3028
Unanswered
discoverlance-com
asked this question in
Q&A
Replies: 1 comment
-
@discoverlance-com I'm using a vinxi middleware to do this. Any feedback from the community is appreciated. ./app.config.ts import { defineConfig } from "@tanstack/start/config";
import tsConfigPaths from "vite-tsconfig-paths";
export default defineConfig({
vite: {
plugins: [
tsConfigPaths({
projects: ["./tsconfig.json"],
}),
],
},
routers: {
ssr: {
middleware: "./app/middleware/ssr.ts",
},
},
}); ./app/middleware/ssr.ts import { defineMiddleware, setResponseHeaders } from "vinxi/http";
export default defineMiddleware({
onBeforeResponse: (event) => {
setResponseHeaders(event, {
"X-Frame-Options": "DENY",
"X-Content-Type-Options": "nosniff",
"Referrer-Policy": "strict-origin-when-cross-origin",
"Permissions-Policy": "geolocation=(), camera=(), microphone=()",
"Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-inline'"
});
},
}); Don't have a solution for nonce's yet but probably it is a post-processing somewhere in the SSR handler, provided a request attribute is set with the correct nonce (pretty similar to the nextjs solution):
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This has been asked before in the discussion, #2476 but since there's no reply I am asking once more and with respect to tanstack start if anyone has an idea.
I want to configure some default http security headers like
x-frame-options
and such globally and also setup csp with a nonce if possible.How can I approach this and has anyone done it before?
Beta Was this translation helpful? Give feedback.
All reactions