This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-gwq3-pvwq-4c9w
Added security headers to UI requests
- Loading branch information
Showing
7 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
user nginx; | ||
worker_processes auto; | ||
|
||
error_log /var/log/nginx/error.log notice; | ||
pid /var/run/nginx.pid; | ||
|
||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
|
||
http { | ||
# hide nginx version | ||
server_tokens off; | ||
|
||
#### Add security headers | ||
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" always; | ||
add_header X-Frame-Options "SAMEORIGIN"; | ||
add_header X-Content-Type-Options "nosniff"; | ||
add_header Cache-Control "no-cache, no-store"; | ||
|
||
# Add CSP policy. Allow the following URLs for the following reasons: | ||
# - fonts.gstatic.com and fonts.googleapis.com: Google Fonts and Material Icons | ||
# - localhost:* and ws://localhost:*: Webpack Dev Server | ||
# - self: own content | ||
# Note that in angular.json, the production 'optimization' configuration was | ||
# updated to the value provided in https://stackoverflow.com/a/71302985/5398197 | ||
# to prevent the need to add 'unsafe-inline' to the default-src directive. | ||
add_header Content-Security-Policy "default-src 'self'; connect-src 'self' <SERVER_URL> <ALGORITHM_STORE_URLS> ws://<SERVER_URL_NO_HTTP> wss://<SERVER_URL_NO_HTTP>; font-src https://fonts.gstatic.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com"; | ||
|
||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
|
||
keepalive_timeout 65; | ||
|
||
include /etc/nginx/conf.d/*.conf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
# replace environment variables for angular app | ||
envsubst < /usr/share/nginx/html/assets/env.template.js > /usr/share/nginx/html/assets/env.js | ||
|
||
# replace environment variables for nginx config. There the URL (without http(s)) | ||
# is used in the Content-Security-Policy header. | ||
# TODO the following process to set nginx configuration via sed is not ideal. Consider | ||
# doing it by directly using env vars in nginx.conf (see https://github.com/docker-library/docs/tree/master/nginx#using-environment-variables-in-nginx-configuration-new-in-119) | ||
if [ -z "${SERVER_URL}" ]; then | ||
SERVER_URL="https://cotopaxi.vantage6.ai" | ||
fi | ||
# Remove http(s) from the server url | ||
SERVER_URL_NO_HTTP=$(echo "$SERVER_URL" | sed 's/^https\?:\/\///g') | ||
# escape the slashes in the url | ||
SERVER_URL=$(echo "$SERVER_URL" | sed 's/\//\\\//g') | ||
sed -i "s/<SERVER_URL>/$SERVER_URL/g" /etc/nginx/nginx.conf | ||
sed -i "s/<SERVER_URL_NO_HTTP>/$SERVER_URL_NO_HTTP/g" /etc/nginx/nginx.conf | ||
|
||
# also whitelist the allowed algorithm stores in the CSP header | ||
if [ -z "${ALLOWED_ALGORITHM_STORES}" ]; then | ||
ALLOWED_ALGORITHM_STORES="*" | ||
fi | ||
# escape the slashes in the urls | ||
ALLOWED_ALGORITHM_STORES=$(echo "$ALLOWED_ALGORITHM_STORES" | sed 's/\//\\\//g') | ||
sed -i "s/<ALGORITHM_STORE_URLS>/$ALLOWED_ALGORITHM_STORES/g" /etc/nginx/nginx.conf |