Sanitize Redfish string fields to strip non-ASCII/non-printable characters

IOM1's HostName field contains binary artifacts that decode to garbage
unicode characters (e.g. 𳇀 prefixing a UUID). Strip any character
outside printable ASCII (0x20–0x7F) from all string fields returned by
_parse_network_data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-16 14:23:11 -04:00
parent 425200030f
commit 022340edae

View File

@@ -27,6 +27,12 @@ from ui import (
# ── Shared helpers ───────────────────────────────────────────────────────────── # ── Shared helpers ─────────────────────────────────────────────────────────────
def _sanitize(value: str) -> str:
"""Strip non-printable and non-ASCII characters from a string field.
IOM Redfish responses occasionally contain binary artifacts in text fields."""
return "".join(c for c in value if 32 <= ord(c) < 128)
def _parse_network_data(data: dict) -> tuple: def _parse_network_data(data: dict) -> tuple:
""" """
Extract network details from a Redfish EthernetInterfaces/1 response dict. Extract network details from a Redfish EthernetInterfaces/1 response dict.
@@ -41,15 +47,15 @@ def _parse_network_data(data: dict) -> tuple:
addrs = data.get("IPv4StaticAddresses") or data.get("IPv4Addresses", []) addrs = data.get("IPv4StaticAddresses") or data.get("IPv4Addresses", [])
if addrs: if addrs:
addr = addrs[0] addr = addrs[0]
ip = addr.get("Address", "--") ip = _sanitize(addr.get("Address", "--"))
gateway = addr.get("Gateway", "--") gateway = _sanitize(addr.get("Gateway", "--"))
netmask = addr.get("SubnetMask", "--") netmask = _sanitize(addr.get("SubnetMask", "--"))
else: else:
ip = gateway = netmask = "--" ip = gateway = netmask = "--"
mac = data.get("MACAddress", "--") mac = _sanitize(data.get("MACAddress", "--"))
hostname = data.get("HostName", "--") hostname = _sanitize(data.get("HostName", "--"))
link_status = data.get("LinkStatus", "--") link_status = _sanitize(data.get("LinkStatus", "--"))
return dhcp_enabled, ip, gateway, netmask, mac, hostname, link_status return dhcp_enabled, ip, gateway, netmask, mac, hostname, link_status