Skip to content

Commit 2909a19

Browse files
committed
GDPR: Added includePrivateInformation flags.
1 parent b110dc9 commit 2909a19

File tree

6 files changed

+195
-17
lines changed

6 files changed

+195
-17
lines changed

src/configuration/Configuration.ts

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ export class Configuration implements IConfigurationSettings {
115115
*/
116116
private _dataExclusions: string[] = [];
117117

118+
private _includePrivateInformation: boolean;
119+
private _includeUserName: boolean;
120+
private _includeMachineName: boolean;
121+
private _includeIpAddress: boolean;
122+
private _includeCookies: boolean;
123+
private _includePostData: boolean;
124+
private _includeQueryString: boolean;
125+
118126
/**
119127
* A list of user agent patterns.
120128
* @type {Array}
@@ -148,6 +156,7 @@ export class Configuration implements IConfigurationSettings {
148156
this.serverUrl = configSettings.serverUrl;
149157
this.heartbeatServerUrl = configSettings.heartbeatServerUrl;
150158
this.updateSettingsWhenIdleInterval = configSettings.updateSettingsWhenIdleInterval;
159+
this.includePrivateInformation = configSettings.includePrivateInformation;
151160

152161
this.environmentInfoCollector = inject(configSettings.environmentInfoCollector);
153162
this.errorParser = inject(configSettings.errorParser);
@@ -286,6 +295,138 @@ export class Configuration implements IConfigurationSettings {
286295
this._dataExclusions = Utils.addRange<string>(this._dataExclusions, ...exclusions);
287296
}
288297

298+
/**
299+
* Gets a value indicating whether to include private information about the local machine.
300+
* @returns {boolean}
301+
*/
302+
public get includePrivateInformation(): boolean {
303+
return this._includePrivateInformation;
304+
}
305+
306+
/**
307+
* Sets a value indicating whether to include private information about the local machine
308+
* @param value
309+
*/
310+
public set includePrivateInformation(value: boolean) {
311+
const val = value || false;
312+
this._includePrivateInformation = val;
313+
this.includeUserName = val;
314+
this._includeMachineName = val;
315+
this.includeIpAddress = val;
316+
this.includeCookies = val;
317+
this.includePostData = val;
318+
this.includeQueryString = val;
319+
this.changed();
320+
}
321+
322+
/**
323+
* Gets a value indicating whether to include User Name.
324+
* @returns {boolean}
325+
*/
326+
public get includeUserName(): boolean {
327+
return this._includeUserName;
328+
}
329+
330+
/**
331+
* Sets a value indicating whether to include User Name.
332+
* @param value
333+
*/
334+
public set includeUserName(value: boolean) {
335+
this._includeUserName = value || false;
336+
this.changed();
337+
}
338+
339+
/**
340+
* Gets a value indicating whether to include MachineName in MachineInfo.
341+
* @returns {boolean}
342+
*/
343+
public get includeMachineName(): boolean {
344+
return this._includeMachineName;
345+
}
346+
347+
/**
348+
* Sets a value indicating whether to include MachineName in MachineInfo.
349+
* @param value
350+
*/
351+
public set includeMachineName(value: boolean) {
352+
this._includeMachineName = value || false;
353+
this.changed();
354+
}
355+
356+
/**
357+
* Gets a value indicating whether to include Ip Addresses in MachineInfo and RequestInfo.
358+
* @returns {boolean}
359+
*/
360+
public get includeIpAddress(): boolean {
361+
return this._includeIpAddress;
362+
}
363+
364+
/**
365+
* Sets a value indicating whether to include Ip Addresses in MachineInfo and RequestInfo.
366+
* @param value
367+
*/
368+
public set includeIpAddress(value: boolean) {
369+
this._includeIpAddress = value || false;
370+
this.changed();
371+
}
372+
373+
/**
374+
* Gets a value indicating whether to include Cookies.
375+
* NOTE: DataExclusions are applied to all Cookie keys when enabled.
376+
* @returns {boolean}
377+
*/
378+
public get includeCookies(): boolean {
379+
return this._includeCookies;
380+
}
381+
382+
/**
383+
* Sets a value indicating whether to include Cookies.
384+
* NOTE: DataExclusions are applied to all Cookie keys when enabled.
385+
* @param value
386+
*/
387+
public set includeCookies(value: boolean) {
388+
this._includeCookies = value || false;
389+
this.changed();
390+
}
391+
392+
/**
393+
* Gets a value indicating whether to include Form/POST Data.
394+
* NOTE: DataExclusions are only applied to Form data keys when enabled.
395+
* @returns {boolean}
396+
*/
397+
public get includePostData(): boolean {
398+
return this._includePostData;
399+
}
400+
401+
/**
402+
* Sets a value indicating whether to include Form/POST Data.
403+
* NOTE: DataExclusions are only applied to Form data keys when enabled.
404+
* @param value
405+
*/
406+
public set includePostData(value: boolean) {
407+
this._includePostData = value || false;
408+
this.changed();
409+
}
410+
411+
/**
412+
* Gets a value indicating whether to include query string information.
413+
* NOTE: DataExclusions are applied to all Query String keys when enabled.
414+
* @returns {boolean}
415+
*/
416+
public get includeQueryString(): boolean {
417+
return this._includeQueryString;
418+
}
419+
420+
/**
421+
* Sets a value indicating whether to include query string information.
422+
* NOTE: DataExclusions are applied to all Query String keys when enabled.
423+
* @param value
424+
*/
425+
public set includeQueryString(value: boolean) {
426+
this._includeQueryString = value || false;
427+
this.changed();
428+
}
429+
289430
/**
290431
* A list of user agent patterns that will cause any event with a matching user agent to not be submitted.
291432
*
@@ -468,7 +609,7 @@ export class Configuration implements IConfigurationSettings {
468609
*/
469610
public static get defaults() {
470611
if (Configuration._defaultSettings === null) {
471-
Configuration._defaultSettings = {};
612+
Configuration._defaultSettings = { includePrivateInformation: true };
472613
}
473614

474615
return Configuration._defaultSettings;

src/configuration/IConfigurationSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface IConfigurationSettings {
1414
serverUrl?: string;
1515
heartbeatServerUrl?: string;
1616
updateSettingsWhenIdleInterval?: number;
17+
includePrivateInformation?: boolean;
1718
environmentInfoCollector?: IEnvironmentInfoCollector;
1819
errorParser?: IErrorParser;
1920
lastReferenceIdManager?: ILastReferenceIdManager;

src/exceptionless.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,18 @@ import { Utils } from './Utils';
6464

6565
const defaults = Configuration.defaults;
6666
const settings = getDefaultsSettingsFromScriptTag();
67-
if (settings && (settings.apiKey || settings.serverUrl)) {
68-
defaults.apiKey = settings.apiKey;
69-
defaults.serverUrl = settings.serverUrl;
67+
if (settings) {
68+
if (settings.apiKey) {
69+
defaults.apiKey = settings.apiKey;
70+
}
71+
72+
if (settings.serverUrl) {
73+
defaults.serverUrl = settings.serverUrl;
74+
}
75+
76+
if (settings.includePrivateInformation) {
77+
defaults.includePrivateInformation = settings.includePrivateInformation;
78+
}
7079
}
7180

7281
defaults.errorParser = new DefaultErrorParser();

src/services/DefaultRequestInfoCollector.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ export class DefaultRequestInfoCollector implements IRequestInfoCollector {
99
return null;
1010
}
1111

12-
const exclusions = context.client.config.dataExclusions;
12+
const config = context.client.config;
13+
const exclusions = config.dataExclusions;
1314
const requestInfo: IRequestInfo = {
1415
user_agent: navigator.userAgent,
1516
is_secure: location.protocol === 'https:',
1617
host: location.hostname,
1718
port: location.port && location.port !== '' ? parseInt(location.port, 10) : 80,
18-
path: location.pathname,
19-
// client_ip_address: 'TODO',
20-
cookies: Utils.getCookies(document.cookie, exclusions),
21-
query_string: Utils.parseQueryString(location.search.substring(1), exclusions)
19+
path: location.pathname
20+
// client_ip_address: 'TODO'
2221
};
2322

23+
if (config.includeCookies) {
24+
requestInfo.cookies = Utils.getCookies(document.cookie, exclusions);
25+
}
26+
27+
if (config.includeQueryString) {
28+
requestInfo.query_string = Utils.parseQueryString(location.search.substring(1), exclusions);
29+
}
30+
2431
if (document.referrer && document.referrer !== '') {
2532
requestInfo.referrer = document.referrer;
2633
}

src/services/NodeEnvironmentInfoCollector.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export class NodeEnvironmentInfoCollector implements IEnvironmentInfoCollector {
3636
architecture: os.arch(),
3737
o_s_name: os.type(),
3838
o_s_version: os.release(),
39-
ip_address: getIpAddresses(),
40-
machine_name: os.hostname(),
4139
// install_id: '',
4240
runtime_version: process.version,
4341
data: {
@@ -48,6 +46,15 @@ export class NodeEnvironmentInfoCollector implements IEnvironmentInfoCollector {
4846
}
4947
};
5048

49+
const config = context.client.config;
50+
if (config.includeMachineName) {
51+
environmentInfo.machine_name = os.hostname();
52+
}
53+
54+
if (config.includeIpAddress) {
55+
environmentInfo.ip_address = getIpAddresses();
56+
}
57+
5158
if ((os as any).endianness) {
5259
environmentInfo.data.endianness = (os as any).endianness();
5360
}

src/services/NodeRequestInfoCollector.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ export class NodeRequestInfoCollector implements IRequestInfoCollector {
1010
return null;
1111
}
1212

13-
const exclusions = context.client.config.dataExclusions;
13+
const config = context.client.config;
14+
const exclusions = config.dataExclusions;
1415

1516
// TODO: include referrer
1617
const request = context.contextData[REQUEST_KEY];
1718
const requestInfo: IRequestInfo = {
18-
client_ip_address: request.ip,
1919
user_agent: request.headers['user-agent'],
2020
is_secure: request.secure,
2121
http_method: request.method,
2222
host: request.hostname || request.host,
23-
path: request.path,
24-
post_data: JSON.parse(Utils.stringify(request.body || {}, exclusions)),
25-
cookies: Utils.getCookies(request.headers.cookie, exclusions),
26-
query_string: JSON.parse(Utils.stringify(request.params || {}, exclusions))
23+
path: request.path
2724
};
2825

2926
const host = request.headers.host;
@@ -32,6 +29,22 @@ export class NodeRequestInfoCollector implements IRequestInfoCollector {
3229
requestInfo.port = port;
3330
}
3431

32+
if (config.includeIpAddress) {
33+
requestInfo.client_ip_address = request.ip;
34+
}
35+
36+
if (config.includeCookies) {
37+
requestInfo.cookies = Utils.getCookies(request.headers.cookie, exclusions);
38+
}
39+
40+
if (config.includeQueryString) {
41+
requestInfo.query_string = JSON.parse(Utils.stringify(request.params || {}, exclusions));
42+
}
43+
44+
if (config.includePostData) {
45+
requestInfo.post_data = JSON.parse(Utils.stringify(request.body || {}, exclusions));
46+
}
47+
3548
return requestInfo;
3649
}
3750
}

0 commit comments

Comments
 (0)