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(recovery): restore per-app route authz gating (plan 29)

Juan Denisd9b04077d454
diff --git a/backend/app/api/app_volumes.py b/backend/app/api/app_volumes.py
index 3ee7d2cd..32b79de4 100644
--- a/backend/app/api/app_volumes.py
+++ b/backend/app/api/app_volumes.py
@@ -1,3 +1,5 @@
+# Bucket: PER-APP (plan 29 #9). Volume routes gate on the shared app-access seam
+# (can_access_app for reads, can_edit_app for attach/detach mutations).
"""Per-app managed volume API — attach/list/detach first-class persistent
volumes for an application. Mounted under ``/api/v1/apps`` alongside the main
apps blueprint (routes are ``/<app_id>/volumes*``).
diff --git a/backend/app/api/apps.py b/backend/app/api/apps.py
index 5e6a6967..f928edc1 100644
--- a/backend/app/api/apps.py
+++ b/backend/app/api/apps.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP (plan 29 #9). Per-app routes gate on the shared app-access
+# seam via the file-local _can_access_app (reads) / _can_edit_app (writes)
+# helpers, or the hand-rolled owner-or-admin idiom; host/system ops stay admin.
import os
import json
import re
@@ -1463,9 +1466,12 @@ def apply_image_update(app_id):
@apps_bp.route('/<int:app_id>/sleep-policy', methods=['GET'])
@jwt_required()
def get_sleep_policy(app_id):
+ user = User.query.get(get_jwt_identity())
app = Application.query.get(app_id)
if not app:
return jsonify({'error': 'Application not found'}), 404
+ if not _can_access_app(user, app):
+ return jsonify({'error': 'Access denied'}), 403
return jsonify(ContainerSleepService.get_or_create_policy(app_id).to_dict())
@@ -1720,9 +1726,12 @@ def purge_micro_cache(app_id):
@apps_bp.route('/<int:app_id>/scale-policy', methods=['GET'])
@jwt_required()
def get_scale_policy(app_id):
+ user = User.query.get(get_jwt_identity())
app = Application.query.get(app_id)
if not app:
return jsonify({'error': 'Application not found'}), 404
+ if not _can_access_app(user, app):
+ return jsonify({'error': 'Access denied'}), 403
return jsonify(ContainerScaleService.get_or_create_policy(app_id).to_dict())
diff --git a/backend/app/api/container_status.py b/backend/app/api/container_status.py
index 789eb6ba..b30684c0 100644
--- a/backend/app/api/container_status.py
+++ b/backend/app/api/container_status.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP read (plan 29 #9). The single-app status read gates on app
+# visibility via require_app_member (viewer+); the all-apps roll-up is a
+# panel-wide authed read.
"""REST surface for the centralized container status aggregator.
Mounted at /api/v1/status (registered in app/__init__.py).
@@ -6,13 +9,14 @@ Mounted at /api/v1/status (registered in app/__init__.py).
from flask import Blueprint, jsonify
from flask_jwt_extended import jwt_required
+from app.middleware.rbac import require_app_member
from app.services import container_status_service as css
container_status_bp = Blueprint('container_status', __name__)
@container_status_bp.route('/app/<int:app_id>', methods=['GET'])
-@jwt_required()
+@require_app_member()
def app_status(app_id):
"""Aggregated container status for a single application."""
return jsonify(css.get_app_status(app_id))
diff --git a/backend/app/api/databases.py b/backend/app/api/databases.py
index dd7112ed..4cc82f9b 100644
--- a/backend/app/api/databases.py
+++ b/backend/app/api/databases.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP (plan 29 #9). The per-app docker DB read (/docker/app/<app_id>)
+# gates on can_access_app; the bare-container docker routes have no app linkage
+# and are system-level admin-only, matching their kill/drop siblings.
import logging
from flask import Blueprint, request, jsonify
@@ -627,6 +630,7 @@ def get_sqlite_tables():
@databases_bp.route('/docker', methods=['GET'])
@jwt_required()
+@admin_required
def list_docker_databases():
"""List all databases running in Docker containers.
@@ -709,6 +713,7 @@ def get_app_databases(app_id):
@databases_bp.route('/docker/<container>/databases', methods=['GET'])
@jwt_required()
+@admin_required
def list_docker_container_databases(container):
"""List databases in a Docker MySQL container."""
user = request.args.get('user', 'root')
@@ -720,6 +725,7 @@ def list_docker_container_databases(container):
@databases_bp.route('/docker/<container>/<database>/tables', methods=['GET'])
@jwt_required()
+@admin_required
def get_docker_database_tables(container, database):
"""Get tables in a Docker MySQL database."""
user = request.args.get('user', 'root')
@@ -735,6 +741,7 @@ def get_docker_database_tables(container, database):
@databases_bp.route('/docker/<container>/<database>/query', methods=['POST'])
@jwt_required()
+@admin_required
def execute_docker_query(container, database):
"""Execute a query on a Docker MySQL database.
@@ -957,6 +964,7 @@ def kill_host_db_process(engine, pid):
@databases_bp.route('/docker/<container>/processes', methods=['GET'])
@jwt_required()
+@admin_required
def list_docker_db_processes(container):
"""List live server processes inside a Docker database container."""
target = {
diff --git a/backend/app/api/deploy.py b/backend/app/api/deploy.py
index 7d541adb..0b4c56b0 100644
--- a/backend/app/api/deploy.py
+++ b/backend/app/api/deploy.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP (plan 29 #9). Deploy config reads/writes gate on the shared
+# app-access seam (can_access_app / can_edit_app); the public inbound webhook is
+# token/signature-verified (ALLOWLISTed — no per-app user session).
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.middleware.rbac import admin_required
diff --git a/backend/app/api/domains.py b/backend/app/api/domains.py
index 1ceec8e9..a6469e79 100644
--- a/backend/app/api/domains.py
+++ b/backend/app/api/domains.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP (plan 29 #9). Per-app domain routes gate on the shared
+# app-access seam (can_access_app for reads, can_edit_app for mutations);
+# host-level DNS/nginx surfaces stay admin-only.
import re
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
diff --git a/backend/app/api/env_vars.py b/backend/app/api/env_vars.py
index eefff5d3..c39c7362 100644
--- a/backend/app/api/env_vars.py
+++ b/backend/app/api/env_vars.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP (plan 29 #9). Env-var routes converge on the app-access seam:
+# reads use can_access_app (owner/admin/any grant — a viewer grant can read,
+# with secrets still masked), writes use can_edit_app (owner/admin/editor grant).
"""
Environment Variables API
@@ -9,19 +12,27 @@ from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.models import Application, User
from app.services.env_service import EnvService
+from app.services.resource_grant_service import ResourceGrantService
env_vars_bp = Blueprint('env_vars', __name__)
-def check_app_access(app_id, user_id):
- """Check if user has access to the application."""
+def check_app_access(app_id, user_id, write=False):
+ """Check that the user may access the application's env vars (plan 29 #9).
+
+ Reads (``write=False``) require can_access_app (owner/admin/any grant);
+ writes require can_edit_app (owner/admin/editor grant — a viewer grant is
+ read-only). Returns ``(user, app, None, None)`` on success or
+ ``(None, None, error_response, status)`` on failure."""
user = User.query.get(user_id)
app = Application.query.get(app_id)
if not app:
return None, None, jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != user_id:
+ ok = (ResourceGrantService.can_edit_app(user, app) if write
+ else ResourceGrantService.can_access_app(user, app))
+ if not ok:
return None, None, jsonify({'error': 'Access denied'}), 403
return user, app, None, None
@@ -52,7 +63,7 @@ def get_env_vars(app_id):
def create_env_var(app_id):
"""Create a new environment variable."""
current_user_id = get_jwt_identity()
- user, app, error, status = check_app_access(app_id, current_user_id)
+ user, app, error, status = check_app_access(app_id, current_user_id, write=True)
if error:
return error, status
@@ -108,7 +119,7 @@ def get_env_var(app_id, key):
def update_env_var(app_id, key):
"""Update an existing environment variable."""
current_user_id = get_jwt_identity()
- user, app, error, status = check_app_access(app_id, current_user_id)
+ user, app, error, status = check_app_access(app_id, current_user_id, write=True)
if error:
return error, status
@@ -158,7 +169,7 @@ def update_env_var(app_id, key):
def delete_env_var(app_id, key):
"""Delete an environment variable."""
current_user_id = get_jwt_identity()
- user, app, error, status = check_app_access(app_id, current_user_id)
+ user, app, error, status = check_app_access(app_id, current_user_id, write=True)
if error:
return error, status
@@ -178,7 +189,7 @@ def delete_env_var(app_id, key):
def bulk_set_env_vars(app_id):
"""Set multiple environment variables at once."""
current_user_id = get_jwt_identity()
- user, app, error, status = check_app_access(app_id, current_user_id)
+ user, app, error, status = check_app_access(app_id, current_user_id, write=True)
if error:
return error, status
@@ -202,7 +213,7 @@ def bulk_set_env_vars(app_id):
def import_env_file(app_id):
"""Import environment variables from .env file content."""
current_user_id = get_jwt_identity()
- user, app, error, status = check_app_access(app_id, current_user_id)
+ user, app, error, status = check_app_access(app_id, current_user_id, write=True)
if error:
return error, status
@@ -280,7 +291,7 @@ def get_env_history(app_id):
def clear_all_env_vars(app_id):
"""Delete all environment variables for an application."""
current_user_id = get_jwt_identity()
- user, app, error, status = check_app_access(app_id, current_user_id)
+ user, app, error, status = check_app_access(app_id, current_user_id, write=True)
if error:
return error, status
diff --git a/backend/app/api/git.py b/backend/app/api/git.py
index 87dbbaaf..1a3bd151 100644
--- a/backend/app/api/git.py
+++ b/backend/app/api/git.py
@@ -1,8 +1,16 @@
+# Bucket: PER-APP (plan 29 #9, #11). The per-app deployment read gates on app
+# visibility (require_app_member); webhook reads are scoped to the linked app's
+# visibility (an unlinked webhook stays panel-wide viewer-visible). Webhook
+# mutations and the Gitea host lifecycle stay admin-only.
"""Git Server API endpoints for managing integrated Gitea instance and webhooks."""
from flask import Blueprint, request, jsonify
-from ..middleware.rbac import admin_required, viewer_required
+from ..middleware.rbac import (
+ admin_required, viewer_required, require_app_member,
+ get_current_user, app_access_tier,
+)
+from ..models import Application, GitWebhook
from ..services.git_service import GitService
from ..services.webhook_service import WebhookService
from ..services.gitea_api_service import GiteaAPIService
@@ -11,6 +19,18 @@ from ..services.git_deploy_service import GitDeployService
git_bp = Blueprint('git', __name__)
+def _webhook_visible_to(user, webhook):
+ """A webhook with no app linkage is a panel-wide viewer-visible resource; an
+ app-linked webhook is visible only to callers who can reach that app
+ (owner/admin/grant/workspace member — plan 29 #11)."""
+ if not getattr(webhook, 'app_id', None):
+ return True
+ app = Application.query.get(webhook.app_id)
+ if app is None:
+ return True
+ return app_access_tier(user, app) is not None
+
+
@git_bp.route('/status', methods=['GET'])
@viewer_required
def get_status():
@@ -97,8 +117,19 @@ def restart():
@git_bp.route('/webhooks', methods=['GET'])
@viewer_required
def list_webhooks():
- """List all configured webhooks."""
+ """List webhooks the caller can see (plan 29 #11): every unlinked webhook
+ plus any app-linked webhook whose app they can reach."""
+ user = get_current_user()
result = WebhookService.list_webhooks()
+ webhooks = result.get('webhooks', [])
+ visible = []
+ for w in webhooks:
+ wh = GitWebhook.query.get(w.get('id'))
+ if wh is None or _webhook_visible_to(user, wh):
+ visible.append(w)
+ result['webhooks'] = visible
+ if 'count' in result:
+ result['count'] = len(visible)
return jsonify(result), 200
@@ -131,7 +162,12 @@ def create_webhook():
@git_bp.route('/webhooks/<int:webhook_id>', methods=['GET'])
@viewer_required
def get_webhook(webhook_id):
- """Get a specific webhook."""
+ """Get a specific webhook (scoped to the linked app's visibility, #11)."""
+ user = get_current_user()
+ wh = GitWebhook.query.get(webhook_id)
+ if wh is None or not _webhook_visible_to(user, wh):
+ return jsonify({'error': 'Not found'}), 404
+
result = WebhookService.get_webhook(webhook_id)
if result.get('success'):
@@ -177,7 +213,11 @@ def toggle_webhook(webhook_id):
@git_bp.route('/webhooks/<int:webhook_id>/logs', methods=['GET'])
@viewer_required
def get_webhook_logs(webhook_id):
- """Get logs for a specific webhook."""
+ """Get logs for a specific webhook (scoped to the linked app's visibility)."""
+ user = get_current_user()
+ wh = GitWebhook.query.get(webhook_id)
+ if wh is None or not _webhook_visible_to(user, wh):
+ return jsonify({'error': 'Not found'}), 404
limit = request.args.get('limit', 50, type=int)
result = WebhookService.get_webhook_logs(webhook_id, limit=limit)
return jsonify(result), 200
@@ -393,7 +433,7 @@ def get_gitea_version():
# ==================== DEPLOYMENT ENDPOINTS ====================
@git_bp.route('/deployments/app/<int:app_id>', methods=['GET'])
-@viewer_required
+@require_app_member()
def get_app_deployments(app_id):
"""Get deployment history for an application."""
limit = request.args.get('limit', 20, type=int)
diff --git a/backend/app/api/private_urls.py b/backend/app/api/private_urls.py
index fd1e32a4..7aab6a6a 100644
--- a/backend/app/api/private_urls.py
+++ b/backend/app/api/private_urls.py
@@ -1,3 +1,5 @@
+# Bucket: PER-APP (plan 29 #9). Private-URL routes gate on the shared app-access
+# seam (can_access_app for reads, can_edit_app for mutations).
"""API endpoints for managing private URLs for applications."""
from flask import Blueprint, request, jsonify
diff --git a/backend/app/api/python.py b/backend/app/api/python.py
index 7cc2015d..b33c3f3c 100644
--- a/backend/app/api/python.py
+++ b/backend/app/api/python.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP (plan 29 #9). Per-app Python runtime routes gate on the shared
+# app-access seam (can_access_app for reads, can_edit_app for mutations);
+# host-level interpreter management stays admin-only.
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.middleware.rbac import admin_required
diff --git a/backend/app/api/security.py b/backend/app/api/security.py
index 18116b5a..4159b7c2 100644
--- a/backend/app/api/security.py
+++ b/backend/app/api/security.py
@@ -1,3 +1,5 @@
+# Bucket: PER-APP (plan 29 #9). Per-app scan/security routes gate on the shared
+# app-access seam; host-level firewall/fail2ban/malware surfaces stay admin-only.
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required
from app.middleware.rbac import admin_required
diff --git a/backend/app/api/snapshots.py b/backend/app/api/snapshots.py
index af1c0811..a4ac4b46 100644
--- a/backend/app/api/snapshots.py
+++ b/backend/app/api/snapshots.py
@@ -1,3 +1,6 @@
+# Bucket: PER-APP (plan 29 #9). Snapshot reads (list/get/diff) require app
+# access (can_access_app); restore requires write access (can_edit_app) on top
+# of the panel-wide @developer_required.
"""
Deployment config snapshot API.
@@ -14,15 +17,23 @@ from app.middleware.rbac import developer_required, get_current_user
from app.models.application import Application
from app.models.deployment_snapshot import DeploymentSnapshot
from app.services.configuration_service import ConfigurationService
+from app.services.resource_grant_service import ResourceGrantService
snapshots_bp = Blueprint('snapshots', __name__)
-def _get_app_or_404(app_id):
- """Return (app, None) or (None, error_response)."""
+def _get_app_or_404(app_id, write=False):
+ """Resolve the app and enforce per-app access (plan 29 #9). ``write`` requires
+ can_edit_app (owner/admin/editor); otherwise can_access_app. A caller without
+ the needed tier gets a 403 (the resource itself exists)."""
app = Application.query.get(app_id)
if not app:
return None, (jsonify({'error': 'Application not found'}), 404)
+ user = get_current_user()
+ ok = (ResourceGrantService.can_edit_app(user, app) if write
+ else ResourceGrantService.can_access_app(user, app))
+ if not ok:
+ return None, (jsonify({'error': 'Access denied'}), 403)
return app, None
@@ -134,7 +145,7 @@ def diff_snapshot(app_id, snap_id):
@developer_required
def restore_snapshot(app_id, snap_id):
"""Restore a snapshot's config (env/domains) and trigger a redeploy."""
- _, err = _get_app_or_404(app_id)
+ _, err = _get_app_or_404(app_id, write=True)
if err:
return err
snap, err = _get_snapshot_or_404(app_id, snap_id)
diff --git a/backend/app/api/status_pages.py b/backend/app/api/status_pages.py
index 058fc0e0..1c3042e8 100644
--- a/backend/app/api/status_pages.py
+++ b/backend/app/api/status_pages.py
@@ -139,6 +139,9 @@ def delete_component(comp_id):
@status_pages_bp.route('/components/<int:comp_id>/check', methods=['POST'])
@jwt_required()
def run_check(comp_id):
+ user = get_current_user()
+ if not user or not user.is_admin:
+ return jsonify({'error': 'Admin access required'}), 403
hc = StatusPageService.run_check(comp_id)
if not hc:
return jsonify({'error': 'Component not found'}), 404
diff --git a/backend/app/api/templates.py b/backend/app/api/templates.py
index fafebf00..44c62ce4 100644
--- a/backend/app/api/templates.py
+++ b/backend/app/api/templates.py
@@ -1,3 +1,5 @@
+# Bucket: PER-APP (plan 29 #9). The per-app template routes gate on the shared
+# app-access seam; catalog browsing/installation stays panel-authed.
"""
Template API Endpoints
diff --git a/builtin-extensions/serverkit-wordpress/backend/wordpress.py b/builtin-extensions/serverkit-wordpress/backend/wordpress.py
index f1dd2e4f..70156b31 100644
--- a/builtin-extensions/serverkit-wordpress/backend/wordpress.py
+++ b/builtin-extensions/serverkit-wordpress/backend/wordpress.py
@@ -1,8 +1,16 @@
+# Bucket: PER-APP (plan 29 #9). Per-site WordPress routes gate on the linked
+# application's access seam: reads use can_access_app (owner/admin/any grant),
+# writes use can_edit_app (owner/admin/editor grant). The P0 <site_id> lifecycle
+# mutations and the previously-open <site_id>/<app_id> reads seal from open —
+# denial (or a missing resource) is an indistinguishable 404 (Decision 5). Host/
+# system ops (standalone install/uninstall/start/stop/restart, legacy install,
+# wp-cli, plugin library) stay @admin_required.
import json
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
-from app.middleware.rbac import admin_required
+from app.middleware.rbac import admin_required, get_current_user
from app.models import User, Application, WordPressSite
+from app.services.resource_grant_service import ResourceGrantService
from .wordpress_service import WordPressService
from app import db
@@ -29,6 +37,40 @@ def _is_wp_app(app):
return WordPressSite.query.filter_by(application_id=app.id).first() is not None
+def _guard_app(site_or_app_id, write=False):
+ """Resolve a per-site WordPress route to its Application and enforce access,
+ returning ``(app, None)`` or ``(None, error_response)``. Reads use
+ can_access_app (owner/admin/any grant); writes use can_edit_app (owner/admin/
+ editor grant). Denial is a 403 — used by the convergence reads that keep
+ their status. A missing/non-WP resource is a 404."""
+ app = _resolve_app(site_or_app_id)
+ if not _is_wp_app(app):
+ return None, (jsonify({'error': 'Application not found'}), 404)
+ user = get_current_user()
+ ok = (ResourceGrantService.can_edit_app(user, app) if write
+ else ResourceGrantService.can_access_app(user, app))
+ if not ok:
+ return None, (jsonify({'error': 'Access denied'}), 403)
+ return app, None
+
+
+def _guard_sealed_app(site_or_app_id, write=False):
+ """Like :func:`_guard_app` but sealed-from-open (Decision 5): a missing
+ resource OR an unauthorized caller both return an indistinguishable
+ ``404 {'error': 'Not found'}`` so a foreign caller cannot probe existence.
+ Used by the P0 <site_id> lifecycle mutations and the previously-open
+ <site_id>/<app_id> reads."""
+ app = _resolve_app(site_or_app_id)
+ if not _is_wp_app(app):
+ return None, (jsonify({'error': 'Not found'}), 404)
+ user = get_current_user()
+ ok = (ResourceGrantService.can_edit_app(user, app) if write
+ else ResourceGrantService.can_access_app(user, app))
+ if not ok:
+ return None, (jsonify({'error': 'Not found'}), 404)
+ return app, None
+
+
# ==================== WORDPRESS SITES HUB ENDPOINTS ====================
@wordpress_bp.route('/sites', methods=['GET'])
@@ -141,6 +183,9 @@ def import_site():
@jwt_required()
def get_site(site_id):
"""Get site detail with environments."""
+ _, err = _guard_sealed_app(site_id)
+ if err:
+ return err
result = WordPressService.get_site(site_id)
if 'error' in result:
return jsonify(result), 404
@@ -151,6 +196,9 @@ def get_site(site_id):
@jwt_required()
def clone_site(site_id):
"""Clone a site into a new INDEPENDENT top-level site with fresh admin creds."""
+ _, err = _guard_sealed_app(site_id, write=True)
+ if err:
+ return err
data = request.get_json() or {}
new_name = data.get('name')
if not new_name:
@@ -167,6 +215,9 @@ def clone_site(site_id):
@jwt_required()
def set_site_tags(site_id):
"""Replace the tag list for a WordPress site."""
+ _, err = _guard_sealed_app(site_id, write=True)
+ if err:
+ return err
data = request.get_json() or {}
tags = data.get('tags')
if tags is None or not isinstance(tags, list):
@@ -197,6 +248,9 @@ def set_site_tags(site_id):
@jwt_required()
def delete_site(site_id):
"""Delete site and all its environments (takes a final backup by default)."""
+ _, err = _guard_sealed_app(site_id, write=True)
+ if err:
+ return err
# Back up before delete unless explicitly opted out via ?create_backup=false
create_backup = request.args.get('create_backup', 'true').lower() != 'false'
result = WordPressService.delete_site(site_id, create_backup=create_backup)
@@ -209,6 +263,9 @@ def delete_site(site_id):
@jwt_required()
def archive_site(site_id):
"""Archive a site: stop the stack but keep all data. Reversible."""
+ _, err = _guard_sealed_app(site_id, write=True)
+ if err:
+ return err
result = WordPressService.archive_site(site_id)
if result.get('success'):
return jsonify(result), 200
@@ -219,6 +276,9 @@ def archive_site(site_id):
@jwt_required()
def unarchive_site(site_id):
"""Restore a previously archived site."""
+ _, err = _guard_sealed_app(site_id, write=True)
+ if err:
+ return err
result = WordPressService.unarchive_site(site_id)
if result.get('success'):
return jsonify(result), 200
@@ -229,6 +289,9 @@ def unarchive_site(site_id):
@jwt_required()
def list_environments(site_id):
"""List environments for a site."""
+ _, err = _guard_sealed_app(site_id)
+ if err:
+ return err
result = WordPressService.get_environments(site_id)
if 'error' in result:
return jsonify(result), 404
@@ -239,6 +302,9 @@ def list_environments(site_id):
@jwt_required()
def create_environment(site_id):
"""Create a staging or development environment."""
+ _, err = _guard_sealed_app(site_id, write=True)
+ if err:
+ return err
data = request.get_json() or {}
env_type = data.get('type', '')
@@ -257,6 +323,9 @@ def create_environment(site_id):
@jwt_required()
def delete_environment(site_id, env_id):
"""Delete a non-production environment."""
+ _, err = _guard_sealed_app(site_id, write=True)
+ if err:
+ return err
result = WordPressService.delete_environment(env_id)
if result.get('success'):
return jsonify(result), 200
@@ -283,6 +352,7 @@ def get_standalone_requirements():
@wordpress_bp.route('/standalone/install', methods=['POST'])
@jwt_required()
+@admin_required
def install_standalone():
"""Install WordPress via Docker Compose."""
data = request.get_json() or {}
@@ -298,6 +368,7 @@ def install_standalone():
@wordpress_bp.route('/standalone/uninstall', methods=['POST'])
@jwt_required()
+@admin_required
def uninstall_standalone():
"""Uninstall standalone WordPress and optionally remove data."""
data = request.get_json() or {}
@@ -313,6 +384,7 @@ def uninstall_standalone():
@wordpress_bp.route('/standalone/start', methods=['POST'])
@jwt_required()
+@admin_required
def start_standalone():
"""Start WordPress containers."""
result = WordPressService.start_wordpress_standalone()
@@ -324,6 +396,7 @@ def start_standalone():
@wordpress_bp.route('/standalone/stop', methods=['POST'])
@jwt_required()
+@admin_required
def stop_standalone():
"""Stop WordPress containers."""
result = WordPressService.stop_wordpress_standalone()
@@ -335,6 +408,7 @@ def stop_standalone():
@wordpress_bp.route('/standalone/restart', methods=['POST'])
@jwt_required()
+@admin_required
def restart_standalone():
"""Restart WordPress containers."""
result = WordPressService.restart_wordpress_standalone()
@@ -391,7 +465,7 @@ def get_php(app_id):
app = _resolve_app(app_id)
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
info = WordPressService.get_php_info(app.root_path)
info['available_versions'] = WordPressService.get_available_php_versions()
@@ -469,7 +543,7 @@ def get_site_status_page(app_id):
app = _resolve_app(app_id)
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
wp_site = WordPressSite.query.filter_by(application_id=app.id).first()
component = None
@@ -555,7 +629,7 @@ def get_site_analytics(app_id):
app = _resolve_app(app_id)
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
result = WpAnalyticsService.get_traffic(app.name, request.args.get('hours', 24))
# PHP fatals/warnings from the WP_DEBUG log (#25 fatals; populated by #30's toggle).
@@ -573,7 +647,7 @@ def get_site_vulnerabilities(app_id):
app = _resolve_app(app_id)
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
wp_site = WordPressSite.query.filter_by(application_id=app.id).first()
if not wp_site:
@@ -872,7 +946,7 @@ def get_wordpress_info(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
if not _is_wp_app(app):
@@ -914,7 +988,7 @@ def get_plugins(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
plugins = WordPressService.get_plugins(app.root_path)
@@ -1013,7 +1087,7 @@ def get_themes(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
themes = WordPressService.get_themes(app.root_path)
@@ -1102,7 +1176,7 @@ def list_backups(app_id):
if not app:
return jsonify({'error': 'Application not found'}), 404
- if user.role != 'admin' and app.user_id != current_user_id:
+ if not ResourceGrantService.can_access_app(user, app):
return jsonify({'error': 'Access denied'}), 403
import os
@@ -1250,9 +1324,9 @@ def optimize_database(app_id):
@jwt_required()
def get_page_cache(app_id):
"""Report full-page cache plugin status for a site."""
- app = _resolve_app(app_id)
- if not app:
- return jsonify({'error': 'Application not found'}), 404
+ app, err = _guard_sealed_app(app_id)
+ if err:
+ return err
return jsonify(WordPressService.get_page_cache_status(app.root_path)), 200
@@ -1298,9 +1372,9 @@ def disable_page_cache(app_id):
@jwt_required()
def object_cache_status(app_id):
"""Report Redis object-cache state for a site."""
- app = _resolve_app(app_id)
- if not app:
- return jsonify({'error': 'Application not found'}), 404
+ app, err = _guard_sealed_app(app_id)
+ if err:
+ return err
return jsonify(WordPressService.object_cache_status(app.root_path)), 200
@@ -1628,6 +1702,9 @@ def scan_site_library_plugins(app_id):
def get_site_managed_plugins(app_id):
"""Which of a site's installed plugins are library-managed (+ update state)."""
from .wordpress_plugin_library_service import WordPressPluginLibraryService
+ _, err = _guard_sealed_app(app_id)
+ if err:
+ return err
site = _resolve_wp_site(app_id)
if not site:
return jsonify({'error': 'Site not found'}), 404