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

Remove file paths from telemetry data

上级 cae49fe8
...@@ -37,7 +37,8 @@ export class TelemetryService implements ITelemetryService { ...@@ -37,7 +37,8 @@ export class TelemetryService implements ITelemetryService {
private _userOptIn: boolean; private _userOptIn: boolean;
private _disposables: IDisposable[] = []; private _disposables: IDisposable[] = [];
private _cleanupPatterns: [RegExp, string][] = []; private _cleanupPatterns: RegExp[] = [];
private readonly fileRegex = process.platform === 'win32' ? /[a-z,A-Z]:(\\?[\\\/]\w+)+/g : /(\/\w+)+/g;
constructor( constructor(
config: ITelemetryServiceConfig, config: ITelemetryServiceConfig,
...@@ -48,18 +49,11 @@ export class TelemetryService implements ITelemetryService { ...@@ -48,18 +49,11 @@ export class TelemetryService implements ITelemetryService {
this._piiPaths = config.piiPaths || []; this._piiPaths = config.piiPaths || [];
this._userOptIn = typeof config.userOptIn === 'undefined' ? true : config.userOptIn; this._userOptIn = typeof config.userOptIn === 'undefined' ? true : config.userOptIn;
// static cleanup patterns for: // static cleanup pattern for: `file:///DANGEROUS/PATH/resources/app/Useful/Information`
// #1 `file:///DANGEROUS/PATH/resources/app/Useful/Information` this._cleanupPatterns = [/file:\/\/\/.*?\/resources\/app\//gi];
// #2 // Any other file path that doesn't match the approved form above should be cleaned.
// #3 "Error: ENOENT; no such file or directory" is often followed with PII, clean it
this._cleanupPatterns.push(
[/file:\/\/\/.*?\/resources\/app\//gi, ''],
[/file:\/\/\/.*/gi, ''],
[/ENOENT: no such file or directory.*?\'([^\']+)\'/gi, 'ENOENT: no such file or directory']
);
for (let piiPath of this._piiPaths) { for (let piiPath of this._piiPaths) {
this._cleanupPatterns.push([new RegExp(escapeRegExpCharacters(piiPath), 'gi'), '']); this._cleanupPatterns.push(new RegExp(escapeRegExpCharacters(piiPath), 'gi'));
} }
if (this._configurationService) { if (this._configurationService) {
...@@ -127,10 +121,21 @@ export class TelemetryService implements ITelemetryService { ...@@ -127,10 +121,21 @@ export class TelemetryService implements ITelemetryService {
private _cleanupInfo(stack: string): string { private _cleanupInfo(stack: string): string {
const m = stack.match(this.fileRegex);
if (!m) {
return stack;
}
// remove file paths that do not match the cleanup patterns
m.forEach(x => {
if (this._cleanupPatterns.every(pattern => !pattern.test(x))) {
stack = stack.replace(x, '');
}
});
// sanitize with configured cleanup patterns // sanitize with configured cleanup patterns
for (let tuple of this._cleanupPatterns) { for (let regexp of this._cleanupPatterns) {
let [regexp, replaceValue] = tuple; stack = stack.replace(regexp, '');
stack = stack.replace(regexp, replaceValue);
} }
return stack; return stack;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册