Skip to content

Commit

Permalink
Simplify error messages to dedupe and avoid any leaked usernames
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pimterry committed Jun 18, 2024
1 parent 2a37990 commit 163dc8d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/error-tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@ export function initErrorTracking() {
return breadcrumb;
},
beforeSend(event, hint) {
if (event.message) {
event.message = simplifyErrorMessages(event.message);
}

if (event.exception && event.exception.values) {
event.exception.values.forEach((value) => {
if (!value.value) return;
value.value = value.value
// Strip any usernames that end up appearing within error values.
// This helps to dedupe error reports, and it's good for privacy too
.replace(/\/home\/[^\/]+\//g, '/home/<username>/')
.replace(/\/Users\/[^\/]+\//g, '/Users/<username>/')
.replace(/(\w):\\Users\\[^\\]+\\/gi, '$1:\\Users\\<username>\\')
// Dedupe temp filenames in errors (from terminal script setup)
.replace(/([a-zA-Z]+)\d{12,}\.temp/g, '$1<number>.temp');
value.value = simplifyErrorMessages(value.value);
});
}

Expand Down Expand Up @@ -118,6 +115,16 @@ export function initErrorTracking() {
}
}

const simplifyErrorMessages = (input: string): string =>
input
// Strip any usernames that end up appearing within error values.
// This helps to dedupe error reports, and it's good for privacy too
.replace(/\/home\/[^\/]+\//g, '/home/<username>/')
.replace(/\/Users\/[^\/]+\//g, '/Users/<username>/')
.replace(/(\w):\\Users\\[^\\]+\\/gi, '$1:\\Users\\<username>\\')
// Dedupe temp filenames in errors (from terminal script setup)
.replace(/([a-zA-Z]+)\d{12,}\.temp/g, '$1<number>.temp');

export function addBreadcrumb(message: string, data: Sentry.Breadcrumb) {
Sentry.addBreadcrumb(Object.assign({ message }, data));
}
Expand Down

0 comments on commit 163dc8d

Please sign in to comment.