@@ -102,39 +102,49 @@ def reset(self) -> None:
102102 "mapData" ,
103103 "rawApiResponse" ,
104104 # Home data
105- "id" ,
105+ "id" , # We want to redact home_data.id but keep some other ids, see below
106106 "name" ,
107107 "productId" ,
108108 "ipAddress" ,
109109 "mac" ,
110110 "wifiName" ,
111- "schema" , # Large
112111 "lat" ,
113112 "long" ,
114113}
114+ KEEP_KEYS = {
115+ # Product information no unique per user
116+ "product.id" ,
117+ "schema.id" ,
118+ # Room ids are likely unique per user, but don't seem too sensitive and are
119+ # useful for debugging
120+ "rooms.id" ,
121+ }
115122DEVICE_UID = "duid"
116123REDACTED = "**REDACTED**"
117124
118125
119- def redact_device_data (data : T ) -> T | dict [str , Any ]:
126+ def redact_device_data (data : T , path : str = "" ) -> T | dict [str , Any ]:
120127 """Redact sensitive data in a dict."""
121128 if not isinstance (data , (Mapping , list )):
122129 return data
123130
124131 if isinstance (data , list ):
125- return cast (T , [redact_device_data (item ) for item in data ])
132+ return cast (T , [redact_device_data (item , path ) for item in data ])
126133
127134 redacted = {** data }
128135
129136 for key , value in redacted .items ():
130- if key in REDACT_KEYS :
137+ curr_path = f"{ path } .{ key } " if path else key
138+ if key in KEEP_KEYS or curr_path in KEEP_KEYS :
139+ continue
140+ if key in REDACT_KEYS or curr_path in REDACT_KEYS :
131141 redacted [key ] = REDACTED
132142 elif key == DEVICE_UID and isinstance (value , str ):
133143 redacted [key ] = redact_device_uid (value )
134144 elif isinstance (value , dict ):
135- redacted [key ] = redact_device_data (value )
145+ redacted [key ] = redact_device_data (value , curr_path )
136146 elif isinstance (value , list ):
137- redacted [key ] = [redact_device_data (item ) for item in value ]
147+ redacted [key ] = [redact_device_data (item , curr_path ) for item in value ]
138148
139149 return redacted
140150
0 commit comments