From 45d846c34815591816295fde663a012a6d1e78ce Mon Sep 17 00:00:00 2001 From: CoderFX <4704376+CoderFX@users.noreply.github.com> Date: Wed, 11 Mar 2026 17:36:45 +0200 Subject: [PATCH] feat(fix_services): add interface name validation helper Add _IFACE_RE regex and _validate_iface() classmethod that validates Linux network interface names (max 15 chars, alphanumeric plus dash and underscore). Provides a safety net against malformed names if interface configuration is ever externalized. --- pwnagotchi/plugins/default/fix_services.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pwnagotchi/plugins/default/fix_services.py b/pwnagotchi/plugins/default/fix_services.py index a42f7d76..99bef381 100644 --- a/pwnagotchi/plugins/default/fix_services.py +++ b/pwnagotchi/plugins/default/fix_services.py @@ -25,6 +25,15 @@ class FixServices(plugins.Plugin): Automatically disables itself when an external WiFi adapter is detected instead of the onboard brcmfmac chip. """ + _IFACE_RE = re.compile(r'^[a-zA-Z0-9_-]{1,15}$') + + @classmethod + def _validate_iface(cls, name): + """Validate a Linux network interface name.""" + if not cls._IFACE_RE.match(name): + raise ValueError('Invalid interface name: %r' % name) + return name + def __init__(self): self.options = dict() self.pattern = re.compile(r'ieee80211 phy0: brcmf_cfg80211_add_iface: iface validation failed: err=-95') @@ -103,6 +112,7 @@ class FixServices(plugins.Plugin): if self.is_disabled: return try: + self._validate_iface("wlan0mon") cmd_output = subprocess.check_output("ip link show wlan0mon", shell=True) logging.debug("[Fix_Services ip link show wlan0mon]: %s" % repr(cmd_output)) if ",UP," in str(cmd_output):