-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Crash report via Sentry #3348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
xen2
wants to merge
12
commits into
stride3d:master
Choose a base branch
from
xen2:feature/crash-report-sentry
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Crash report via Sentry #3348
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
52c9aff
Remove duplicate Stride.Editor.CrashReport project reference
xen2 4856814
Crash report: optional upload to Sentry
xen2 b5d11d4
Crash report: send only basic GPU fields
xen2 ff308d5
Crash report: map data onto Sentry structures, opt-in minidump
xen2 8afd36e
Crash report: adapter/API, CPU model, memory state, longer log
xen2 a589570
Crash report: optional name/email/description feedback
xen2 0591c50
Crash report window: theme fallback and layout polish
xen2 6a7bfa4
Crash report: mask user name and profile path inside minidumps
xen2 a437074
Crash report: save a minidump or full memory dump locally
xen2 ad1124c
Crash report window: destination notice, default button, and polish
xen2 f5f2081
Crash report: dev channel DSN, keep only the anonymous install id
xen2 c0899ec
Crash report: prevent Sentry geolocation
xen2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
sources/editor/Stride.Editor.CrashReport/CrashReportAnonymizer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| // Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) | ||
| // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| namespace Stride.Editor.CrashReport; | ||
|
|
||
| /// <summary> | ||
| /// Strips the user name and profile path from crash report text before it leaves the machine. | ||
| /// It also makes paths easier to copy and paste between machines. | ||
| /// </summary> | ||
| public static class CrashReportAnonymizer | ||
| { | ||
| public static void Scrub(CrashReportData report) | ||
| { | ||
| for (var i = 0; i < report.Data.Count; i++) | ||
| { | ||
| report.Data[i] = (report.Data[i].Item1, Scrub(report.Data[i].Item2)); | ||
| } | ||
| } | ||
|
|
||
| public static string Scrub(string text) | ||
| { | ||
| if (string.IsNullOrEmpty(text)) | ||
| return text; | ||
|
|
||
| var userProfile = Environment.GetEnvironmentVariable("USERPROFILE"); | ||
| if (!string.IsNullOrEmpty(userProfile)) | ||
| text = Regex.Replace(text, Regex.Escape(userProfile), "%USERPROFILE%", RegexOptions.IgnoreCase); | ||
|
|
||
| var userName = Environment.GetEnvironmentVariable("USERNAME"); | ||
| if (!string.IsNullOrEmpty(userName)) | ||
| text = Regex.Replace(text, $@"\b{Regex.Escape(userName)}\b", "%USERNAME%", RegexOptions.IgnoreCase); | ||
|
|
||
| return text; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Masks the profile path and user name inside a region of a binary buffer (e.g. minidump strings and | ||
| /// memory ranges), in both ASCII and UTF-16. Binary offsets cannot shift, so matches are overwritten | ||
| /// in place with same-length 'x' runs. | ||
| /// </summary> | ||
| public static void Scrub(byte[] buffer, int offset, int length) | ||
| { | ||
| Scrub(buffer, offset, length, | ||
| Environment.GetEnvironmentVariable("USERPROFILE"), | ||
| Environment.GetEnvironmentVariable("USERNAME")); | ||
| } | ||
|
|
||
| public static void Scrub(byte[] buffer, int offset, int length, string userProfile, string userName) | ||
| { | ||
| if (!string.IsNullOrEmpty(userProfile)) | ||
| MaskAllEncodings(buffer, offset, length, userProfile, requireBoundary: false); | ||
| if (!string.IsNullOrEmpty(userName)) | ||
| MaskAllEncodings(buffer, offset, length, userName, requireBoundary: true); | ||
| } | ||
|
|
||
| private static void MaskAllEncodings(byte[] buffer, int offset, int length, string text, bool requireBoundary) | ||
| { | ||
| if (text.All(char.IsAscii)) | ||
| { | ||
| Mask(buffer, offset, length, text, 1, requireBoundary); | ||
| Mask(buffer, offset, length, text, 2, requireBoundary); | ||
| return; | ||
| } | ||
|
|
||
| // Non-ASCII: per-character case folding does not survive multi-byte encodings, so match the exact | ||
| // byte patterns of the realistic casings in each encoding instead | ||
| foreach (var variant in new[] { text, text.ToLowerInvariant(), text.ToUpperInvariant() }.Distinct()) | ||
| { | ||
| MaskPattern(buffer, offset, length, Encoding.Unicode.GetBytes(variant), 2, requireBoundary); | ||
| MaskPattern(buffer, offset, length, Encoding.UTF8.GetBytes(variant), 1, requireBoundary); | ||
| if (variant.All(c => c <= 0xFF)) | ||
| MaskPattern(buffer, offset, length, Encoding.Latin1.GetBytes(variant), 1, requireBoundary); | ||
| } | ||
| } | ||
|
|
||
| private static void MaskPattern(byte[] buffer, int offset, int length, byte[] pattern, int stride, bool requireBoundary) | ||
| { | ||
| var end = Math.Min(offset + length, buffer.Length); | ||
| for (var i = Math.Max(offset, 0); i + pattern.Length <= end; i++) | ||
| { | ||
| var match = true; | ||
| for (var j = 0; j < pattern.Length && match; j++) | ||
| match = buffer[i + j] == pattern[j]; | ||
| if (!match) | ||
| continue; | ||
| if (requireBoundary && (IsWordChar(buffer, i - stride, stride) || IsWordChar(buffer, i + pattern.Length, stride))) | ||
| continue; | ||
|
|
||
| for (var j = 0; j < pattern.Length; j++) | ||
| buffer[i + j] = (byte)(stride == 2 && j % 2 == 1 ? 0 : 'x'); | ||
| i += pattern.Length - 1; | ||
| } | ||
| } | ||
|
|
||
| /// <summary>Case-insensitive search and mask at the given character stride (1 = ASCII, 2 = UTF-16).</summary> | ||
| private static void Mask(byte[] buffer, int offset, int length, string text, int stride, bool requireBoundary) | ||
| { | ||
| var end = Math.Min(offset + length, buffer.Length); | ||
| for (var i = Math.Max(offset, 0); i + text.Length * stride <= end; i++) | ||
| { | ||
| var match = true; | ||
| for (var j = 0; j < text.Length && match; j++) | ||
| { | ||
| var c = (char)buffer[i + j * stride]; | ||
| if (stride == 2 && buffer[i + j * stride + 1] != 0) | ||
| match = false; | ||
| else | ||
| match = char.ToLowerInvariant(c) == char.ToLowerInvariant(text[j]); | ||
| } | ||
| if (!match) | ||
| continue; | ||
| if (requireBoundary && (IsWordChar(buffer, i - stride, stride) || IsWordChar(buffer, i + text.Length * stride, stride))) | ||
| continue; | ||
|
|
||
| for (var j = 0; j < text.Length; j++) | ||
| { | ||
| buffer[i + j * stride] = (byte)'x'; | ||
| if (stride == 2) | ||
| buffer[i + j * stride + 1] = 0; | ||
| } | ||
| i += text.Length * stride - 1; | ||
| } | ||
| } | ||
|
|
||
| private static bool IsWordChar(byte[] buffer, int index, int stride) | ||
| { | ||
| if (index < 0 || index + stride > buffer.Length) | ||
| return false; | ||
| if (stride == 2 && buffer[index + 1] != 0) | ||
| return false; | ||
| var c = (char)buffer[index]; | ||
| return char.IsLetterOrDigit(c) || c == '_'; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're calling OS-specific code. I know GameStudio isn't cross-platform yet, but it's worth having these checks somewhere in place for the future. But its just a nitpick 😅️
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, now that I think about it, we could move AppHelper to a new folder called "Desktop" (or Core?). The same thing goes with FileLock.cs (its fully xplat now)