Skip to content

Commit

Permalink
fix: Only set ip.address: '{{auto}}' when sendDefaultPii: true (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish authored Feb 14, 2025
1 parent 0e13866 commit 9175622
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/test-apps/other/no-pii/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Event } from '@sentry/core';
import { expect } from 'vitest';

import { TestServerEvent } from '../../../server';

export async function execute(events: TestServerEvent<Event>[]): Promise<void> {
expect(events.length).greaterThanOrEqual(1);

for (const event of events) {
expect(event.data.user?.ip_address).toBeUndefined();
}
}
8 changes: 8 additions & 0 deletions test/e2e/test-apps/other/no-pii/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "javascript-no-pii",
"version": "1.0.0",
"main": "src/main.js",
"dependencies": {
"@sentry/electron": "5.6.0"
}
}
3 changes: 3 additions & 0 deletions test/e2e/test-apps/other/no-pii/recipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: No PII
category: JavaScript
command: yarn
19 changes: 19 additions & 0 deletions test/e2e/test-apps/other/no-pii/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<script>
const { init } = require('@sentry/electron/renderer');

init({
debug: true,
});

setTimeout(() => {
throw new Error('Some renderer error');
}, 500);
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions test/e2e/test-apps/other/no-pii/src/main.js
Original file line number Diff line number Diff line change
@@ -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'));
});

0 comments on commit 9175622

Please sign in to comment.