Skip to content

Commit

Permalink
feat: add security headers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanMorel committed Dec 11, 2023
1 parent 495c85f commit 65b4427
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import fs from "fs";

const safeStylesheet = [].join(" ");

const safeScripts = ["*.googletagmanager.com"].join(" ");

const contentSecurityPolicy = `style-src 'self' 'unsafe-eval' 'unsafe-inline' ${safeStylesheet}; script-src 'self' ${safeScripts} 'unsafe-eval' 'unsafe-inline';`;

export function redirects() {
try {
const redirectsFile = fs.readFileSync("./src/redirects.json", "utf8");
Expand All @@ -17,6 +23,35 @@ const config = {
},
async redirects() {
return redirects();
},
async headers() {
return [
{
source: "/(.*)",
headers: [
{
key: "X-Frame-Options",
value: "DENY"
},
{
key: "Content-Security-Policy",
value: contentSecurityPolicy
},
{
key: "X-Content-Type-Options",
value: "nosniff"
},
{
key: "Permissions-Policy",
value: "camera=(), battery=(self), geolocation=(), microphone=()"
},
{
key: "Referrer-Policy",
value: "origin-when-cross-origin"
}
]
}
];
}
};

Expand Down

0 comments on commit 65b4427

Please sign in to comment.