提交 25462545 编写于 作者: R Ramya Achutha Rao

Anonymize paths only from error telemetry else data like mimetypes get anonymized

上级 e40581af
......@@ -166,7 +166,7 @@ export default class ErrorTelemetry {
"${include}": [ "${ErrorEvent}" ]
}
*/
this._telemetryService.publicLog('UnhandledError', error);
this._telemetryService.publicLog('UnhandledError', error, true);
}
this._buffer.length = 0;
}
......
......@@ -29,7 +29,7 @@ export interface ITelemetryService {
* Sends a telemetry event that has been privacy approved.
* Do not call this unless you have been given approval.
*/
publicLog(eventName: string, data?: ITelemetryData): TPromise<void>;
publicLog(eventName: string, data?: ITelemetryData, anonymizeFilePaths?: boolean): TPromise<void>;
getTelemetryInfo(): TPromise<ITelemetryInfo>;
......
......@@ -91,7 +91,7 @@ export class TelemetryService implements ITelemetryService {
this._disposables = dispose(this._disposables);
}
publicLog(eventName: string, data?: ITelemetryData): TPromise<any> {
publicLog(eventName: string, data?: ITelemetryData, anonymizeFilePaths?: boolean): TPromise<any> {
// don't send events when the user is optout
if (!this._userOptIn) {
return TPromise.as(undefined);
......@@ -105,7 +105,7 @@ export class TelemetryService implements ITelemetryService {
// (last) remove all PII from data
data = cloneAndChange(data, value => {
if (typeof value === 'string') {
return this._cleanupInfo(value);
return this._cleanupInfo(value, anonymizeFilePaths);
}
return undefined;
});
......@@ -118,29 +118,33 @@ export class TelemetryService implements ITelemetryService {
});
}
private _cleanupInfo(stack: string): string {
const cleanUpIndexes: [number, number][] = [];
for (let regexp of this._cleanupPatterns) {
private _cleanupInfo(stack: string, anonymizeFilePaths?: boolean): string {
let updatedStack = stack;
if (anonymizeFilePaths) {
const cleanUpIndexes: [number, number][] = [];
for (let regexp of this._cleanupPatterns) {
while (true) {
const result = regexp.exec(stack);
if (!result) {
break;
}
cleanUpIndexes.push([result.index, regexp.lastIndex]);
}
}
const nodeModulesRegex = /^[\\\/]?(node_modules|node_modules\.asar)[\\\/]/;
const fileRegex = /(file:\/\/)?([a-zA-Z]:(\\\\|\\|\/)|(\\\\|\\|\/))?([\w-\._]+(\\\\|\\|\/))+[\w-\._]*/g;
while (true) {
const result = regexp.exec(stack);
const result = fileRegex.exec(stack);
if (!result) {
break;
}
cleanUpIndexes.push([result.index, regexp.lastIndex]);
}
}
const nodeModulesRegex = /^[\\\/]?(node_modules|node_modules\.asar)[\\\/]/;
const fileRegex = /(file:\/\/)?([a-zA-Z]:(\\\\|\\|\/)|(\\\\|\\|\/))?([\w-\._]+(\\\\|\\|\/))+[\w-\._]*/g;
let updatedStack = stack;
while (true) {
const result = fileRegex.exec(stack);
if (!result) {
break;
}
// Anoynimize user file paths that do not need to be retained or cleaned up.
if (!nodeModulesRegex.test(result[0]) && cleanUpIndexes.every(([x, y]) => result.index < x || result.index >= y)) {
updatedStack = updatedStack.slice(0, result.index) + result[0].replace(/./g, 'a') + updatedStack.slice(fileRegex.lastIndex);
// Anoynimize user file paths that do not need to be retained or cleaned up.
if (!nodeModulesRegex.test(result[0]) && cleanUpIndexes.every(([x, y]) => result.index < x || result.index >= y)) {
updatedStack = updatedStack.slice(0, result.index) + result[0].replace(/./g, 'a') + updatedStack.slice(fileRegex.lastIndex);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册