Skip to content

Commit 496ccbf

Browse files
committed
cleaup
1 parent 0b74049 commit 496ccbf

2 files changed

Lines changed: 9 additions & 20 deletions

File tree

backend/config/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ def _get_env(var: str, fallback: str | None = None) -> str | None:
113113
"PLAYMATCH_API_URL", "https://playmatch.retrorealm.dev/api/v2"
114114
).rstrip("/")
115115

116-
# Origins allowed to resolve to private/internal addresses despite SSRF
117-
# protection, so admin-configured self-hosted providers on a LAN or Docker
118-
# network stay reachable. Only user-configured provider URLs belong here.
119-
SSRF_ALLOWED_INTERNAL_ORIGINS: Final[tuple[str, ...]] = (PLAYMATCH_API_URL,)
120-
121116
# HASHEOUS
122117
HASHEOUS_API_ENABLED: Final[bool] = safe_str_to_bool(_get_env("HASHEOUS_API_ENABLED"))
123118

backend/utils/ssrf.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from urllib.parse import urlparse
3232

3333
import httpcore
34+
import pydash
3435
from httpcore._backends.auto import AutoBackend
3536
from httpcore._backends.base import (
3637
SOCKET_OPTION,
@@ -41,7 +42,7 @@
4142
)
4243
from httpcore._backends.sync import SyncBackend
4344

44-
from config import SSRF_ALLOWED_INTERNAL_ORIGINS
45+
from config import PLAYMATCH_API_URL
4546
from logger.logger import log
4647
from utils.validation import ValidationError
4748

@@ -102,29 +103,22 @@ def _parse_origin(origin: str) -> tuple[str, int] | None:
102103
parts = urlparse(origin)
103104
if parts.scheme not in ("http", "https") or not parts.hostname:
104105
return None
106+
105107
try:
106108
port = parts.port
107109
except ValueError:
108110
return None
111+
109112
if port is None:
110113
port = 443 if parts.scheme == "https" else 80
111-
return parts.hostname.lower(), port
112114

113-
114-
def build_internal_origin_allowlist(
115-
origins: typing.Iterable[str],
116-
) -> frozenset[tuple[str, int]]:
117-
"""Normalize admin-configured trusted origins into (host, port) pairs."""
118-
return frozenset(
119-
parsed for parsed in (_parse_origin(o) for o in origins if o) if parsed
120-
)
115+
return parts.hostname.lower(), port
121116

122117

123-
# Origins the admin explicitly configured (e.g. a self-hosted Playmatch on a
124-
# LAN or Docker network) are trusted to reach private addresses. Matched by
125-
# exact host and port so the exception stays as narrow as possible.
126-
INTERNAL_ORIGIN_ALLOWLIST: frozenset[tuple[str, int]] = build_internal_origin_allowlist(
127-
SSRF_ALLOWED_INTERNAL_ORIGINS
118+
# Origins the admin explicitly configured are trusted to reach private addresses.
119+
# Matched by exact host and port so the exception stays as narrow as possible.
120+
INTERNAL_ORIGIN_ALLOWLIST: frozenset[tuple[str, int]] = frozenset(
121+
pydash.compact([_parse_origin(PLAYMATCH_API_URL)])
128122
)
129123

130124

0 commit comments

Comments
 (0)