diff --git a/src/main/sdk.ts b/src/main/sdk.ts index c5cc6148..b1b987d7 100644 --- a/src/main/sdk.ts +++ b/src/main/sdk.ts @@ -182,8 +182,10 @@ export function init(userOptions: ElectronMainOptions): void { const client = new NodeClient(options); - client.on('postprocessEvent', addAutoIpAddressToUser); - client.on('beforeSendSession', addAutoIpAddressToSession); + if (options.sendDefaultPii === true) { + client.on('postprocessEvent', addAutoIpAddressToUser); + client.on('beforeSendSession', addAutoIpAddressToSession); + } scope.setClient(client); client.init(); diff --git a/test/e2e/test-apps/other/no-pii/events.ts b/test/e2e/test-apps/other/no-pii/events.ts new file mode 100644 index 00000000..c96e2433 --- /dev/null +++ b/test/e2e/test-apps/other/no-pii/events.ts @@ -0,0 +1,12 @@ +import { Event } from '@sentry/core'; +import { expect } from 'vitest'; + +import { TestServerEvent } from '../../../server'; + +export async function execute(events: TestServerEvent[]): Promise { + expect(events.length).greaterThanOrEqual(1); + + for (const event of events) { + expect(event.data.user?.ip_address).toBeUndefined(); + } +} diff --git a/test/e2e/test-apps/other/no-pii/package.json b/test/e2e/test-apps/other/no-pii/package.json new file mode 100644 index 00000000..93f0409d --- /dev/null +++ b/test/e2e/test-apps/other/no-pii/package.json @@ -0,0 +1,8 @@ +{ + "name": "javascript-no-pii", + "version": "1.0.0", + "main": "src/main.js", + "dependencies": { + "@sentry/electron": "5.6.0" + } +} diff --git a/test/e2e/test-apps/other/no-pii/recipe.yml b/test/e2e/test-apps/other/no-pii/recipe.yml new file mode 100644 index 00000000..9fde876f --- /dev/null +++ b/test/e2e/test-apps/other/no-pii/recipe.yml @@ -0,0 +1,3 @@ +description: No PII +category: JavaScript +command: yarn diff --git a/test/e2e/test-apps/other/no-pii/src/index.html b/test/e2e/test-apps/other/no-pii/src/index.html new file mode 100644 index 00000000..537391c9 --- /dev/null +++ b/test/e2e/test-apps/other/no-pii/src/index.html @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/test/e2e/test-apps/other/no-pii/src/main.js b/test/e2e/test-apps/other/no-pii/src/main.js new file mode 100644 index 00000000..f7574f9a --- /dev/null +++ b/test/e2e/test-apps/other/no-pii/src/main.js @@ -0,0 +1,23 @@ +const path = require('path'); + +const { app, BrowserWindow } = require('electron'); +const { init } = require('@sentry/electron/main'); + +init({ + dsn: '__DSN__', + debug: true, + integrations: (integrations) => integrations.filter((i) => i.name !== 'MainProcessSession'), + onFatalError: () => {}, +}); + +app.on('ready', () => { + const mainWindow = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + }, + }); + + mainWindow.loadFile(path.join(__dirname, 'index.html')); +});