Skip to content

Commit bb4003b

Browse files
author
charlesgauthereau
committed
Working on header and CSP.
1 parent 1593984 commit bb4003b

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

docker/dockerfile/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ RUN chown -R nextjs:nodejs /app/public
8888

8989

9090
COPY --from=builder /app/next.config.ts ./
91+
COPY --from=builder /app/portabase.config.ts ./
9192
COPY --from=builder /app/drizzle.config.ts ./
9293
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
9394
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

next.config.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
import type { NextConfig } from "next";
2+
import {PORTABASE_DEFAULT_SETTINGS} from "./portabase.config";
3+
4+
5+
function buildCSPHeader(): string {
6+
const { CSP } = PORTABASE_DEFAULT_SETTINGS.SECURITY;
7+
8+
const directives = [
9+
`default-src ${CSP.DEFAULT_SRC.join(" ")}`,
10+
`script-src ${CSP.SCRIPT_SRC.join(" ")}`,
11+
`style-src ${CSP.STYLE_SRC.join(" ")}`,
12+
`img-src ${CSP.IMG_SRC.join(" ")}`,
13+
`font-src ${CSP.FONT_SRC.join(" ")}`,
14+
`object-src ${CSP.OBJECT_SRC.join(" ")}`,
15+
`base-uri ${CSP.BASE_URI.join(" ")}`,
16+
`form-action ${CSP.FORM_ACTION.join(" ")}`,
17+
`frame-ancestors ${CSP.FRAME_ANCESTORS.join(" ")}`,
18+
];
19+
20+
if (CSP.BLOCK_ALL_MIXED_CONTENT) {
21+
directives.push("block-all-mixed-content");
22+
}
23+
24+
if (CSP.UPGRADE_INSECURE_REQUESTS) {
25+
directives.push("upgrade-insecure-requests");
26+
}
27+
28+
return directives.join("; ");
29+
}
30+
31+
function buildPermissionsPolicy(): string {
32+
return Object.entries(PORTABASE_DEFAULT_SETTINGS.SECURITY.PERMISSIONS_POLICY)
33+
.map(([feature, values]) => `${feature}=${values.join(", ")}`)
34+
.join(", ");
35+
}
36+
37+
38+
239

340
const nextConfig: NextConfig = {
441
output: "standalone",
@@ -14,6 +51,36 @@ const nextConfig: NextConfig = {
1451
experimental: {
1552
nodeMiddleware: true,
1653
},
54+
async headers() {
55+
return [
56+
{
57+
source: "/(.*)",
58+
headers: [
59+
{
60+
key: "Content-Security-Policy",
61+
value: buildCSPHeader(),
62+
},
63+
{
64+
key: "Permissions-Policy",
65+
value: buildPermissionsPolicy(),
66+
},
67+
{
68+
key: 'X-Content-Type-Options',
69+
value: 'nosniff',
70+
},
71+
{
72+
key: 'X-Frame-Options',
73+
value: 'DENY',
74+
},
75+
{
76+
key: 'Referrer-Policy',
77+
value: 'strict-origin-when-cross-origin',
78+
},
79+
// ...other security headers
80+
],
81+
},
82+
];
83+
},
1784
};
1885

1986
export default nextConfig;

portabase.config.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
export const PORTABASE_DEFAULT_SETTINGS = {
3+
SECURITY: {
4+
CSP: {
5+
DEFAULT_SRC: ["'self'"],
6+
SCRIPT_SRC: ["'self'", "'unsafe-eval'", "'unsafe-inline'", "https://cdn.jsdelivr.net", "https://www.googletagmanager.com"],
7+
STYLE_SRC: ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"],
8+
IMG_SRC: ["'self'", "blob:", "data:", "https:"],
9+
FONT_SRC: ["'self'"],
10+
OBJECT_SRC: ["'none'"],
11+
BASE_URI: ["'self'"],
12+
FORM_ACTION: ["'self'"],
13+
FRAME_ANCESTORS: ["'none'"],
14+
BLOCK_ALL_MIXED_CONTENT: false,
15+
UPGRADE_INSECURE_REQUESTS: true,
16+
},
17+
PERMISSIONS_POLICY: {
18+
CAMERA: ["()"],
19+
MICROPHONE: ["()"],
20+
GEOLOCATION: ["()"],
21+
FULLSCREEN: ["(self)"],
22+
// ...other features
23+
},
24+
},
25+
};

0 commit comments

Comments
 (0)