Skip to content

Commit

Permalink
Redact privacy sensitive fields from device specification
Browse files Browse the repository at this point in the history
* functon which can redact device log fields

* reverted dubble quotes to single quotes.

* another double quote to single quote. IDE automatically changes this when save.. :-(

* set default Redacted fields, and append redacted fields when needed. added same redacted function for other driver.

* Ensure filter implementation does not crash

---------

Co-authored-by: Eelco <[email protected]>
Co-authored-by: Bob van de Vijver <[email protected]>
  • Loading branch information
3 people authored Jul 29, 2024
1 parent 5767e19 commit 307aeff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion drivers/other/driver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const TuyaOAuth2Driver = require("../../lib/TuyaOAuth2Driver");
const TuyaOAuth2Util = require("../../lib/TuyaOAuth2Util");

module.exports = class TuyaOAuth2DriverOther extends TuyaOAuth2Driver {
onTuyaPairListDeviceFilter() {
Expand All @@ -11,7 +12,7 @@ module.exports = class TuyaOAuth2DriverOther extends TuyaOAuth2Driver {
const props = super.onTuyaPairListDeviceProperties(device);

const combinedSpecification = {
device: device,
device: TuyaOAuth2Util.redactFields(device),
specifications: specifications,
};

Expand Down
3 changes: 2 additions & 1 deletion lib/TuyaOAuth2Driver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { OAuth2Driver } = require('homey-oauth2app');
const TuyaOAuth2Util = require('./TuyaOAuth2Util');

/**
* @extends OAuth2Driver
Expand All @@ -14,7 +15,7 @@ class TuyaOAuth2Driver extends OAuth2Driver {
const devices = await oAuth2Client.getDevices();
const filteredDevices = devices
.filter(device => {
this.log('Device:', JSON.stringify(device));
this.log('Device:', JSON.stringify(TuyaOAuth2Util.redactFields(device)));
return this.onTuyaPairListDeviceFilter(device);
});
const listDevices = [];
Expand Down
17 changes: 17 additions & 0 deletions lib/TuyaOAuth2Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ class TuyaOAuth2Util {
return headers;
}

/*
* Redact sensitive fields when logging Device information
*/
static redactFields(device, additionalFields = []) {
const defaultFields = ['ip', 'lat', 'lon', 'owner_id', 'uid', 'uuid', 'local_key'];
const combinedFields = [...new Set([...defaultFields, ...additionalFields])];

const newObj = JSON.parse(JSON.stringify(device));
combinedFields.forEach((field) => {
if (newObj.hasOwnProperty(field)) {
newObj[field] = "<redacted>";
}
});

return newObj;
}

}

module.exports = TuyaOAuth2Util;

0 comments on commit 307aeff

Please sign in to comment.