Skip to content

Commit 2a65371

Browse files
committed
fix: only return config parse error to authenticated users
The raw PyYAML parser error embeds the config file path and line context. The /config endpoint is unauthenticated, so gate CONFIG_FILE_PARSE_ERROR behind auth like EJS_NETPLAY_ICE_SERVERS, returning None to anonymous callers. Generated-By: PostHog Code Task-Id: 3d4f28a8-5157-4ca4-97a6-f283f5d6329e
1 parent 8e74790 commit 2a65371

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

backend/endpoints/configs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def get_config(request: Request) -> ConfigResponse:
4242
return ConfigResponse(
4343
CONFIG_FILE_MOUNTED=cfg.CONFIG_FILE_MOUNTED,
4444
CONFIG_FILE_WRITABLE=cfg.CONFIG_FILE_WRITABLE,
45-
CONFIG_FILE_PARSE_ERROR=cfg.CONFIG_FILE_PARSE_ERROR,
45+
# Raw parser error may leak the config file path, so only send when authenticated
46+
CONFIG_FILE_PARSE_ERROR=(
47+
cfg.CONFIG_FILE_PARSE_ERROR if request.user.is_authenticated else None
48+
),
4649
EXCLUDED_PLATFORMS=cfg.EXCLUDED_PLATFORMS,
4750
EXCLUDED_SINGLE_EXT=cfg.EXCLUDED_SINGLE_EXT,
4851
EXCLUDED_SINGLE_FILES=cfg.EXCLUDED_SINGLE_FILES,

backend/tests/endpoints/test_config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ def test_config(client):
3131
assert config.get("GAMELIST_MEDIA_IMAGE") == "screenshot"
3232

3333

34+
def test_config_parse_error_gated_by_auth(client, access_token: str):
35+
# The raw parser error can leak the config file path, so it is only
36+
# returned to authenticated users.
37+
cfg = cm.get_config()
38+
cfg.CONFIG_FILE_PARSE_ERROR = 'in "/data/config.yml", line 2'
39+
40+
with patch.object(cm, "get_config", return_value=cfg):
41+
anon = client.get("/api/config")
42+
assert anon.status_code == status.HTTP_200_OK
43+
assert anon.json().get("CONFIG_FILE_PARSE_ERROR") is None
44+
45+
auth = client.get(
46+
"/api/config",
47+
headers={"Authorization": f"Bearer {access_token}"},
48+
)
49+
assert auth.status_code == status.HTTP_200_OK
50+
assert (
51+
auth.json().get("CONFIG_FILE_PARSE_ERROR")
52+
== 'in "/data/config.yml", line 2'
53+
)
54+
55+
3456
def test_add_platform_binding_payload_shape(client, access_token: str):
3557
with patch.object(cm, "add_platform_binding") as add_platform_binding:
3658
response = client.post(

0 commit comments

Comments
 (0)