Skip to content

Commit 26d4e63

Browse files
author
Eric
committed
feat(nginx): emit Content-Security-Policy from origin (csp-headers.conf)
Include CSP in each location that sets Cache-Control so headers apply on HTML/static responses (nginx add_header inheritance rules). Used by Dockerfile-react / ghcr.io isaac-react-app-cs image builds. Made-with: Cursor
1 parent e49a7e8 commit 26d4e63

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

Dockerfile-react

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ ARG BUILD_TARGET
1818

1919
COPY --from=builder /build/$BUILD_TARGET/ /usr/share/nginx/html
2020
COPY nginx.conf /etc/nginx/nginx.conf
21+
COPY csp-headers.conf /etc/nginx/csp-headers.conf

csp-headers.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Included from each location block that sets Cache-Control (nginx does not inherit
2+
# add_header from http/server when a location defines its own add_header).
3+
add_header Content-Security-Policy "default-src 'self' https://*.isaaccomputerscience.org; object-src 'none'; frame-src 'self' https://*.isaaccomputerscience.org https://www.youtube.com https://www.youtube-nocookie.com https://www.google.com https://www.gstatic.com https://fast.wistia.net; img-src 'self' data: https://cdn-cookieyes.com https://*.isaaccomputerscience.org https://*.google-analytics.com https://*.googletagmanager.com https://*.tile.openstreetmap.org https://developers.google.com https://i.ytimg.com/; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://*.isaaccomputerscience.org https://fonts.gstatic.com; connect-src 'self' wss://*.isaaccomputerscience.org https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com https://*.cookieyes.com https://cdn-cookieyes.com; script-src 'self' https://*.isaaccomputerscience.org https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com https://www.youtube-nocookie.com https://www.youtube.com https://www.google.com https://www.gstatic.com https://cdn-cookieyes.com https://fast.wistia.net https://embedwistia-a.akamaihd.net" always;

nginx.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,28 @@ http {
5050
location /assets {
5151
# Strongly cache these things for at least 30 days:
5252
add_header Cache-Control "public, max-age=2592000, no-transform";
53+
include /etc/nginx/csp-headers.conf;
5354
try_files $uri @default;
5455
}
5556

5657
location /static {
5758
# Maybe also strongly cache these things for at least 30 days?
5859
add_header Cache-Control "public, max-age=2592000, no-transform";
60+
include /etc/nginx/csp-headers.conf;
5961
try_files $uri @default;
6062
}
6163

6264
location /index.html {
6365
# Index pages, and also serves unknown URLs too from @default.
6466
# Do not allow caching of these index pages at all:
6567
add_header Cache-Control "no-cache, no-store, must-revalidate";
68+
include /etc/nginx/csp-headers.conf;
6669
try_files $uri @default;
6770
}
6871

6972
location ~ ^/unsupported_browser.(html|js)$ {
7073
add_header Cache-Control "no-cache, no-store, must-revalidate";
74+
include /etc/nginx/csp-headers.conf;
7175
try_files $uri @default;
7276
}
7377

@@ -78,6 +82,7 @@ http {
7882
}
7983
# Allow caching, but require revalidation every time:
8084
add_header Cache-Control "no-cache, must-revalidate";
85+
include /etc/nginx/csp-headers.conf;
8186
try_files $uri @default;
8287
}
8388

0 commit comments

Comments
 (0)