added sha256 hash to obfuscate analytics data

This commit is contained in:
Nikhil Nandagopal 2020-11-04 16:23:15 +05:30
parent 0f90b19dc0
commit f05ac9a9c6
3 changed files with 23 additions and 15 deletions

View File

@ -63,6 +63,7 @@
"interweave": "^12.1.1", "interweave": "^12.1.1",
"interweave-autolink": "^4.0.1", "interweave-autolink": "^4.0.1",
"js-base64": "^3.4.5", "js-base64": "^3.4.5",
"js-sha256": "^0.9.0",
"json-fn": "^1.1.1", "json-fn": "^1.1.1",
"lint-staged": "^9.2.5", "lint-staged": "^9.2.5",
"localforage": "^1.7.3", "localforage": "^1.7.3",
@ -141,7 +142,6 @@
"eslintConfig": { "eslintConfig": {
"extends": "react-app", "extends": "react-app",
"parser": "@typescript-eslint/parser" "parser": "@typescript-eslint/parser"
}, },
"browserslist": [ "browserslist": [
">0.2%", ">0.2%",

View File

@ -6,6 +6,7 @@ import { getAppsmithConfigs } from "configs";
import * as Sentry from "@sentry/react"; import * as Sentry from "@sentry/react";
import { ANONYMOUS_USERNAME, User } from "../constants/userConstants"; import { ANONYMOUS_USERNAME, User } from "../constants/userConstants";
const { cloudHosting } = getAppsmithConfigs(); const { cloudHosting } = getAppsmithConfigs();
import { sha256 } from "js-sha256";
export type EventLocation = export type EventLocation =
| "LIGHTNING_MENU" | "LIGHTNING_MENU"
@ -173,13 +174,16 @@ class AnalyticsUtil {
const app = (userData.applications || []).find( const app = (userData.applications || []).find(
(app: any) => app.id === appId, (app: any) => app.id === appId,
); );
const user = { let user: any = {};
if (windowDoc.cloudHosting) {
user = {
userId: userData.username, userId: userData.username,
email: userData.email, email: userData.email,
currentOrgId: userData.currentOrganizationId, currentOrgId: userData.currentOrganizationId,
appId: appId, appId: appId,
appName: app ? app.name : undefined, appName: app ? app.name : undefined,
}; };
}
finalEventData = { finalEventData = {
...eventData, ...eventData,
userData: user.userId === ANONYMOUS_USERNAME ? undefined : user, userData: user.userId === ANONYMOUS_USERNAME ? undefined : user,
@ -193,22 +197,21 @@ class AnalyticsUtil {
static identifyUser(userData: User) { static identifyUser(userData: User) {
const windowDoc: any = window; const windowDoc: any = window;
const userId = windowDoc.cloudHosting const userId = userData.username;
? userData.username
: userData.anonymousId;
log.debug("Identify User " + userId); log.debug("Identify User " + userId);
AnalyticsUtil.user = userData;
FeatureFlag.identify(userData); FeatureFlag.identify(userData);
if (windowDoc.analytics) { if (windowDoc.analytics) {
let userProperties = {};
if (windowDoc.cloudHosting) { if (windowDoc.cloudHosting) {
userProperties = { const userProperties = {
email: userData.email, email: userData.email,
name: userData.name, name: userData.name,
userId: userId, userId: userId,
}; };
} AnalyticsUtil.user = userData;
windowDoc.analytics.identify(userId, userProperties); windowDoc.analytics.identify(userId, userProperties);
} else {
windowDoc.analytics.identify(sha256(userId));
}
} }
Sentry.configureScope(function(scope) { Sentry.configureScope(function(scope) {
scope.setUser({ scope.setUser({

View File

@ -11781,6 +11781,11 @@ js-base64@^3.4.5:
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.5.2.tgz#3cc800e4f10812b55fb5ec53e7cabaef35dc6d3c" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.5.2.tgz#3cc800e4f10812b55fb5ec53e7cabaef35dc6d3c"
integrity sha512-VG2qfvV5rEQIVxq9UmAVyWIaOdZGt9M16BLu8vFkyWyhv709Hyg4nKUb5T+Ru+HmAr9RHdF+kQDKAhbJlcdKeQ== integrity sha512-VG2qfvV5rEQIVxq9UmAVyWIaOdZGt9M16BLu8vFkyWyhv709Hyg4nKUb5T+Ru+HmAr9RHdF+kQDKAhbJlcdKeQ==
js-sha256@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==
js-string-escape@^1.0.1: js-string-escape@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/js-string-escape/-/js-string-escape-1.0.1.tgz#e2625badbc0d67c7533e9edc1068c587ae4137ef" resolved "https://registry.yarnpkg.com/js-string-escape/-/js-string-escape-1.0.1.tgz#e2625badbc0d67c7533e9edc1068c587ae4137ef"