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(github): repair app manifest setup flow (#131)

Rebertt Rodrigues498c249536d0
diff --git a/backend/app/middleware/security.py b/backend/app/middleware/security.py
index e78fd842..9c9b5ea9 100644
--- a/backend/app/middleware/security.py
+++ b/backend/app/middleware/security.py
@@ -34,7 +34,7 @@ def register_security_headers(app: Flask):
"connect-src 'self' ws: wss: http://localhost:* http://127.0.0.1:*",
"frame-ancestors 'none'",
"base-uri 'self'",
- "form-action 'self'",
+ "form-action 'self' https://github.com",
]
else:
csp_directives = [
@@ -46,7 +46,7 @@ def register_security_headers(app: Flask):
"connect-src 'self' ws: wss:",
"frame-ancestors 'none'",
"base-uri 'self'",
- "form-action 'self'",
+ "form-action 'self' https://github.com",
]
response.headers['Content-Security-Policy'] = '; '.join(csp_directives)
diff --git a/backend/app/services/source_connection_service.py b/backend/app/services/source_connection_service.py
index c846f162..bcf2c4ea 100644
--- a/backend/app/services/source_connection_service.py
+++ b/backend/app/services/source_connection_service.py
@@ -110,6 +110,13 @@ class SourceConnectionService:
'name': f'ServerKit {suffix}',
'url': base_url,
'redirect_url': redirect_uri,
+ # GitHub requires a webhook URL when the manifest subscribes to
+ # events. Keep delivery disabled until ServerKit has an app-level
+ # receiver; deployments configure their own webhooks separately.
+ 'hook_attributes': {
+ 'url': f'{base_url}/api/v1/source-connections/github/webhook',
+ 'active': False,
+ },
# Where GitHub sends the user after they install the app (also the
# user-to-server OAuth callback, so install + authorize land here).
'callback_urls': [f'{base_url}/connections/callback/github'],
diff --git a/backend/tests/test_github_app_manifest.py b/backend/tests/test_github_app_manifest.py
index 11610c8c..16507011 100644
--- a/backend/tests/test_github_app_manifest.py
+++ b/backend/tests/test_github_app_manifest.py
@@ -23,6 +23,10 @@ def test_build_manifest_shape_and_state(app):
assert manifest['name'].startswith('ServerKit')
assert manifest['url'] == 'https://panel.example'
assert manifest['redirect_url'].endswith('/connections/github-app/callback')
+ assert manifest['hook_attributes'] == {
+ 'url': 'https://panel.example/api/v1/source-connections/github/webhook',
+ 'active': False,
+ }
assert manifest['callback_urls'] == ['https://panel.example/connections/callback/github']
assert manifest['default_permissions']['contents'] == 'read'
assert manifest['request_oauth_on_install'] is True
@@ -37,6 +41,18 @@ def test_build_manifest_requires_urls(app):
SC.build_github_app_manifest('', 'https://panel.example')
+def test_manifest_webhook_url_has_no_double_slash(app):
+ with app.test_request_context():
+ manifest, _, _ = SC.build_github_app_manifest(
+ 'https://panel.example/connections/github-app/callback',
+ 'https://panel.example/',
+ )
+
+ assert manifest['hook_attributes']['url'] == (
+ 'https://panel.example/api/v1/source-connections/github/webhook'
+ )
+
+
def _fake_conversion_response():
class FakeResp:
def raise_for_status(self):
diff --git a/backend/tests/test_security_headers.py b/backend/tests/test_security_headers.py
index bf8659ec..58d6cebc 100644
--- a/backend/tests/test_security_headers.py
+++ b/backend/tests/test_security_headers.py
@@ -1,4 +1,4 @@
-"""Proving tests — HSTS is gated on the operator's SSL choice.
+"""Proving tests for the panel's security headers.
HTTPS is optional in ServerKit, so the panel must NOT advertise HSTS/preload
(a hard-to-reverse browser commitment) unless the deployment actually
@@ -7,7 +7,19 @@ a proxy Flask can't tell real TLS from a Cloudflare-Flexible edge, so we trust
the recorded choice rather than the request scheme.
"""
+from pathlib import Path
+
import config as cfg
+import pytest
+
+
+PANEL_NGINX_CONFIGS = [
+ Path(__file__).resolve().parents[2] / 'nginx' / 'nginx.conf',
+ Path(__file__).resolve().parents[2]
+ / 'nginx'
+ / 'sites-available'
+ / 'serverkit.conf',
+]
def _make_app(hsts_enabled, debug):
@@ -44,6 +56,27 @@ def test_hsts_absent_in_debug_even_if_secure():
assert 'Strict-Transport-Security' not in r.headers
[email protected]('debug', [False, True])
+def test_csp_allows_only_github_as_an_external_form_target(debug):
+ r = _make_app(hsts_enabled=False, debug=debug).test_client().get('/ping')
+ csp = r.headers['Content-Security-Policy']
+ form_action = next(
+ directive.strip()
+ for directive in csp.split(';')
+ if directive.strip().startswith('form-action ')
+ )
+
+ assert form_action == "form-action 'self' https://github.com"
+
+
[email protected]('config_path', PANEL_NGINX_CONFIGS)
+def test_panel_nginx_csp_allows_github_manifest_submission(config_path):
+ config = config_path.read_text()
+
+ assert "form-action 'self' https://github.com;" in config
+ assert "form-action 'self';" not in config
+
+
def test_resolve_ssl_mode(monkeypatch):
monkeypatch.setenv('SERVERKIT_SSL_MODE', 'secure')
assert cfg._resolve_ssl_mode() == 'secure'
diff --git a/nginx/nginx.conf b/nginx/nginx.conf
index 1649f208..7b9d80d9 100644
--- a/nginx/nginx.conf
+++ b/nginx/nginx.conf
@@ -111,7 +111,7 @@ http {
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
# Content Security Policy
- add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self' ws: wss:; frame-ancestors 'none'; base-uri 'self'; form-action 'self';" always;
+ add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self' ws: wss:; frame-ancestors 'none'; base-uri 'self'; form-action 'self' https://github.com;" always;
# Connection limits
limit_conn conn_limit 20;
diff --git a/nginx/sites-available/serverkit.conf b/nginx/sites-available/serverkit.conf
index 3004bbf7..b09887fd 100644
--- a/nginx/sites-available/serverkit.conf
+++ b/nginx/sites-available/serverkit.conf
@@ -105,7 +105,7 @@ server {
# Content Security Policy
# Note: 'unsafe-inline'/'unsafe-eval' are kept because many SPAs need them.
# Once your build is verified to work without inline scripts, remove them.
- add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self' ws: wss:; frame-ancestors 'none'; base-uri 'self'; form-action 'self';" always;
+ add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self' ws: wss:; frame-ancestors 'none'; base-uri 'self'; form-action 'self' https://github.com;" always;
# ═══════════════════════════════════════════════════════════════════════════
# ServerKit frontend — served directly by host nginx from the built SPA