1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 04:36:48 +00:00

fix(settings): ALLOWED_HOSTS lists the server's names instead of accepting any host

This commit is contained in:
catborise 2026-10-07 15:46:45 +03:00
parent c1381318f1
commit 9f5e8fe1c4
8 changed files with 90 additions and 4 deletions

View file

@ -58,3 +58,16 @@ wvc_install_nginx() {
cp "$snippet" "$etc/conf.d/webvirtcloud.conf"
return 0
}
# Python list literal for ALLOWED_HOSTS: the FQDN, the loopbacks and the given
# IPs. IPv6 addresses are bracketed, as Django compares them.
wvc_allowed_hosts() {
local host out="" seen=" "
for host in "$1" localhost 127.0.0.1 ::1 "${@:2}"; do
case "$host" in *:*) host="[$host]" ;; esac
case "$seen" in *" $host "*) continue ;; esac
seen+="$host "
out+="${out:+, }'$host'"
done
echo "[$out]"
}

View file

@ -66,5 +66,9 @@ echo "OP_EDIT" > "$etc3/nginx.conf"
wvc_install_nginx "$tmp/main_tpl" "$tmp/snippet" "$etc3"
check "no-orig second run keeps operator edit" "[ \"\$(cat '$etc3/nginx.conf')\" = OP_EDIT ]"
# wvc_allowed_hosts: fqdn + loopbacks + IPs, IPv6 bracketed, no duplicates
check "allowed hosts list" "[ \"\$(wvc_allowed_hosts wvc.example.com 192.0.2.10 2001:db8::1 127.0.0.1)\" = \"['wvc.example.com', 'localhost', '127.0.0.1', '[::1]', '192.0.2.10', '[2001:db8::1]']\" ]"
check "allowed hosts without ips" "[ \"\$(wvc_allowed_hosts wvc.example.com)\" = \"['wvc.example.com', 'localhost', '127.0.0.1', '[::1]']\" ]"
[ "$fail" = 0 ] && echo "ALL PASS" || echo "FAILURES"
exit "$fail"