diff --git a/docs/configuration.md b/docs/configuration.md index a1cf54f..52d02e2 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -161,3 +161,5 @@ Set MCSManager `panel_version` to `9.x` or `10.x` so MAP can choose the correct Prefer `deploy/configure_panels.py` for systemd. It reads keys with hidden input and writes the panel array in base64 form to `/etc/realmsnetwork-map/map.env`. The file should remain root-owned, group-readable by the MAP account, and mode `0640`. Base64 is encoding, not encryption. Filesystem permissions still matter. The helper preserves the server name and request/response/file-size limits and prompts for each provider's authentication type. Never put secrets in command-line arguments, committed JSON, screenshots, bug reports, or prompts. + +MAP's OAuth and AMP session caches are process-local and keyed only by non-secret panel identity fields. **Restart the MAP service after rotating an OAuth client secret, AMP password, or TOTP configuration** so cached tokens and sessions are discarded. diff --git a/src/map_server/client.py b/src/map_server/client.py index c9be0cf..070f3f3 100644 --- a/src/map_server/client.py +++ b/src/map_server/client.py @@ -2,7 +2,6 @@ from __future__ import annotations import base64 -import hashlib import ipaddress import json import os @@ -102,6 +101,8 @@ def _safe_json(value: Any) -> Any: +# These caches are memory-only and are cleared when MAP restarts. Cache keys deliberately +# contain panel identity fields only, never passwords, client secrets, or derived fingerprints. _OAUTH_CACHE: dict[str, tuple[str, float]] = {} _OAUTH_LOCK = threading.Lock() _AMP_SESSION_CACHE: dict[str, tuple[str, float]] = {} @@ -123,8 +124,7 @@ def _oauth_access_token(panel: dict[str, Any]) -> str: cache_key = "|".join(( panel_id, str(panel.get("base_url", "")), - str(panel.get("oauth_client_id", "")), - hashlib.sha256(str(panel.get("oauth_client_secret", "")).encode("utf-8")).hexdigest(), + str(client_id), str(panel.get("oauth_token_path", "/oauth2/token")), )) now = time.monotonic() @@ -197,8 +197,7 @@ def _amp_session(panel: dict[str, Any]) -> str: password = str(panel.get("auth_password", "")) if not username or not password: raise RuntimeError(f"AMP panel '{panel_id}' requires auth_username and auth_password.") - password_fingerprint = hashlib.sha256(password.encode("utf-8")).hexdigest() - cache_key = "|".join((panel_id, base_url, username, password_fingerprint)) + cache_key = "|".join((panel_id, base_url, username)) now = time.monotonic() cached = _AMP_SESSION_CACHE.get(cache_key) if cached and cached[1] > now + 30: diff --git a/tests/test_safety.py b/tests/test_safety.py index 0f916a9..a783e3f 100644 --- a/tests/test_safety.py +++ b/tests/test_safety.py @@ -444,6 +444,8 @@ def fake_request(method, url, **kwargs): assert api_calls[0][1] == "https://puffer.example.test/api/servers" assert api_calls[0][2]["headers"]["Authorization"] == "Bearer cached-access-token" assert "oauth-client-secret" not in json.dumps(server.list_panels()) + assert all("oauth-client-secret" not in key for key in client._OAUTH_CACHE) + assert all("oauth-client-secret" not in value[0] for value in client._OAUTH_CACHE.values()) def test_pterodactyl_style_tools_reject_unrelated_panel_types(monkeypatch): @@ -587,6 +589,8 @@ def fake_request(method, url, **kwargs): assert first["data"]["SESSIONID"] == "[REDACTED]" assert "amp-session-secret" not in json.dumps(first) assert "hidden-amp-password" not in json.dumps(server.list_panels()) + assert all("hidden-amp-password" not in key for key in client._AMP_SESSION_CACHE) + assert all("hidden-amp-password" not in value[0] for value in client._AMP_SESSION_CACHE.values()) def test_amp_native_api_requires_post_and_json_object(monkeypatch):