Skip to content

Commit 163dc8d

Browse files
committed
Simplify error messages to dedupe and avoid any leaked usernames
It would be possible for usernames to leak as part of the paths for some kinds of errors (e.g. no disk space remaining failures). We already handled this in exception details, but not the overall message, to this filters that too.
1 parent 2a37990 commit 163dc8d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/error-tracking.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,14 @@ export function initErrorTracking() {
6565
return breadcrumb;
6666
},
6767
beforeSend(event, hint) {
68+
if (event.message) {
69+
event.message = simplifyErrorMessages(event.message);
70+
}
71+
6872
if (event.exception && event.exception.values) {
6973
event.exception.values.forEach((value) => {
7074
if (!value.value) return;
71-
value.value = value.value
72-
// Strip any usernames that end up appearing within error values.
73-
// This helps to dedupe error reports, and it's good for privacy too
74-
.replace(/\/home\/[^\/]+\//g, '/home/<username>/')
75-
.replace(/\/Users\/[^\/]+\//g, '/Users/<username>/')
76-
.replace(/(\w):\\Users\\[^\\]+\\/gi, '$1:\\Users\\<username>\\')
77-
// Dedupe temp filenames in errors (from terminal script setup)
78-
.replace(/([a-zA-Z]+)\d{12,}\.temp/g, '$1<number>.temp');
75+
value.value = simplifyErrorMessages(value.value);
7976
});
8077
}
8178

@@ -118,6 +115,16 @@ export function initErrorTracking() {
118115
}
119116
}
120117

118+
const simplifyErrorMessages = (input: string): string =>
119+
input
120+
// Strip any usernames that end up appearing within error values.
121+
// This helps to dedupe error reports, and it's good for privacy too
122+
.replace(/\/home\/[^\/]+\//g, '/home/<username>/')
123+
.replace(/\/Users\/[^\/]+\//g, '/Users/<username>/')
124+
.replace(/(\w):\\Users\\[^\\]+\\/gi, '$1:\\Users\\<username>\\')
125+
// Dedupe temp filenames in errors (from terminal script setup)
126+
.replace(/([a-zA-Z]+)\d{12,}\.temp/g, '$1<number>.temp');
127+
121128
export function addBreadcrumb(message: string, data: Sentry.Breadcrumb) {
122129
Sentry.addBreadcrumb(Object.assign({ message }, data));
123130
}

0 commit comments

Comments
 (0)