fix(docker): disallow embedding SwaggerUI served from docker by default (#9520)

This commit is contained in:
Vladimír Gorej
2024-01-26 15:57:18 +01:00
committed by GitHub
parent 8a53e7c6ec
commit f9ecb01aa8
4 changed files with 20 additions and 2 deletions

View File

@@ -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/

View File

@@ -38,5 +38,6 @@
}
include templates/cors.conf;
include templates/embedding.conf;
}
}

View File

@@ -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
docker/embedding.conf Normal file
View File

@@ -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;