From 6a8ebfe235af5376bca11984d0ff3fadc515e1da Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Tue, 17 Nov 2026 13:53:19 +0100 Subject: [PATCH] fix(security): say why the device's /tmp and the http(s) fetch are fine (bandit) --- napalm_openwrt/firmware_mixin.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/napalm_openwrt/firmware_mixin.py b/napalm_openwrt/firmware_mixin.py index 5ffe1af..e54f5ed 100644 --- a/napalm_openwrt/firmware_mixin.py +++ b/napalm_openwrt/firmware_mixin.py @@ -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")