Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/test_mqtt_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@
f"evt/{device_type}/{device_topic}/#",
]

def mask_mac_in_topic(topic, mac_addr):
if mac_addr and mac_addr in topic:
return topic.replace(mac_addr, "[REDACTED_MAC]")
return topic

for topic in topics:
try:
await mqtt_client.subscribe(topic, message_handler)
print(f" ✅ Subscribed to: {topic}")
print(f" ✅ Subscribed to: {mask_mac_in_topic(topic, device_id)}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High test

This expression logs
sensitive data (private)
as clear text.

Copilot Autofix

AI 6 months ago

To fix the problem, all print or log statements that display the sensitive device MAC address (device_id, from device.device_info.mac_address) should redact it before outputting. The best method is to replace every instance where the MAC address would be printed with a redacted string such as "[REDACTED_MAC]", ensuring that no clear-text MAC addresses are shown as output. Specifically:

  • On line 92, replace the output of the MAC address.
  • In mask_mac_in_topic, ensure its masking is robust, and review all places where device identifiers are printed.
  • Ensure that, wherever device identifiers (especially device_id/MAC addresses) are included in debug, print, or log statements, they are masked.
  • Changes are limited to only the edit regions shown in the provided code, so only change print statements in the provided snippet.

No additional imports are needed, as masking is handled via string replacement.


Suggested changeset 1
examples/test_mqtt_messaging.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/test_mqtt_messaging.py b/examples/test_mqtt_messaging.py
--- a/examples/test_mqtt_messaging.py
+++ b/examples/test_mqtt_messaging.py
@@ -89,7 +89,7 @@
             additional_value = device.device_info.additional_value
 
             print(f"✅ Found device: {device.device_info.device_name}")
-            print(f"   MAC Address: {device_id}")
+            print("   MAC Address: [REDACTED_MAC]")
             print(f"   Device Type: {device_type}")
             print(f"   Additional Value: {additional_value}")
             print(f"   Connection Status: {device.device_info.connected}")
@@ -125,7 +125,7 @@
             for topic in topics:
                 try:
                     await mqtt_client.subscribe(topic, message_handler)
-                    print(f"   ✅ Subscribed to: {mask_mac_in_topic(topic, device_id)}")
+                    print("   ✅ Subscribed to: [REDACTED_TOPIC_MAC]")
                 except Exception as e:
                     print(
                         f"   ⚠️ Failed to subscribe to device topic (type: {device_type}): {e}"
EOF
@@ -89,7 +89,7 @@
additional_value = device.device_info.additional_value

print(f"✅ Found device: {device.device_info.device_name}")
print(f" MAC Address: {device_id}")
print(" MAC Address: [REDACTED_MAC]")
print(f" Device Type: {device_type}")
print(f" Additional Value: {additional_value}")
print(f" Connection Status: {device.device_info.connected}")
@@ -125,7 +125,7 @@
for topic in topics:
try:
await mqtt_client.subscribe(topic, message_handler)
print(f" ✅ Subscribed to: {mask_mac_in_topic(topic, device_id)}")
print(" ✅ Subscribed to: [REDACTED_TOPIC_MAC]")
except Exception as e:
print(
f" ⚠️ Failed to subscribe to device topic (type: {device_type}): {e}"
Copilot is powered by AI and may make mistakes. Always verify output.
except Exception as e:
print(
f" ⚠️ Failed to subscribe to device topic (type: {device_type}): {e}"
Expand Down