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
fix(git): enforce app-level authorization on deployment read endpoints
Juan Denis783e195304fd
diff --git a/backend/app/api/deploy.py b/backend/app/api/deploy.pyindex 0b4c56b0..05168764 100644--- a/backend/app/api/deploy.py+++ b/backend/app/api/deploy.py@@ -3,7 +3,7 @@# token/signature-verified (ALLOWLISTed — no per-app user session).from flask import Blueprint, request, jsonifyfrom flask_jwt_extended import jwt_required, get_jwt_identity-from app.middleware.rbac import admin_required+from app.middleware.rbac import admin_required, app_access_tierfrom app.models import User, Applicationfrom app.services.git_service import GitServicefrom app.services.resource_grant_service import ResourceGrantService@@ -154,10 +154,22 @@ def get_commit_info(app_id):@deploy_bp.route('/history', methods=['GET'])@jwt_required()def get_deployment_history():- """Get deployment history."""+ """Get deployment history. App-scoped queries require access to that app;+ global queries (no app_id) are restricted to panel admins."""+ current_user_id = get_jwt_identity()+ user = User.query.get(current_user_id)app_id = request.args.get('app_id', type=int)limit = request.args.get('limit', 50, type=int)+ if app_id:+ app = Application.query.get(app_id)+ if not app:+ return jsonify({'error': 'Application not found'}), 404+ if not user or app_access_tier(user, app) is None:+ return jsonify({'error': 'Access denied'}), 403+ elif not user or not user.is_admin:+ return jsonify({'error': 'Access denied'}), 403+history = GitService.get_deployment_history(app_id, limit)return jsonify({'deployments': history}), 200@@ -219,10 +231,22 @@ def get_branches_from_url():@deploy_bp.route('/webhook-logs', methods=['GET'])@jwt_required()def get_webhook_logs():- """Get webhook logs for debugging."""+ """Get webhook logs for debugging. App-scoped queries require access to that+ app; global queries (no app_id) are restricted to panel admins."""+ current_user_id = get_jwt_identity()+ user = User.query.get(current_user_id)app_id = request.args.get('app_id', type=int)limit = request.args.get('limit', 50, type=int)+ if app_id:+ app = Application.query.get(app_id)+ if not app:+ return jsonify({'error': 'Application not found'}), 404+ if not user or app_access_tier(user, app) is None:+ return jsonify({'error': 'Access denied'}), 403+ elif not user or not user.is_admin:+ return jsonify({'error': 'Access denied'}), 403+logs = GitService.get_webhook_logs(app_id, limit)return jsonify({'logs': logs}), 200diff --git a/backend/app/api/git.py b/backend/app/api/git.pyindex 1a3bd151..2e3e2ffc 100644--- a/backend/app/api/git.py+++ b/backend/app/api/git.py@@ -445,6 +445,16 @@ def get_app_deployments(app_id):@viewer_requireddef get_deployment(deployment_id):"""Get a specific deployment with logs."""+ from app.models import GitDeployment++ deployment = GitDeployment.query.get(deployment_id)+ if deployment is None:+ return jsonify({'success': False, 'error': 'Deployment not found'}), 404++ app = Application.query.get(deployment.app_id)+ if app is None or app_access_tier(get_current_user(), app) is None:+ return jsonify({'success': False, 'error': 'Access denied'}), 403+include_logs = request.args.get('logs', 'false').lower() == 'true'result = GitDeployService.get_deployment(deployment_id, include_logs=include_logs)@@ -487,6 +497,12 @@ def get_webhook_deployments(webhook_id):"""Get deployments triggered by a specific webhook."""from app.models import GitDeployment+ webhook = GitWebhook.query.get(webhook_id)+ if webhook is None:+ return jsonify({'success': False, 'error': 'Webhook not found'}), 404+ if not _webhook_visible_to(get_current_user(), webhook):+ return jsonify({'success': False, 'error': 'Access denied'}), 403+limit = request.args.get('limit', 20, type=int)deployments = GitDeployment.query.filter_by(webhook_id=webhook_id)\.order_by(GitDeployment.created_at.desc())\diff --git a/backend/tests/BASELINE_COUNT b/backend/tests/BASELINE_COUNTindex 2c7a84e8..d3cf57bc 100644--- a/backend/tests/BASELINE_COUNT+++ b/backend/tests/BASELINE_COUNT@@ -1 +1 @@-2534+3146diff --git a/backend/tests/test_git_deployment_authz.py b/backend/tests/test_git_deployment_authz.pynew file mode 100644index 00000000..df12dc6d--- /dev/null+++ b/backend/tests/test_git_deployment_authz.py@@ -0,0 +1,111 @@+"""GHSA-6w78-q5vm-rfmh — git deployment read endpoints must enforce app-level+authorization, not just authentication.++- GET /api/v1/git/deployments/<id> (deployment logs may contain secrets)+- GET /api/v1/git/deployments/webhook/<id> (deployment metadata across tenants)+- GET /api/v1/deploy/history (global leak when app_id omitted)+- GET /api/v1/deploy/webhook-logs (global leak when app_id omitted)++A caller with no path to the linked application gets 403/404; app-scoped+queries stay open to anyone who can reach the app; global (no app_id) history+queries are restricted to panel admins.+"""+import pytest+++def deployment_rbac(app, scoping_rbac):+ """One app-linked webhook + one deployment on scoping_rbac's app, plus one+ unlinked webhook."""+ from types import SimpleNamespace+ from app import db+ from app.models import GitDeployment, GitWebhook++ linked = GitWebhook(+ name='dep-linked', source='github',+ source_repo_url='https://example.com/r.git',+ secret='s', webhook_token='tok-dep-linked',+ app_id=scoping_rbac.app_id,+ )+ unlinked = GitWebhook(+ name='dep-unlinked', source='github',+ source_repo_url='https://example.com/r2.git',+ secret='s', webhook_token='tok-dep-unlinked',+ app_id=None,+ )+ db.session.add_all([linked, unlinked])+ db.session.commit()++ deployment = GitDeployment(+ app_id=scoping_rbac.app_id, webhook_id=linked.id,+ version=1, commit_sha='abc123', status='success',+ deploy_output='DB_PASSWORD=hunter2',+ )+ db.session.add(deployment)+ db.session.commit()++ return SimpleNamespace(+ linked_id=linked.id, unlinked_id=unlinked.id,+ deployment_id=deployment.id, s=scoping_rbac,+ )+++def test_deployment_detail_requires_app_access(client, deployment_rbac):+ """Anyone who can reach the app reads the deployment (incl. logs); a+ foreign caller is denied before any log bytes are returned."""+ s = deployment_rbac.s+ url = f'/api/v1/git/deployments/{deployment_rbac.deployment_id}?logs=true'+ for persona in ('owner', 'member', 'viewer', 'admin'):+ assert client.get(url, headers=getattr(s, persona)).status_code == 200, persona+ assert client.get(url, headers=s.foreign).status_code == 403+++def test_deployment_detail_missing_404(client, deployment_rbac):+ assert client.get('/api/v1/git/deployments/999999',+ headers=deployment_rbac.s.admin).status_code == 404+++def test_webhook_deployments_scoped_to_app_visibility(client, deployment_rbac):+ s = deployment_rbac.s+ url = f'/api/v1/git/deployments/webhook/{deployment_rbac.linked_id}'+ assert client.get(url, headers=s.member).status_code == 200+ assert client.get(url, headers=s.foreign).status_code == 403+++def test_webhook_deployments_unlinked_stays_visible(client, deployment_rbac):+ """Unlinked webhooks remain panel-wide viewer-visible (plan 29 #11)."""+ url = f'/api/v1/git/deployments/webhook/{deployment_rbac.unlinked_id}'+ assert client.get(url, headers=deployment_rbac.s.foreign).status_code == 200+++def test_webhook_deployments_missing_404(client, deployment_rbac):+ assert client.get('/api/v1/git/deployments/webhook/999999',+ headers=deployment_rbac.s.admin).status_code == 404+++def test_deploy_history_app_scoped_requires_access(client, deployment_rbac):+ s = deployment_rbac.s+ url = f'/api/v1/deploy/history?app_id={s.app_id}'+ assert client.get(url, headers=s.member).status_code == 200+ assert client.get(url, headers=s.foreign).status_code == 403+++def test_deploy_history_global_admin_only(client, deployment_rbac):+ s = deployment_rbac.s+ assert client.get('/api/v1/deploy/history', headers=s.admin).status_code == 200+ for persona in ('owner', 'member', 'viewer', 'foreign'):+ assert client.get('/api/v1/deploy/history',+ headers=getattr(s, persona)).status_code == 403, persona+++def test_webhook_logs_app_scoped_requires_access(client, deployment_rbac):+ s = deployment_rbac.s+ url = f'/api/v1/deploy/webhook-logs?app_id={s.app_id}'+ assert client.get(url, headers=s.member).status_code == 200+ assert client.get(url, headers=s.foreign).status_code == 403+++def test_webhook_logs_global_admin_only(client, deployment_rbac):+ s = deployment_rbac.s+ assert client.get('/api/v1/deploy/webhook-logs', headers=s.admin).status_code == 200+ assert client.get('/api/v1/deploy/webhook-logs', headers=s.foreign).status_code == 403