Skip to content

Commit

Permalink
Merge pull request #276 from equinor/feat/add-security-headers
Browse files Browse the repository at this point in the history
✨  add security headers
  • Loading branch information
Brynjulf authored Sep 11, 2023
2 parents 9524fac + de09a73 commit e50abe7
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ USER 0
# Clear default nginx html file
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /app/storybook-static /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf.template
COPY proxy/nginx.conf /etc/nginx/conf.d/default.conf
COPY proxy/securityheaders.conf /etc/nginx/securityheaders.conf

WORKDIR /usr/share/nginx/html
USER 101
Expand Down
1 change: 1 addition & 0 deletions config/config_files/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ USER 0
RUN rm -rf /usr/share/nginx/html/*
COPY --from=base /app/dist /usr/share/nginx/html
COPY proxy/nginx.conf /etc/nginx/conf.d/default.conf.template
COPY proxy/securityheaders.conf /etc/nginx/conf.d/securityheaders.conf.template

EXPOSE 5001
ENV APPSETTING_ENV=local
Expand Down
4 changes: 4 additions & 0 deletions config/config_files/client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ jobs:
working-directory: client/proxy
run: diff nginx.conf <(curl https://raw.githubusercontent.com/equinor/amplify-components/main/config/config_files/nginx.conf)

- name: Compare remote proxy/nginx.conf to local
working-directory: client/proxy
run: diff securityheaders.conf <(curl https://raw.githubusercontent.com/equinor/amplify-components/main/config/config_files/securityheaders.conf)

- name: Compare remote src/setupLocalhost.mjs to local
working-directory: client/src
run: diff setupLocalhost.mjs <(curl https://raw.githubusercontent.com/equinor/amplify-components/main/config/config_files/setupLocalhost.mjs)
Expand Down
3 changes: 2 additions & 1 deletion config/config_files/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ echo " PORTAL_PROD_CLIENT_ID: \"$value\"," >>./env-config.js

echo "}" >>./env-config.js

# Update nginx.conf with relevant environment variables
# Update nginx.conf and securityheaders.conf with relevant environment variables
envsubst '${API_URL}' </etc/nginx/conf.d/default.conf.template >/etc/nginx/conf.d/default.conf
envsubst '${API_URL}' </etc/nginx/conf.d/securityheaders.conf.template >/etc/nginx/conf.d/securityheaders.conf
2 changes: 2 additions & 0 deletions config/config_files/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ server {

root /usr/share/nginx/html;

include /etc/nginx/securityheaders.conf;

location /api/ {
client_max_body_size 100M;
proxy_pass ${API_URL};
Expand Down
7 changes: 7 additions & 0 deletions config/config_files/securityheaders.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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 Referrer-Policy "same-origin";
add_header Permissions-Policy "fullscreen=(self), microphone=(), camera=(), autoplay=(), encrypted-media=(), geolocation=(), payment=(), usb=(), magnetometer=(), gyroscope=(), payment=()";
add_header Content-Security-Policy "default-src 'self'; frame-src 'self' https://login.microsoftonline.com; frame-ancestors 'self' https://login.microsoftonline.com; img-src 'self' https://*.equinor.com https://raw.githubusercontent.com data:; script-src 'self'; style-src 'self' 'unsafe-inline' https://cdn.eds.equinor.com; font-src 'self' https://cdn.eds.equinor.com; media-src 'none'; connect-src https://login.microsoftonline.com ${API_URL} https://graph.microsoft.com; block-all-mixed-content;";
add_header X-XSS-Protection "1; mode=block";
2 changes: 2 additions & 0 deletions config/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ cd ./proxy || (mkdir proxy && cd ./proxy || return)

curl -s "https://raw.githubusercontent.com/equinor/amplify-components/main/config/config_files/nginx.conf" > nginx.conf

curl -s "https://raw.githubusercontent.com/equinor/amplify-components/main/config/config_files/securityheaders.conf" > securityheaders.conf

cd ../..

printf -- "Downloading client github action...\n"
Expand Down
4 changes: 3 additions & 1 deletion nginx.conf → proxy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ server {

root /usr/share/nginx/html;

include /etc/nginx/securityheaders.conf;

location / {
index index.html index.htm;
try_files $uri /index.html;
try_files $uri /index.html;
}

location ~ \.html$ {
Expand Down
7 changes: 7 additions & 0 deletions proxy/securityheaders.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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 Referrer-Policy "same-origin";
add_header Permissions-Policy "fullscreen=(self), microphone=(), camera=(), autoplay=(), encrypted-media=(), geolocation=(), payment=(), usb=(), magnetometer=(), gyroscope=(), payment=()";
add_header Content-Security-Policy "default-src 'self'; frame-src 'self'; frame-ancestors 'self'; img-src 'self' https://raw.githubusercontent.com https://img.shields.io/npm/v/@equinor/amplify-components data:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' https://cdn.eds.equinor.com; font-src 'self' https://cdn.eds.equinor.com; media-src 'none'; connect-src 'self'; block-all-mixed-content;";
add_header X-XSS-Protection "1; mode=block";

0 comments on commit e50abe7

Please sign in to comment.