|
31 | 31 | from urllib.parse import urlparse |
32 | 32 |
|
33 | 33 | import httpcore |
| 34 | +import pydash |
34 | 35 | from httpcore._backends.auto import AutoBackend |
35 | 36 | from httpcore._backends.base import ( |
36 | 37 | SOCKET_OPTION, |
|
41 | 42 | ) |
42 | 43 | from httpcore._backends.sync import SyncBackend |
43 | 44 |
|
44 | | -from config import SSRF_ALLOWED_INTERNAL_ORIGINS |
| 45 | +from config import PLAYMATCH_API_URL |
45 | 46 | from logger.logger import log |
46 | 47 | from utils.validation import ValidationError |
47 | 48 |
|
@@ -102,29 +103,22 @@ def _parse_origin(origin: str) -> tuple[str, int] | None: |
102 | 103 | parts = urlparse(origin) |
103 | 104 | if parts.scheme not in ("http", "https") or not parts.hostname: |
104 | 105 | return None |
| 106 | + |
105 | 107 | try: |
106 | 108 | port = parts.port |
107 | 109 | except ValueError: |
108 | 110 | return None |
| 111 | + |
109 | 112 | if port is None: |
110 | 113 | port = 443 if parts.scheme == "https" else 80 |
111 | | - return parts.hostname.lower(), port |
112 | 114 |
|
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 |
121 | 116 |
|
122 | 117 |
|
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)]) |
128 | 122 | ) |
129 | 123 |
|
130 | 124 |
|
|
0 commit comments