Skip to content

Commit 8308237

Browse files
committed
Ensure no sensitive HTTP data can be collected in error breadcrumbs
1 parent eedd199 commit 8308237

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/error-tracking.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,39 @@ export function initErrorTracking() {
1313
}
1414

1515
if (SENTRY_DSN) {
16-
Sentry.init({ dsn: SENTRY_DSN, release: packageJson.version });
16+
Sentry.init({
17+
dsn: SENTRY_DSN,
18+
release: packageJson.version,
19+
beforeBreadcrumb(breadcrumb, hint) {
20+
if (breadcrumb.category === 'http') {
21+
// Almost all HTTP requests sent by the server are actually forwarded HTTP from
22+
// the proxy, so could be very sensitive. We need to ensure errors don't leak data.
23+
24+
// Remove all but the host from the breadcrumb data. The host is fairly safe & often
25+
// useful for context, but the path & query could easily contain sensitive secrets.
26+
if (breadcrumb.data && breadcrumb.data.url) {
27+
const url = breadcrumb.data.url as string;
28+
const hostIndex = url.indexOf('://') + 3;
29+
const pathIndex = url.indexOf('/', hostIndex);
30+
if (pathIndex !== -1) {
31+
breadcrumb.data.url = url.slice(0, pathIndex);
32+
}
33+
}
34+
35+
if (hint) {
36+
// Make sure we don't collect the full HTTP data in hints either.
37+
delete hint.request;
38+
delete hint.response;
39+
}
40+
}
41+
return breadcrumb;
42+
}
43+
});
44+
1745
Sentry.configureScope((scope) => {
1846
scope.setTag('platform', process.platform);
1947
});
48+
2049
sentryInitialized = true;
2150
}
2251
}

0 commit comments

Comments
 (0)