fix(docker): escape env values in env.js heredoc

SEC-9: a double quote or backslash in APP_* broke the generated JS
(silent config corruption). js_escape() escapes both and collapses
newlines before interpolation. Docker-verified with a hostile
APP_BRAND_NAME: env.js parses, value round-trips exactly.
This commit is contained in:
Bastien Chanot committed 2026-07-12 16:26:21 +02:00
1 parent f58a49f7fc
commit 0214ae1537
1 file changed
+15 -4
+15 -4
View File
@@ -7,12 +7,23 @@ set -e
ENV_JS="/usr/share/nginx/html/env.js"
# Escapes a value for safe embedding in a double-quoted JS string literal
# (backslashes, double quotes; newlines collapsed to spaces).
js_escape() {
printf '%s' "$1" | tr '\n' ' ' | sed 's/\\/\\\\/g; s/"/\\"/g'
}
SITE_NAME=$(js_escape "${APP_SITE_NAME:-Faunosteo}")
BRAND_NAME=$(js_escape "${APP_BRAND_NAME:-Faunosteo}")
FOOTER_NAME=$(js_escape "${APP_FOOTER_NAME:-Faunosteo}")
TAGLINE=$(js_escape "${APP_TAGLINE:-Outils pour ostéopathes animaliers}")
cat > "$ENV_JS" <<EOF
window.__APP_CONFIG__ = {
siteName: "${APP_SITE_NAME:-Faunosteo}",
brandName: "${APP_BRAND_NAME:-Faunosteo}",
footerName: "${APP_FOOTER_NAME:-Faunosteo}",
tagline: "${APP_TAGLINE:-Outils pour ostéopathes animaliers}"
siteName: "${SITE_NAME}",
brandName: "${BRAND_NAME}",
footerName: "${FOOTER_NAME}",
tagline: "${TAGLINE}"
};
EOF