ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(security): server-wide TLS floor at install/update + fix HTTPS update regression
Juan Denis3703b474568c
diff --git a/install.sh b/install.shindex c09ae552..7848718a 100644--- a/install.sh+++ b/install.sh@@ -616,6 +616,11 @@ configure_nginx() {sed -i '/http {/a \ include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conffi+ # Server-wide TLS floor: harden ssl_protocols/ssl_ciphers in the main+ # nginx.conf so even the default server and vhosts ServerKit did not+ # generate cannot negotiate TLS 1.0/1.1 or weak ciphers.+ harden_global_tls+# Drop any foreign catch-all vhost that would shadow the panel.for conf in /etc/nginx/sites-enabled/*; do[ -f "$conf" ] || continue@@ -700,6 +705,34 @@ install_nginx_config_for_mode() {fimkdir -p /etc/serverkitprintf '%s\n' "$SSL_MODE" > /etc/serverkit/ssl-mode+ # Persist the domain so update.sh can re-apply the cert path on upgrades+ # without depending on the (commented-out) .env public URL.+ [ -n "$PANEL_DOMAIN" ] && printf '%s\n' "$PANEL_DOMAIN" > /etc/serverkit/panel-domain+}++# ---------------------------------------------------------------------------+# Server-wide TLS floor. Rewrites the ssl_protocols / ssl_ciphers lines in the+# main nginx.conf (or injects them) so every HTTPS listener is forced onto+# TLS 1.2/1.3 with AEAD-only ciphers. Editing nginx.conf in place -- rather than+# adding a conf.d snippet -- avoids nginx's "duplicate ssl_protocols" error on+# distros (Debian/Ubuntu) that already set it in http{}. Idempotent.+# ---------------------------------------------------------------------------+harden_global_tls() {+ local conf=/etc/nginx/nginx.conf+ [ -f "$conf" ] || return 0+ local ciphers='ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384'++ if grep -qE '^[[:space:]]*ssl_protocols[[:space:]]' "$conf"; then+ sed -i -E 's|^([[:space:]]*)ssl_protocols[[:space:]].*|\1ssl_protocols TLSv1.2 TLSv1.3;|' "$conf"+ else+ sed -i '/http {/a \ ssl_protocols TLSv1.2 TLSv1.3;' "$conf"+ fi++ if grep -qE '^[[:space:]]*ssl_ciphers[[:space:]]' "$conf"; then+ sed -i -E "s|^([[:space:]]*)ssl_ciphers[[:space:]].*|\1ssl_ciphers ${ciphers};|" "$conf"+ else+ sed -i "/http {/a \\ ssl_ciphers ${ciphers};" "$conf"+ fi}# ---------------------------------------------------------------------------diff --git a/scripts/update.sh b/scripts/update.shindex 3d58e022..2498102b 100644--- a/scripts/update.sh+++ b/scripts/update.sh@@ -249,6 +249,13 @@ fi# ---------------------------------------------------------------------------phase "Refreshing Configuration"+# Recover the panel domain baked into the *current* live config before we+# overwrite it -- older installs predate /etc/serverkit/panel-domain.+PRIOR_PANEL_DOMAIN=$(grep -oE '/etc/letsencrypt/live/[^/]+/' \+ /etc/nginx/sites-available/serverkit.conf 2>/dev/null | head -n1 | \+ sed -E 's|.*/live/([^/]+)/|\1|')+[ "$PRIOR_PANEL_DOMAIN" = "YOUR_DOMAIN" ] && PRIOR_PANEL_DOMAIN=""+if [ -f "$INSTALL_DIR/nginx/sites-available/serverkit.conf" ]; thencp "$INSTALL_DIR/nginx/sites-available/serverkit.conf" /etc/nginx/sites-available/fi@@ -256,23 +263,46 @@ if [ -f "$INSTALL_DIR/nginx/sites-available/serverkit-insecure.conf" ]; thencp "$INSTALL_DIR/nginx/sites-available/serverkit-insecure.conf" /etc/nginx/sites-available/fi+# Re-apply the server-wide TLS floor (TLS 1.2/1.3 + AEAD ciphers) so existing+# installs get hardened on update too, not just fresh installs.+if [ -f /etc/nginx/nginx.conf ]; then+ SK_CIPHERS='ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384'+ if grep -qE '^[[:space:]]*ssl_protocols[[:space:]]' /etc/nginx/nginx.conf; then+ sed -i -E 's|^([[:space:]]*)ssl_protocols[[:space:]].*|\1ssl_protocols TLSv1.2 TLSv1.3;|' /etc/nginx/nginx.conf+ else+ sed -i '/http {/a \ ssl_protocols TLSv1.2 TLSv1.3;' /etc/nginx/nginx.conf+ fi+ if grep -qE '^[[:space:]]*ssl_ciphers[[:space:]]' /etc/nginx/nginx.conf; then+ sed -i -E "s|^([[:space:]]*)ssl_ciphers[[:space:]].*|\1ssl_ciphers ${SK_CIPHERS};|" /etc/nginx/nginx.conf+ else+ sed -i "/http {/a \\ ssl_ciphers ${SK_CIPHERS};" /etc/nginx/nginx.conf+ fi+fi+# Preserve the user's secure/insecure SSL choice across updates.SSL_MODE="insecure"if [ -f /etc/serverkit/ssl-mode ]; thenSSL_MODE=$(cat /etc/serverkit/ssl-mode)fiif [ "$SSL_MODE" = "secure" ] && [ -f /etc/nginx/sites-available/serverkit.conf ]; then- # Re-apply the Let's Encrypt path if we know the panel domain.+ # Recover the panel domain: prefer the value install.sh persisted, then the+ # one scraped from the prior live config above. (The old .env scrape was+ # broken -- SERVERKIT_PUBLIC_URL is written commented out.)PANEL_DOMAIN="${PANEL_DOMAIN:-}"- if [ -z "$PANEL_DOMAIN" ] && [ -f "$INSTALL_DIR/.env" ]; then- PANEL_DOMAIN=$(grep -E '^SERVERKIT_PUBLIC_URL=' "$INSTALL_DIR/.env" 2>/dev/null | \- sed 's|^SERVERKIT_PUBLIC_URL=||; s|^https\?://||; s|/.*||' || true)+ if [ -z "$PANEL_DOMAIN" ] && [ -f /etc/serverkit/panel-domain ]; then+ PANEL_DOMAIN=$(cat /etc/serverkit/panel-domain 2>/dev/null || true)fi+ [ -z "$PANEL_DOMAIN" ] && PANEL_DOMAIN="$PRIOR_PANEL_DOMAIN"+if [ -n "$PANEL_DOMAIN" ] && [ -d "/etc/letsencrypt/live/$PANEL_DOMAIN" ]; thensed -i "s|/etc/letsencrypt/live/YOUR_DOMAIN/|/etc/letsencrypt/live/$PANEL_DOMAIN/|g" \/etc/nginx/sites-available/serverkit.conf+ ln -sf /etc/nginx/sites-available/serverkit.conf /etc/nginx/sites-enabled/serverkit.conf+ else+ warn "SSL mode is 'secure' but no certificate was found for '${PANEL_DOMAIN:-unknown}'."+ warn "Using the HTTP config so nginx still reloads. Re-run certbot to restore HTTPS."+ ln -sf /etc/nginx/sites-available/serverkit-insecure.conf /etc/nginx/sites-enabled/serverkit.conffi- ln -sf /etc/nginx/sites-available/serverkit.conf /etc/nginx/sites-enabled/serverkit.confelseln -sf /etc/nginx/sites-available/serverkit-insecure.conf /etc/nginx/sites-enabled/serverkit.conffi