@@ -226,6 +226,47 @@ init_nginx() {
226
226
fi
227
227
fi
228
228
229
+ # Adjust Content-Security-Policy
230
+ echo " ... adjusting Content-Security-Policy"
231
+ # Remove any existing CSP header
232
+ sed -i ' /add_header Content-Security-Policy/d' /etc/nginx/includes/misp
233
+
234
+ if [[ -n " $CONTENT_SECURITY_POLICY " ]]; then
235
+ # If $CONTENT_SECURITY_POLICY is set, add CSP header
236
+ echo " ... setting Content-Security-Policy to '$CONTENT_SECURITY_POLICY '"
237
+ sed -i " /add_header X-Download-Options/a add_header Content-Security-Policy \" $CONTENT_SECURITY_POLICY \" ;" /etc/nginx/includes/misp
238
+ else
239
+ # Otherwise, do not add any CSP headers
240
+ echo " ... no Content-Security-Policy header will be set as CONTENT_SECURITY_POLICY is not defined"
241
+ fi
242
+
243
+ # Adjust X-Frame-Options
244
+ echo " ... adjusting X-Frame-Options"
245
+ # Remove any existing X-Frame-Options header
246
+ sed -i ' /add_header X-Frame-Options/d' /etc/nginx/includes/misp
247
+
248
+ if [[ -z " $X_FRAME_OPTIONS " ]]; then
249
+ echo " ... setting 'X-Frame-Options SAMEORIGIN'"
250
+ sed -i " /add_header X-Download-Options/a add_header X-Frame-Options \" SAMEORIGIN\" always;" /etc/nginx/includes/misp
251
+ else
252
+ echo " ... setting 'X-Frame-Options $X_FRAME_OPTIONS '"
253
+ sed -i " /add_header X-Download-Options/a add_header X-Frame-Options \" $X_FRAME_OPTIONS \" ;" /etc/nginx/includes/misp
254
+ fi
255
+
256
+ # Adjust HTTP Strict Transport Security (HSTS)
257
+ echo " ... adjusting HTTP Strict Transport Security (HSTS)"
258
+ # Remove any existing HSTS header
259
+ sed -i ' /add_header Strict-Transport-Security/d' /etc/nginx/includes/misp
260
+
261
+ if [[ -n " $HSTS_MAX_AGE " ]]; then
262
+ # If $HSTS_MAX_AGE is defined, add the HSTS header
263
+ echo " ... setting HSTS to 'max-age=$HSTS_MAX_AGE ; includeSubdomains'"
264
+ sed -i " /add_header X-Download-Options/a add_header Strict-Transport-Security \" max-age=$HSTS_MAX_AGE ; includeSubdomains\" ;" /etc/nginx/includes/misp
265
+ else
266
+ # Otherwise, do nothing, keeping without the HSTS header
267
+ echo " ... no HSTS header will be set as HSTS_MAX_AGE is not defined"
268
+ fi
269
+
229
270
# Testing for files also test for links, and generalize better to mounted files
230
271
if [[ ! -f " /etc/nginx/sites-enabled/misp80" ]]; then
231
272
echo " ... enabling port 80 redirect"
0 commit comments