Skip to content

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.

fix(security): a webhook with no signature is as unauthenticated as a wrong one

Juan Denis47ec555915e4
diff --git a/backend/app/services/nginx_advanced_service.py b/backend/app/services/nginx_advanced_service.py
index 399aa546..570f7bdc 100644
--- a/backend/app/services/nginx_advanced_service.py
+++ b/backend/app/services/nginx_advanced_service.py
@@ -153,6 +153,11 @@ class NginxAdvancedService:
@staticmethod
def preview_diff(domain, new_config):
"""Preview config changes as a diff."""
+ # `domain` is joined onto SITES_AVAILABLE below — refuse anything that
+ # is not a plain filename so ../ can't turn this into an arbitrary
+ # file read (the API layer gates admins, but never trust one layer).
+ if not domain or os.path.basename(domain) != domain or domain in ('.', '..'):
+ return {'error': 'invalid domain'}
conf_path = os.path.join(NginxAdvancedService.SITES_AVAILABLE, domain)
old_config = ''
if os.path.isfile(conf_path):
diff --git a/backend/app/services/webhook_gateway_service.py b/backend/app/services/webhook_gateway_service.py
index 4f3cb200..e7e50b7a 100644
--- a/backend/app/services/webhook_gateway_service.py
+++ b/backend/app/services/webhook_gateway_service.py
@@ -164,12 +164,15 @@ class WebhookGatewayService:
db.session.add(delivery)
db.session.commit()
- if not signature_valid and signature_header:
+ # Reject unconditionally: every endpoint has a secret, so a request with
+ # a missing OR wrong signature is equally unauthenticated. The old
+ # `and signature_header` clause let unsigned requests through.
+ if not signature_valid:
delivery.status = 'failed'
- delivery.error_message = 'Invalid signature'
+ delivery.error_message = 'Invalid signature' if signature_header else 'Missing signature'
delivery.completed_at = datetime.utcnow()
db.session.commit()
- return {'success': False, 'error': 'Invalid signature', 'event_id': event_id}, 401
+ return {'success': False, 'error': delivery.error_message, 'event_id': event_id}, 401
try:
payload_json = json.loads(payload.decode('utf-8', errors='replace')) if payload else {}