Skip to content

Commit c9f956b

Browse files
authored
fix: Make sure that body is not exposed in the breadcrumb by default (#2911)
1 parent dcba3fb commit c9f956b

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ import {
1111
safeJoin,
1212
} from '@sentry/utils';
1313

14-
/**
15-
* @hidden
16-
*/
17-
export interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
18-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19-
[key: string]: any;
20-
__sentry_xhr__?: {
21-
method?: string;
22-
url?: string;
23-
status_code?: number;
24-
};
25-
}
26-
2714
/** JSDoc */
2815
interface BreadcrumbsOptions {
2916
console: boolean;
@@ -212,15 +199,21 @@ export class Breadcrumbs implements Integration {
212199
return;
213200
}
214201

202+
const { method, url, status_code, body } = handlerData.xhr.__sentry_xhr__ || {};
203+
215204
getCurrentHub().addBreadcrumb(
216205
{
217206
category: 'xhr',
218-
data: handlerData.xhr.__sentry_xhr__,
207+
data: {
208+
method,
209+
url,
210+
status_code,
211+
},
219212
type: 'http',
220213
},
221214
{
222215
xhr: handlerData.xhr,
223-
...(handlerData.xhr.__sentry_xhr__.body && { input: handlerData.xhr.__sentry_xhr__.body }),
216+
input: body,
224217
},
225218
);
226219

packages/browser/test/integration/suites/breadcrumbs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ describe("breadcrumbs", function() {
8080
assert.equal(summary.breadcrumbs[0].type, "http");
8181
assert.equal(summary.breadcrumbs[0].category, "xhr");
8282
assert.equal(summary.breadcrumbs[0].data.method, "GET");
83+
assert.isUndefined(summary.breadcrumbs[0].data.input);
8384
// To make sure that we are not providing this key for non-post requests
8485
assert.equal(summary.breadcrumbHints[0].input, undefined);
8586
});
@@ -109,6 +110,7 @@ describe("breadcrumbs", function() {
109110
assert.equal(summary.breadcrumbs[0].type, "http");
110111
assert.equal(summary.breadcrumbs[0].category, "xhr");
111112
assert.equal(summary.breadcrumbs[0].data.method, "POST");
113+
assert.isUndefined(summary.breadcrumbs[0].data.input);
112114
assert.equal(summary.breadcrumbHints[0].input, '{"foo":"bar"}');
113115
});
114116
}

0 commit comments

Comments
 (0)