From c282d93ffa6964db0c9a457b84e883acdfd4699a Mon Sep 17 00:00:00 2001 From: LyCecilion Date: Sat, 11 Jul 2026 11:25:27 +0800 Subject: [PATCH] fix(privacy): redact hardware addresses in CLI --- xidio/xidio.CLI/ConsoleDiagnosticReporter.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/xidio/xidio.CLI/ConsoleDiagnosticReporter.cs b/xidio/xidio.CLI/ConsoleDiagnosticReporter.cs index 9a578be..91d957e 100644 --- a/xidio/xidio.CLI/ConsoleDiagnosticReporter.cs +++ b/xidio/xidio.CLI/ConsoleDiagnosticReporter.cs @@ -278,7 +278,7 @@ private static void PrintPrimaryInterfaceDetails(PrimaryInterfaceInfo primaryInt detailsTable.AddRow("已连接", FormatBool(primaryInterface.IsConnected)); detailsTable.AddRow("状态", FormatOperationalStatus(primaryInterface.OperationalStatus)); detailsTable.AddRow("接口类型", Escape(primaryInterface.NetworkInterfaceType.ToString())); - detailsTable.AddRow("MAC 地址", Escape(primaryInterface.MacAddress ?? "")); + detailsTable.AddRow("MAC 地址", Escape(FormatHardwareAddress(primaryInterface.MacAddress))); detailsTable.AddRow("链路速度", Escape(FormatLinkSpeed(primaryInterface.LinkSpeedBitsPerSecond))); detailsTable.AddRow("MTU", Escape(primaryInterface.Mtu is null ? "" @@ -287,7 +287,7 @@ private static void PrintPrimaryInterfaceDetails(PrimaryInterfaceInfo primaryInt if (primaryInterface.WirelessConnection is not null) { detailsTable.AddRow("SSID", Escape(primaryInterface.WirelessConnection.Ssid)); - detailsTable.AddRow("BSSID", Escape(primaryInterface.WirelessConnection.Bssid)); + detailsTable.AddRow("BSSID", Escape(FormatHardwareAddress(primaryInterface.WirelessConnection.Bssid))); detailsTable.AddRow("RSSI", Escape(primaryInterface.WirelessConnection.RssiDbm is null ? "" : $"{primaryInterface.WirelessConnection.RssiDbm} dBm")); @@ -371,7 +371,7 @@ private static void PrintNeighborSummary(IReadOnlyList neig neighborTable.AddRow( Escape(FormatAddressFamily(neighbor.AddressFamily)), Escape(neighbor.IpAddress), - Escape(string.IsNullOrWhiteSpace(neighbor.LinkLayerAddress) ? "" : neighbor.LinkLayerAddress), + Escape(FormatHardwareAddress(neighbor.LinkLayerAddress, "")), Escape(neighbor.State)); } @@ -637,6 +637,19 @@ private static string FormatWirelessRates(WirelessConnectionInfo wireless) return $"Rx {rx}, Tx {tx}"; } + private static string FormatHardwareAddress(string? address, string unavailable = "") + { + if (string.IsNullOrWhiteSpace(address)) + return unavailable; + + var separator = address.Contains(':') ? ':' : '-'; + var parts = address.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + return parts.Length == 6 && parts.All(part => part.Length == 2) + ? string.Join(separator, parts.Take(3).Concat(["XX", "XX", "XX"])) + : ""; + } + private static string FormatDnsResult(DnsProbeResult result) { var source = string.IsNullOrWhiteSpace(result.DnsServer) ? "system" : result.DnsServer;