fix(GUI): don't log absolute paths in Mixpanel (#1161)

The event data may contain absolute paths that contain user information that
should not be logged in Mixpanel. Instead, we replace absolute path properties
with their base name.

Change-Type: patch
Changelog-Entry: Don't include user paths in Mixpanel analytics events.
This commit is contained in:
Ștefan Daniel Mihăilă
2017-03-15 04:05:48 +00:00
committed by Juan Cruz Viotti
parent 2342831104
commit fe20f5061f
5 changed files with 272 additions and 4 deletions

View File

@@ -17,8 +17,10 @@
'use strict';
const _ = require('lodash');
_.mixin(require('lodash-deep'));
const flatten = require('flat').flatten;
const deepMapKeys = require('deep-map-keys');
const path = require('path');
/**
* @summary Create a flattened copy of the object with all keys transformed in start case
@@ -81,3 +83,53 @@ exports.makeFlatStartCaseObject = (object) => {
});
};
/**
* @summary Create an object clone with all absolute paths replaced with the path basename
* @function
* @public
*
* @param {Object} object - original object
* @returns {Object} transformed object
*
* @example
* const anonymized = utils.hideAbsolutePathsInObject({
* path1: '/home/john/rpi.img',
* simpleProperty: null,
* nested: {
* path2: '/home/john/another-image.img',
* path3: 'yet-another-image.img',
* otherProperty: false
* }
* });
*
* console.log(anonymized);
* > {
* > path1: 'rpi.img',
* > simpleProperty: null,
* > nested: {
* > path2: 'another-image.img',
* > path3: 'yet-another-image.img',
* > otherProperty: false
* > }
* > }
*/
exports.hideAbsolutePathsInObject = (object) => {
return _.deepMapValues(object, (value) => {
if (!_.isString(value)) {
return value;
}
// Don't alter disk devices, even though they appear as full paths
if (_.some([
_.startsWith(value, '/dev/'),
_.startsWith(value, '\\\\.\\')
])) {
return value;
}
return path.isAbsolute(value) ? path.basename(value) : value;
});
};