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(logs): keep panel-internal roots out of the log viewer

Juan Denis8837a26af049
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f798b6a..dc70771d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,11 @@ release history; historical `agent-v*` tags are not panel releases.
begins with an allowed root, such as `/opt-private` next to `/opt`, was
treated as though it sat inside that root and could be read, searched and
cleared through the Log Files tab.
+- Keep panel-internal files out of the log viewer entirely. On the standard
+ install layout the panel's own directory sits under the allowed root
+ `/opt`, so the Log Files tab could read — or clear — the backend `.env`
+ and database. The log viewer now shares the file manager's protected-roots
+ exclusion.
## [1.11.4] - 2026-09-12
diff --git a/backend/app/services/log_service.py b/backend/app/services/log_service.py
index 3113ad04..a2a3081e 100644
--- a/backend/app/services/log_service.py
+++ b/backend/app/services/log_service.py
@@ -7,6 +7,7 @@ import threading
import queue
from app import paths
+from app.services.file_service import FileService
from app.utils.formatting import format_bytes
from app.utils.system import (run_privileged, privileged_cmd, is_command_available,
run_checked, sourced_result)
@@ -35,6 +36,16 @@ class LogService:
'/opt',
]
+ # Panel-internal directories that must NEVER be reachable through the log
+ # viewer, even for an admin: the backend .env (JWT_SECRET_KEY, encryption
+ # key, DB creds), the SQLite instance dir and the generated deploy config
+ # all live here. On the documented install.sh layout the install dir sits
+ # under the allowed root /opt, so without this exclusion the viewer could
+ # read — and, through clear_log, truncate — the panel's own secrets.
+ # Shared with FileService (GHSA-rm3m-9mvw-68fh) so the two surfaces
+ # cannot drift apart.
+ PROTECTED_ROOTS = FileService.PROTECTED_ROOTS
+
@classmethod
def is_path_allowed(cls, filepath: str) -> bool:
"""Check if the filepath is within allowed directories."""
@@ -42,6 +53,10 @@ class LogService:
# Resolve the absolute path to prevent traversal attacks
real_path = os.path.realpath(filepath)
+ if any(real_path == root or real_path.startswith(root + os.sep)
+ for root in cls.PROTECTED_ROOTS):
+ return False
+
# Compare whole path segments, the way FileService.is_path_allowed
# does. A bare startswith is a text test, not a containment test:
# '/opt-private' would pass on the strength of the root '/opt'.
diff --git a/backend/tests/test_log_path_containment.py b/backend/tests/test_log_path_containment.py
index 82a856ff..17bdd778 100644
--- a/backend/tests/test_log_path_containment.py
+++ b/backend/tests/test_log_path_containment.py
@@ -20,6 +20,7 @@ import os
import pytest
+from app.services.file_service import FileService
from app.services.log_service import LogService
@@ -79,3 +80,44 @@ def test_paths_inside_the_root_still_pass(roots):
assert LogService.is_path_allowed(os.path.join(roots['allowed'], 'app.log'))
assert LogService.is_path_allowed(
os.path.join(roots['allowed'], 'nested', '..', 'app.log'))
+
+
+# --------------------------------------------------------------------------- #
+# Panel-internal roots are never allowed, even under an allowed root
+# --------------------------------------------------------------------------- #
+def test_protected_roots_are_shared_with_file_service():
+ """One source of truth: LogService must not grow its own copy of the
+ panel-internal list and drift away from FileService's."""
+ assert LogService.PROTECTED_ROOTS is FileService.PROTECTED_ROOTS
+
+
+def test_install_dir_is_rejected_even_when_its_parent_is_allowed(monkeypatch):
+ """On the install.sh layout the install dir sits under the allowed root
+ /opt, so reachability must come from the exclusion, not from the allowed
+ list happening not to contain the parent."""
+ parent = os.path.dirname(FileService._INSTALL_DIR)
+ monkeypatch.setattr(LogService, 'ALLOWED_LOG_DIRECTORIES', [parent])
+
+ assert not LogService.is_path_allowed(FileService._INSTALL_DIR)
+ assert not LogService.is_path_allowed(
+ os.path.join(FileService._INSTALL_DIR, '.env'))
+ assert not LogService.is_path_allowed(
+ os.path.join(FileService._BACKEND_DIR, 'config.py'))
+
+
+def test_clear_log_refuses_a_panel_secret(monkeypatch):
+ """The exclusion also gates truncation, through clear_log.
+
+ The target deliberately does not exist, so if the guard regresses the
+ call falls through to 'Log file not found' instead of running truncate
+ against a real file.
+ """
+ parent = os.path.dirname(FileService._INSTALL_DIR)
+ monkeypatch.setattr(LogService, 'ALLOWED_LOG_DIRECTORIES', [parent])
+ target = os.path.join(
+ FileService._INSTALL_DIR, '.env-not-present-for-this-test')
+
+ result = LogService.clear_log(target)
+
+ assert result['success'] is False
+ assert result['error'] == 'Access denied: path not in allowed directories'