File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ Images with `nginx` can be configured using the following environment variables.
1414
1515### Content Security Policy
1616
17+ You can control the CSP behaviour with the ` NGINX_CSP_MODE ` key:
18+ - ` enforce ` (default): Configure the ` Content-Security-Policy ` header.
19+ - ` report-only ` : Instead configure the ` Content-Security-Policy-Report-Only ` header.
20+
1721Fetch:
1822
1923| Environment Key | Applied | Description | Default |
Original file line number Diff line number Diff line change @@ -5,13 +5,25 @@ set -euo pipefail
55# Configure nginx security based on ENV vars.
66#
77# Inputs (aside from all the individual CSP settings):
8+ # - NGINX_CSP_MODE: defaults to 'enforce'
89# - NGINX_CSP_REPORT_URI: defaults to ''
910# - NGINX_FRAME_OPTIONS: defaults to 'deny', note that setting to `disable` removes the header completely.
1011
1112# Set defaults
13+ NGINX_CSP_MODE=" ${NGINX_CSP_MODE:- enforce} "
1214NGINX_CSP_REPORT_URI=" ${NGINX_CSP_REPORT_URI:- } "
1315NGINX_FRAME_OPTIONS=" ${NGINX_FRAME_OPTIONS:- deny} "
1416
17+ # Validate input
18+ if [ " ${NGINX_CSP_MODE} " = ' enforce' ]; then
19+ NGINX_CSP_HEADER_NAME=' Content-Security-Policy'
20+ elif [ " ${NGINX_CSP_MODE} " = ' report-only' ]; then
21+ NGINX_CSP_HEADER_NAME=' Content-Security-Policy-Report-Only'
22+ else
23+ echo " Nginx: invalid CSP mode ${NGINX_CSP_MODE} "
24+ exit 1
25+ fi
26+
1527# Check nginx structure
1628if [ ! -d /etc/nginx/site-mods-enabled.d/ ]; then
1729 echo " Nginx: site-mods-enabled folder is missing, skipping security…"
2941# nginx content policy
3042echo " Nginx: configuring content security policy…"
3143cat << EOF >> /etc/nginx/site-mods-enabled.d/00-generated-security.conf
32- add_header 'Content-Security-Policy ' "\
44+ add_header '${NGINX_CSP_HEADER_NAME} ' "\
3345default-src 'self'; \
3446child-src ${NGINX_CSP_CHILD_SRC:- } ; \
3547connect-src ${NGINX_CSP_CONNECT_SRC:- } ; \
You can’t perform that action at this time.
0 commit comments