fix: admin CSP allow inline scripts

script-src 'self' 'unsafe-inline' added to admin Content-Security-Policy.
default-src 'self' was blocking OverType editor init block and
the dev live-reload poller. Admin section is auth-gated so
unsafe-inline is acceptable.
This commit is contained in:
Pontoporeia
2026-04-06 16:49:14 +02:00
parent e6960f0c9c
commit b45e6c50cc
4 changed files with 21 additions and 10 deletions

View File

@@ -11,6 +11,10 @@ Pending tasks have been split into topic files under [`todo/`](todo/README.md):
## Recently completed (this session) ## Recently completed (this session)
- [x] `scripts/deploy-server.sh` — add step 4: `systemctl reload nginx` runs automatically; remove manual reload instruction from justfile
- [x] `nginx/posterg.conf` — add `script-src 'self' 'unsafe-inline'` to admin CSP; `default-src 'self'` was blocking OverType init script and live-reload poller
- [x] `RateLimit.php` — silence `mkdir()` with `@`; guard `file_put_contents` with `is_writable()` check so permission errors degrade gracefully (allow request, skip write) instead of spamming nginx error log - [x] `RateLimit.php` — silence `mkdir()` with `@`; guard `file_put_contents` with `is_writable()` check so permission errors degrade gracefully (allow request, skip write) instead of spamming nginx error log
- [x] `scripts/deploy-server.sh` + `scripts/setup-server.sh` — add `mkdir -p storage/cache/rate_limit` + `chown`/`chmod 2775` so php-fpm has write access on fresh deploys - [x] `scripts/deploy-server.sh` + `scripts/setup-server.sh` — add `mkdir -p storage/cache/rate_limit` + `chown`/`chmod 2775` so php-fpm has write access on fresh deploys

View File

@@ -70,7 +70,6 @@ deploy-nginx:
@echo "Files uploaded. SSH into the server and run:" @echo "Files uploaded. SSH into the server and run:"
@echo "" @echo ""
@echo " sudo bash /tmp/deploy-server.sh" @echo " sudo bash /tmp/deploy-server.sh"
@echo " sudo systemctl reload nginx"
@echo "" @echo ""
[group('deploy')] [group('deploy')]

View File

@@ -123,8 +123,10 @@ server {
# Rate limiting for admin # Rate limiting for admin
limit_req zone=admin burst=20 nodelay; limit_req zone=admin burst=20 nodelay;
# Content-Security-Policy - Tighter policy for admin # Content-Security-Policy - Admin policy
add_header Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; object-src 'none'; frame-ancestors 'none';" always; # script-src needs 'unsafe-inline' for the OverType editor init block
# and the live-reload poller (dev only). Admin is already auth-gated.
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; object-src 'none'; frame-ancestors 'none';" always;
# Disable directory listing # Disable directory listing
autoindex off; autoindex off;

View File

@@ -84,15 +84,21 @@ else
exit 1 exit 1
fi fi
# ── Step 4: Reload nginx ─────────────────────────────────────────────────────
printf "\n"
echo "📋 Step 4: Reloading nginx..."
echo "------------------------------"
systemctl reload nginx
ok "Nginx reloaded"
# ── Done ────────────────────────────────────────────────────────────────────── # ── Done ──────────────────────────────────────────────────────────────────────
printf "\n" printf "\n"
ok "Permissions fixed" ok "Permissions fixed"
ok "Nginx config installed" ok "Nginx config installed"
ok "Configuration validated" ok "Configuration validated"
printf "\n" ok "Nginx reloaded"
warn "Nginx has not been reloaded yet." printf "\nVerify:\n"
printf "Run: sudo systemctl reload nginx\n\n" printf " https://posterg.erg.be/\n"
printf "After reload, verify:\n" printf " https://posterg.erg.be/admin/\n"
printf " https://posterg.erg.be/\n" printf " https://posterg.erg.be/storage/posterg.db (should 403/404)\n"
printf " • https://posterg.erg.be/admin/\n"
printf " • https://posterg.erg.be/storage/posterg.db (should 403/404)\n"