Skip to content

Commit 3710a4f

Browse files
security: fix errors security errors detected in cicd stage, not detected in local environment.
1 parent fdaa4d1 commit 3710a4f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

pkg_infra/session.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datetime import datetime, timezone
99
from dataclasses import dataclass
1010
from urllib.error import URLError
11+
from urllib.parse import urlparse
1112
from urllib.request import urlopen
1213

1314
# Third-party/local imports
@@ -21,6 +22,8 @@
2122
logger = logging.getLogger(__name__)
2223
logger.addHandler(logging.NullHandler())
2324

25+
IPINFO_URL = 'https://ipinfo.io/json'
26+
2427
# ---- Classes
2528

2629

@@ -148,7 +151,11 @@ def _get_location(timeout: float = 3.0) -> str | None:
148151
"""
149152
logger.debug('Resolving location via ipinfo.io')
150153
try:
151-
with urlopen('https://ipinfo.io/json', timeout=timeout) as response:
154+
parsed = urlparse(IPINFO_URL)
155+
if parsed.scheme != 'https' or parsed.netloc != 'ipinfo.io':
156+
raise ValueError('Unsafe location lookup URL configuration.')
157+
158+
with urlopen(IPINFO_URL, timeout=timeout) as response: # nosec B310
152159
data = json.load(response)
153160
city = data.get('city')
154161
region = data.get('region')

0 commit comments

Comments
 (0)