Skip to content

Commit

Permalink
fix(docker): disallow embedding SwaggerUI served from docker by defau…
Browse files Browse the repository at this point in the history
…lt (#9520)
  • Loading branch information
char0n authored Jan 26, 2024
1 parent 8a53e7c commit f9ecb01
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ ENV API_KEY="**None**" \
PORT="8080" \
PORT_IPV6="" \
BASE_URL="/" \
SWAGGER_JSON_URL=""
SWAGGER_JSON_URL="" \
CORS="true" \
EMBEDDING="false"

COPY --chown=nginx:nginx --chmod=0666 ./docker/default.conf.template ./docker/cors.conf /etc/nginx/templates/
COPY --chown=nginx:nginx --chmod=0666 ./docker/default.conf.template ./docker/cors.conf ./docker/embedding.conf /etc/nginx/templates/

COPY --chmod=0666 ./dist/* /usr/share/nginx/html/
COPY --chmod=0555 ./docker/docker-entrypoint.d/ /docker-entrypoint.d/
Expand Down
1 change: 1 addition & 0 deletions docker/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
}

include templates/cors.conf;
include templates/embedding.conf;
}
}
10 changes: 10 additions & 0 deletions docker/docker-entrypoint.d/40-swagger-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ if [[ -n "${PORT_IPV6}" ]]; then
sed -i "s|${PORT};|${PORT};\n listen [::]:${PORT_IPV6};|g" $NGINX_CONF
fi

# enable/disable CORS
if [ "$CORS" != "true" ]; then
truncate -s 0 /etc/nginx/templates/cors.conf
fi

# allow/disallow embedding the swagger-ui in frames/iframes from different origins
if [ "$EMBEDDING" != "false" ]; then
truncate -s 0 /etc/nginx/templates/embedding.conf
fi

find $NGINX_ROOT -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;
5 changes: 5 additions & 0 deletions docker/embedding.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Prevent displaying inside an iframe
#
add_header 'X-Frame-Options' 'DENY' always;
add_header 'Content-Security-Policy' "frame-ancestors 'none'" always;

0 comments on commit f9ecb01

Please sign in to comment.