From e25aebbe455b2044f72a2c4e9c9005a6ec662501 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sat, 28 Nov 2026 09:42:10 +0100 Subject: [PATCH] fix(logins): the password states are named constants, not literals in a comparison (NetOrk/netork#2707) bandit reads password == "locked" as a hardcoded password (B105) and fails the security job. A state word is none; STATE_SET, STATE_LOCKED and STATE_NONE name them. --- napalm_device_types/login_accounts.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/napalm_device_types/login_accounts.py b/napalm_device_types/login_accounts.py index 5591f26..4b76c35 100644 --- a/napalm_device_types/login_accounts.py +++ b/napalm_device_types/login_accounts.py @@ -84,8 +84,18 @@ _LASTLOG_DATE = re.compile(r"\s(\w{3} \w{3} +\d{1,2} \d{2}:\d{2}:\d{2}(?: [+-]\d _ISO = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}") #: A row of a ``faillock`` tally starts with its date. _ISO_DATE = re.compile(r"^\d{4}-\d{2}-\d{2} ") +#: The states of an account's password, as the reading names them. Named, not literals in +#: a comparison: a state word is no password, but a scanner reading ``password == "..."`` +#: takes it for one (bandit B105). +STATE_SET, STATE_LOCKED, STATE_NONE = "set", "locked", "none" #: ``passwd -S``'s second word: shadow's and libuser's. -_PASSWORD_STATES = {"P": "set", "PS": "set", "L": "locked", "LK": "locked", "NP": "none"} +_PASSWORD_STATES = { + "P": STATE_SET, + "PS": STATE_SET, + "L": STATE_LOCKED, + "LK": STATE_LOCKED, + "NP": STATE_NONE, +} _NEVER = "never" _MUST_CHANGE = "password must be changed" @@ -285,7 +295,7 @@ def _expired(account_expires: str | None, today: date | None) -> bool | None: def _locked(password: str | None, account_expires: str | None, today: date | None) -> bool | None: """Locked when either says so, open when both say not, else unknown.""" - password_locked = None if password is None else password == "locked" + password_locked = None if password is None else password == STATE_LOCKED expired = _expired(account_expires, today) if password_locked or expired: return True