generated from nhcarrigan/template
refactor: remove port 80 listeners and enforce HTTPS-only in tests
Removes the listen 80 / listen [::]:80 blocks from cdn.conf since port 80 is blocked at the firewall. Updates test 6 to enforce that no custom server block listens on port 80 at all.
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
|
||||||
listen [::]:80;
|
|
||||||
listen 443 ssl;
|
listen 443 ssl;
|
||||||
listen [::]:443 ssl;
|
listen [::]:443 ssl;
|
||||||
|
|
||||||
|
|||||||
@@ -101,21 +101,19 @@ done
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────
|
||||||
# 6. Any port-80 listener must also have a port-443 listener in the
|
# 6. No port-80 listeners in any custom server block
|
||||||
# same file (HTTP-only serving is not acceptable for real sites)
|
# (port 80 is blocked at the firewall; all traffic is HTTPS only)
|
||||||
# ──────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────
|
||||||
echo "--- HTTP-only server block check ---"
|
echo "--- Port 80 listener check ---"
|
||||||
http_only_errors=0
|
http_blocks=$(grep -rnP 'listen\s.*\b80\b' "$NGINX_DIR/sites-available/" \
|
||||||
for conf in "$NGINX_DIR/sites-available/"*.conf; do
|
| grep -v 'sites-available/default' \
|
||||||
[ "$(basename "$conf")" = "default" ] && continue
|
| grep -v '^\s*#' || true)
|
||||||
has_80=$(grep -cP 'listen\s.*\b80\b' "$conf" 2>/dev/null || true)
|
if [ -n "$http_blocks" ]; then
|
||||||
has_443=$(grep -c 'listen 443' "$conf" 2>/dev/null || true)
|
fail "Port 80 listeners found in custom site configs:"
|
||||||
if [ "${has_80:-0}" -gt 0 ] && [ "${has_443:-0}" -eq 0 ]; then
|
printf '%s\n' "$http_blocks" | sed 's/^/ /'
|
||||||
fail "$(basename "$conf"): listens on port 80 but has no port-443 listener"
|
else
|
||||||
http_only_errors=1
|
pass "No port 80 listeners in custom server blocks"
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
[ "$http_only_errors" -eq 0 ] && pass "No HTTP-only server blocks in custom sites"
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user