fix(security): say why the device's /tmp and the http(s) fetch are fine (bandit)
driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Successful in 17s
driver / types (pull_request) Successful in 56s
driver / test (3.13) (pull_request) Successful in 57s
driver / test (3.12) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 28s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m4s
CI / driver (pull_request) Successful in 2m19s
driver / publish (pull_request) Skipped

This commit is contained in:
Christian Manivong committed 2026-11-17 13:53:19 +01:00
1 parent 3e80f7d02a
commit 6a8ebfe235
1 file changed
+5 -3
+5 -3
View File
@@ -73,8 +73,9 @@ _MAX_BYTES: Final = 2 * 1024 * 1024
#: Per server URL: (monotonic time fetched, overview or None for a failed fetch).
_OVERVIEWS: dict[str, tuple[float, dict[str, Any] | None]] = {}
_LOG: Final = "/tmp/owut-upgrade.log"
_PID: Final = "/tmp/owut-upgrade.pid"
# On the device, not here: its /tmp is RAM, where owut keeps its image too.
_LOG: Final = "/tmp/owut-upgrade.log" # nosec B108
_PID: Final = "/tmp/owut-upgrade.pid" # nosec B108
_STATUS: Final = "__OWUT_RC="
_STATUS_RE: Final = re.compile(rf"^{_STATUS}(\d+)\s*$", re.MULTILINE)
#: What owut prints right before it hands the image to sysupgrade.
@@ -138,7 +139,8 @@ def _builds(branch: dict[str, Any], target: str) -> bool:
def _fetch_json(url: str) -> dict[str, Any]:
"""GET *url* as JSON; raises on any failure."""
request = urllib.request.Request(url, headers={"User-Agent": "napalm-openwrt"})
with urllib.request.urlopen(request, timeout=_FETCH_TIMEOUT) as response: # noqa: S310 - http(s) only, see _server_url
# http(s) only: _server_url gives nothing else.
with urllib.request.urlopen(request, timeout=_FETCH_TIMEOUT) as response: # noqa: S310 # nosec B310
data = json.loads(response.read(_MAX_BYTES))
if not isinstance(data, dict):
raise ValueError("overview.json is not an object")