Skip to content

Commit c9b05b2

Browse files
committed
feat(core)!: Stop setting user in requestDataIntegration
This was an express-specific, rather undocumented behavior, and also conflicted with our privacy-by-default stance. Starting in v9, you'll need to manually call `Sentry.setUser()` e.g. in a middleware to set the user on Sentry events. Docs for this are already pending: getsentry/sentry-docs#12224
1 parent 64d36a9 commit c9b05b2

File tree

12 files changed

+8
-95
lines changed

12 files changed

+8
-95
lines changed

docs/migration/v8-to-v9.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ In v9, an `undefined` value will be treated the same as if the value is not defi
8484

8585
- When `skipOpenTelemetrySetup: true` is configured, `httpIntegration({ spans: false })` will be configured by default. This means that you no longer have to specify this yourself in this scenario. With this change, no spans are emitted once `skipOpenTelemetrySetup: true` is configured, without any further configuration being needed.
8686

87+
- The `requestDataIntegration` will no longer automatically set the user from `request.user`. This is an express-specific, undocumented behavior, and also conflicts with our privacy-by-default strategy. Starting in v9, you'll need to manually call `Sentry.setUser()` e.g. in a middleware to set the user on Sentry events.
88+
8789
### `@sentry/browser`
8890

8991
- The `captureUserFeedback` method has been removed. Use `captureFeedback` instead and update the `comments` field to `message`.
@@ -128,6 +130,8 @@ Sentry.init({
128130
});
129131
```
130132

133+
- The `DEFAULT_USER_INCLUDES` constant has been removed.
134+
131135
### `@sentry/react`
132136

133137
- The `wrapUseRoutes` method has been removed. Use `wrapUseRoutesV6` or `wrapUseRoutesV7` instead depending on what version of react router you are using.

packages/astro/src/index.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export {
3333
cron,
3434
dataloaderIntegration,
3535
dedupeIntegration,
36-
DEFAULT_USER_INCLUDES,
3736
defaultStackParser,
3837
endSession,
3938
expressErrorHandler,

packages/aws-serverless/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export {
4444
getSentryRelease,
4545
// eslint-disable-next-line deprecation/deprecation
4646
addRequestDataToEvent,
47-
DEFAULT_USER_INCLUDES,
4847
// eslint-disable-next-line deprecation/deprecation
4948
extractRequestData,
5049
createGetModuleFromFilename,

packages/bun/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export {
6464
getSentryRelease,
6565
// eslint-disable-next-line deprecation/deprecation
6666
addRequestDataToEvent,
67-
DEFAULT_USER_INCLUDES,
6867
// eslint-disable-next-line deprecation/deprecation
6968
extractRequestData,
7069
createGetModuleFromFilename,

packages/core/src/integrations/requestdata.ts

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ export type RequestDataIntegrationOptions = {
1717
ip?: boolean;
1818
query_string?: boolean;
1919
url?: boolean;
20-
user?:
21-
| boolean
22-
| {
23-
id?: boolean;
24-
username?: boolean;
25-
email?: boolean;
26-
};
2720
};
2821

2922
/**
@@ -41,11 +34,6 @@ const DEFAULT_OPTIONS = {
4134
ip: false,
4235
query_string: true,
4336
url: true,
44-
user: {
45-
id: true,
46-
username: true,
47-
email: true,
48-
},
4937
},
5038
transactionNamingScheme: 'methodPath' as const,
5139
};
@@ -59,14 +47,6 @@ const _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) =
5947
include: {
6048
...DEFAULT_OPTIONS.include,
6149
...options.include,
62-
user:
63-
options.include && typeof options.include.user === 'boolean'
64-
? options.include.user
65-
: {
66-
...DEFAULT_OPTIONS.include.user,
67-
// Unclear why TS still thinks `options.include.user` could be a boolean at this point
68-
...((options.include || {}).user as Record<string, boolean>),
69-
},
7050
},
7151
};
7252

@@ -87,9 +67,8 @@ const _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) =
8767
if (normalizedRequest) {
8868
// Some other data is not available in standard HTTP requests, but can sometimes be augmented by e.g. Express or Next.js
8969
const ipAddress = request ? request.ip || (request.socket && request.socket.remoteAddress) : undefined;
90-
const user = request ? request.user : undefined;
9170

92-
addNormalizedRequestDataToEvent(event, normalizedRequest, { ipAddress, user }, addRequestDataOptions);
71+
addNormalizedRequestDataToEvent(event, normalizedRequest, { ipAddress }, addRequestDataOptions);
9372
return event;
9473
}
9574

@@ -118,7 +97,7 @@ function convertReqDataIntegrationOptsToAddReqDataOpts(
11897
const {
11998
// eslint-disable-next-line deprecation/deprecation
12099
transactionNamingScheme,
121-
include: { ip, user, ...requestOptions },
100+
include: { ip, ...requestOptions },
122101
} = integrationOptions;
123102

124103
const requestIncludeKeys: string[] = ['method'];
@@ -128,25 +107,9 @@ function convertReqDataIntegrationOptsToAddReqDataOpts(
128107
}
129108
}
130109

131-
let addReqDataUserOpt;
132-
if (user === undefined) {
133-
addReqDataUserOpt = true;
134-
} else if (typeof user === 'boolean') {
135-
addReqDataUserOpt = user;
136-
} else {
137-
const userIncludeKeys: string[] = [];
138-
for (const [key, value] of Object.entries(user)) {
139-
if (value) {
140-
userIncludeKeys.push(key);
141-
}
142-
}
143-
addReqDataUserOpt = userIncludeKeys;
144-
}
145-
146110
return {
147111
include: {
148112
ip,
149-
user: addReqDataUserOpt,
150113
request: requestIncludeKeys.length !== 0 ? requestIncludeKeys : undefined,
151114
transaction: transactionNamingScheme,
152115
},

packages/core/src/utils-hoist/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export type { PromiseBuffer } from './promisebuffer';
6666

6767
// TODO: Remove requestdata export once equivalent integration is used everywhere
6868
export {
69-
DEFAULT_USER_INCLUDES,
7069
addNormalizedRequestDataToEvent,
7170
// eslint-disable-next-line deprecation/deprecation
7271
addRequestDataToEvent,

packages/core/src/utils-hoist/requestdata.ts

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ import { getClientIPAddress, ipHeaderNames } from './vendor/getIpAddress';
2222
const DEFAULT_INCLUDES = {
2323
ip: false,
2424
request: true,
25-
user: true,
2625
};
2726
const DEFAULT_REQUEST_INCLUDES = ['cookies', 'data', 'headers', 'method', 'query_string', 'url'];
28-
export const DEFAULT_USER_INCLUDES = ['id', 'username', 'email'];
2927

3028
/**
3129
* Options deciding what parts of the request to use when enhancing an event
@@ -38,7 +36,6 @@ export type AddRequestDataToEventOptions = {
3836
/** @deprecated This option will be removed in v9. It does not do anything anymore, the `transcation` is set in other places. */
3937
// eslint-disable-next-line deprecation/deprecation
4038
transaction?: boolean | 'path' | 'methodPath' | 'handler';
41-
user?: boolean | Array<(typeof DEFAULT_USER_INCLUDES)[number]>;
4239
};
4340

4441
/** Injected platform-specific dependencies */
@@ -103,24 +100,6 @@ export function extractPathForTransaction(
103100
return [name, source];
104101
}
105102

106-
function extractUserData(
107-
user: {
108-
[key: string]: unknown;
109-
},
110-
keys: boolean | string[],
111-
): { [key: string]: unknown } {
112-
const extractedUser: { [key: string]: unknown } = {};
113-
const attributes = Array.isArray(keys) ? keys : DEFAULT_USER_INCLUDES;
114-
115-
attributes.forEach(key => {
116-
if (user && key in user) {
117-
extractedUser[key] = user[key];
118-
}
119-
});
120-
121-
return extractedUser;
122-
}
123-
124103
/**
125104
* Normalize data from the request object, accounting for framework differences.
126105
*
@@ -260,7 +239,7 @@ export function addNormalizedRequestDataToEvent(
260239
event: Event,
261240
req: RequestEventData,
262241
// This is non-standard data that is not part of the regular HTTP request
263-
additionalData: { ipAddress?: string; user?: Record<string, unknown> },
242+
additionalData: { ipAddress?: string },
264243
options: AddRequestDataToEventOptions,
265244
): void {
266245
const include = {
@@ -282,20 +261,6 @@ export function addNormalizedRequestDataToEvent(
282261
};
283262
}
284263

285-
if (include.user) {
286-
const extractedUser =
287-
additionalData.user && isPlainObject(additionalData.user)
288-
? extractUserData(additionalData.user, include.user)
289-
: {};
290-
291-
if (Object.keys(extractedUser).length) {
292-
event.user = {
293-
...extractedUser,
294-
...event.user,
295-
};
296-
}
297-
}
298-
299264
if (include.ip) {
300265
const ip = (req.headers && getClientIPAddress(req.headers)) || additionalData.ipAddress;
301266
if (ip) {
@@ -343,17 +308,6 @@ export function addRequestDataToEvent(
343308
};
344309
}
345310

346-
if (include.user) {
347-
const extractedUser = req.user && isPlainObject(req.user) ? extractUserData(req.user, include.user) : {};
348-
349-
if (Object.keys(extractedUser).length) {
350-
event.user = {
351-
...event.user,
352-
...extractedUser,
353-
};
354-
}
355-
}
356-
357311
// client ip:
358312
// node, nextjs: req.socket.remoteAddress
359313
// express, koa: req.ip

packages/google-cloud-serverless/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export {
4444
getSentryRelease,
4545
// eslint-disable-next-line deprecation/deprecation
4646
addRequestDataToEvent,
47-
DEFAULT_USER_INCLUDES,
4847
// eslint-disable-next-line deprecation/deprecation
4948
extractRequestData,
5049
createGetModuleFromFilename,

packages/node/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export { cron } from './cron';
5555
export type { NodeOptions } from './types';
5656

5757
// eslint-disable-next-line deprecation/deprecation
58-
export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from '@sentry/core';
58+
export { addRequestDataToEvent, extractRequestData } from '@sentry/core';
5959

6060
export {
6161
// This needs exporting so the NodeClient can be used without calling init

packages/remix/src/index.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export {
3636
createTransport,
3737
cron,
3838
dedupeIntegration,
39-
DEFAULT_USER_INCLUDES,
4039
defaultStackParser,
4140
endSession,
4241
expressErrorHandler,

packages/solidstart/src/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export {
2828
createTransport,
2929
cron,
3030
dedupeIntegration,
31-
DEFAULT_USER_INCLUDES,
3231
defaultStackParser,
3332
endSession,
3433
expressErrorHandler,

packages/sveltekit/src/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export {
2828
createTransport,
2929
cron,
3030
dedupeIntegration,
31-
DEFAULT_USER_INCLUDES,
3231
defaultStackParser,
3332
endSession,
3433
expressErrorHandler,

0 commit comments

Comments
 (0)