Add a content security policy and expire mailed export links.
Responses had no CSP, the 48-hour download token never changed, and short share slugs could be guessed without a miss limit.
This commit is contained in:
1 parent
0fe2624002
commit
75649a9a42
18 files changed
+249
-19
No files matched your search
@@ -24,9 +24,41 @@ const svgrLoaderOptions = {
|
||||
},
|
||||
};
|
||||
|
||||
function umamiOrigin() {
|
||||
const src = process.env.NEXT_PUBLIC_UMAMI_SRC?.trim() ?? "";
|
||||
if (!src) return "";
|
||||
try {
|
||||
return new URL(src).origin;
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function contentSecurityPolicy() {
|
||||
const umami = umamiOrigin();
|
||||
const scriptSrc = umami
|
||||
? `'self' 'unsafe-inline' ${umami}`
|
||||
: `'self' 'unsafe-inline'`;
|
||||
const connectSrc = umami ? `'self' ${umami}` : `'self'`;
|
||||
return [
|
||||
"default-src 'self'",
|
||||
`script-src ${scriptSrc}`,
|
||||
"style-src 'self' 'unsafe-inline'",
|
||||
"img-src 'self' data: blob:",
|
||||
"font-src 'self'",
|
||||
`connect-src ${connectSrc}`,
|
||||
"object-src 'none'",
|
||||
"base-uri 'self'",
|
||||
"form-action 'self'",
|
||||
"frame-ancestors 'none'",
|
||||
"upgrade-insecure-requests",
|
||||
].join("; ");
|
||||
}
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
output: "standalone",
|
||||
poweredByHeader: false,
|
||||
serverExternalPackages: ["@prisma/client"],
|
||||
// React Compiler — annotation mode: opt-in via the `"use memo"` directive at
|
||||
// the top of a component/hook. With no annotations in the codebase yet, this
|
||||
@@ -102,6 +134,18 @@ const nextConfig = {
|
||||
key: "X-XSS-Protection",
|
||||
value: "1; mode=block",
|
||||
},
|
||||
{
|
||||
key: "Referrer-Policy",
|
||||
value: "same-origin",
|
||||
},
|
||||
{
|
||||
key: "Permissions-Policy",
|
||||
value: "camera=(), microphone=(), geolocation=()",
|
||||
},
|
||||
{
|
||||
key: "Content-Security-Policy",
|
||||
value: contentSecurityPolicy(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user