From b62cd243a925052b2b503105c5a6811e79b08fff Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 13 Feb 2025 12:58:21 +0100 Subject: [PATCH 1/2] fix: Only set `ip.address: '{{auto}}'` when `sendDefaultPii: true` --- src/main/sdk.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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(); From 7c5ea0a1c5aee48e69d45a2f409e49db93bcff0a Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Fri, 14 Feb 2025 11:17:21 +0100 Subject: [PATCH 2/2] Add test! --- test/e2e/test-apps/other/no-pii/events.ts | 12 ++++++++++ test/e2e/test-apps/other/no-pii/package.json | 8 +++++++ test/e2e/test-apps/other/no-pii/recipe.yml | 3 +++ .../e2e/test-apps/other/no-pii/src/index.html | 19 +++++++++++++++ test/e2e/test-apps/other/no-pii/src/main.js | 23 +++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 test/e2e/test-apps/other/no-pii/events.ts create mode 100644 test/e2e/test-apps/other/no-pii/package.json create mode 100644 test/e2e/test-apps/other/no-pii/recipe.yml create mode 100644 test/e2e/test-apps/other/no-pii/src/index.html create mode 100644 test/e2e/test-apps/other/no-pii/src/main.js 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')); +});