Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 4 additions & 5 deletions src/map_server/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import base64
import hashlib
import ipaddress
import json
import os
Expand Down Expand Up @@ -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]] = {}
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Loading