mirror of
https://github.com/block/buzz.git
synced 2026-11-27 19:52:31 +00:00
fix(mobile): replace kept error text with a mail link query or a CR
A mailto: link carries a query without "://", so the URL guard let its subject through. Also replace a first line with a "?" or "#" that could start a query or fragment, keeping nullable types such as "List<String?>" readable. End the first line at a carriage return too, not only a line feed. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -4,7 +4,7 @@ A mobile build does [diagnostic reporting](../../CONTEXT.md#diagnostic-reporting
|
||||
|
||||
We chose this so that the open-source app carries no organization's destination and no rule about which organizations may collect reports, the same reasoning that keeps organization hosts out of the code in [ADR 0001](0001-internal-and-public-mobile-builds.md). The first use is an organization's internal build, where everyone who has the app is a member of the organization that reads the reports.
|
||||
|
||||
A report may carry the stack trace and error type, the first line of a Dart programmer error's message (a `StateError`, `TypeError`, `AssertionError` or `UnsupportedError`, whose text developers write) when it has no URL, app, operating system and device details, a trail of recent events written from a fixed list, the host names of the servers the app talks to, the signed-in member's public key, a random identifier the app creates for its installation, a random identifier the reporting SDK creates for the installation (which stands in as the user on reports sent while no one is signed in, and appears in the SDK's session records, which also carry when a session started, its length from start to end, how it ended and its error count), on iOS native crash and hang reports only, a hash the SDK computes from the identifier iOS gives the app's vendor, the hardware model and the app's bundle identifier (it stays the same across launches, and across a reinstall while another app from the same vendor stays installed) and, when the person is signed in to a Builderlab account, that Builderlab's origin and the account's subject identifier, never its email address. Networking measurements also carry the operation's name from a fixed list, its outcome, the kind of failure and how long it took. A report never carries message content, channel or community names, private keys or other secrets, or a URL's query string or fragment.
|
||||
A report may carry the stack trace and error type, the first line of a Dart programmer error's message (a `StateError`, `TypeError`, `AssertionError` or `UnsupportedError`, whose text developers write) when it has no URL and no `?` or `#` that could start a query or fragment, app, operating system and device details, a trail of recent events written from a fixed list, the host names of the servers the app talks to, the signed-in member's public key, a random identifier the app creates for its installation, a random identifier the reporting SDK creates for the installation (which stands in as the user on reports sent while no one is signed in, and appears in the SDK's session records, which also carry when a session started, its length from start to end, how it ended and its error count), on iOS native crash and hang reports only, a hash the SDK computes from the identifier iOS gives the app's vendor, the hardware model and the app's bundle identifier (it stays the same across launches, and across a reinstall while another app from the same vendor stays installed) and, when the person is signed in to a Builderlab account, that Builderlab's origin and the account's subject identifier, never its email address. Networking measurements also carry the operation's name from a fixed list, its outcome, the kind of failure and how long it took. A report never carries message content, channel or community names, private keys or other secrets, or a URL's query string or fragment.
|
||||
|
||||
## Considered options
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ A build that is given a [reporting destination](../CONTEXT.md#reporting-destinat
|
||||
- **No log lines in step one.** The counts carry the member and the time. The first implementation task confirms that the destination can filter counts by member; if it cannot, the fallback is one log line per outage, sent after it ends.
|
||||
- **Breadcrumbs come from a fixed list:** networking events, written by the app, and the app moving to the foreground or background, written by the SDK. The SDK's other automatic breadcrumbs, which could carry content or addresses, are turned off or filtered.
|
||||
- **Who a report is about.** The member's public key is set as the report's user when a session starts and cleared when it ends. When the session is a Builderlab account, the Builderlab's origin and the account's subject identifier are added, never its email address. Every report also carries the app's own random per-install identifier, created on first launch and kept in a file that device backups and transfers skip, so a phone restored from another gets its own, as a separate field, signed in or not, so reports from one device can be matched to the members who used it, and a member's reports to the devices they used. With no member set, for example before sign-in, the SDK fills the report's user with its own random per-install identifier, on Dart and native reports alike. On iOS, native crash and hang reports also carry the SDK's device app hash: a hash of the identifier iOS gives the app's vendor, the hardware model and the bundle identifier, stable across launches and across a reinstall while another app from the same vendor stays installed. The Dart filter drops it, so Dart reports don't carry it. The SDK also sends session records, so the destination can show a crash-free rate. A session begins each time the app starts or returns after 30 seconds or more in the background. The SDK sends a record when it begins, an update each time an error is counted, and a last record when it ends. Together they carry when the session started, how many errors it had, how it ended (normally, crashed or abnormally), the time from start to end (not time in active use), the release, the environment and the SDK's identifier.
|
||||
- **One filter before anything leaves.** Errors, breadcrumbs and counts from Dart all pass through a single filter that removes URL query strings and fragments, drops any attribute not on the allowed list, replaces every error's own text with fixed wording except for Dart's programmer-error types (`StateError`, `TypeError`, `AssertionError` and `UnsupportedError`, which includes `UnimplementedError`), whose first line is kept because developers write those messages and they make issue titles readable (a first line that contains a URL or is over 200 characters is replaced too), drops what the SDK adds about the failing widget or platform call, and keeps only the app, operating system, device and runtime details among the report's contexts, so the SDK's accessibility settings, locale and the device's own name stay on the device. An error keeps its type and stack trace. The accepted risk is a programmer-error message that interpolates a value. Flutter's `FlutterError` implements `AssertionError` but its text is still replaced. The SDK's options for sending personal data, screenshots, view hierarchies and session recordings stay off.
|
||||
- **One filter before anything leaves.** Errors, breadcrumbs and counts from Dart all pass through a single filter that removes URL query strings and fragments, drops any attribute not on the allowed list, replaces every error's own text with fixed wording except for Dart's programmer-error types (`StateError`, `TypeError`, `AssertionError` and `UnsupportedError`, which includes `UnimplementedError`), whose first line is kept because developers write those messages and they make issue titles readable (a first line that contains a URL or a `?` or `#` that could start a query or fragment, or is over 200 characters, is replaced too), drops what the SDK adds about the failing widget or platform call, and keeps only the app, operating system, device and runtime details among the report's contexts, so the SDK's accessibility settings, locale and the device's own name stay on the device. An error keeps its type and stack trace. The accepted risk is a programmer-error message that interpolates a value. Flutter's `FlutterError` implements `AssertionError` but its text is still replaced. The SDK's options for sending personal data, screenshots, view hierarchies and session recordings stay off.
|
||||
- **Main-thread hangs** are captured by the SDK's own hang detection, at the SDK's default thresholds. The app's Dart code runs on the platform's main thread, so Dart work that blocks it shows up here. On iOS, the SDK reports the main thread being blocked, fully or mostly, for 2 seconds or more while the app is active, with the main thread's stack taken during the hang, including freezes the app recovers from. A hang that is still going when the app is killed, for example by the system watchdog, is sent on the next launch as a fatal hang. The SDK's separate watchdog-termination tracking also reports, on the next launch, a run that ended while the app was in the foreground with nothing else to explain it; it never reports on simulators or for kills in the background. App hang detection is off while a debugger is attached ([sentry-cocoa 9.35.0](https://github.com/getsentry/sentry-cocoa/blob/9.35.0/Sources/Swift/Integrations/AppHangTracking/SentryHangTrackingIntegration.swift)). On Android the SDK reports only freezes the system itself declared "app not responding". On Android 11 and later it reports only one that ended the process, read from the system's exit records on the next launch: the most recent unreported one, and only when the system kept a usable thread dump. Before Android 11 it reports when the main thread has been blocked for 5 seconds and the system has marked the app not responding, never with a debugger attached ([sentry-java 8.64.0](https://github.com/getsentry/sentry-java/blob/8.64.0/sentry-android-core/src/main/java/io/sentry/android/core/AnrIntegrationFactory.java)). So with these defaults, a freeze the app recovers from is reported on iOS, and on Android only before Android 11 and only once the system has marked the app not responding. Dart frames in a hang's stack are readable only with the Dart code's debug symbols at the destination, the same as for crashes.
|
||||
- **Native reports skip that filter.** Native crashes and app hangs are captured and sent by the native SDKs, which never call the Dart filter. They carry stack traces and, for a native exception, its reason text. No app code puts content in a native exception today, and the SDK's native network breadcrumbs, which would carry request addresses, are off.
|
||||
- **Readable stack traces** need the build's debug symbols at the destination. Uploading them belongs to the release process of whoever distributes the build; this repository documents the requirement and adds nothing organization-specific.
|
||||
|
||||
@@ -136,17 +136,24 @@ abstract final class DiagnosticFilter {
|
||||
static const _keptTextLimit = 200;
|
||||
|
||||
/// The first line of a kept error's [text], or [removedText] when that line
|
||||
/// contains a URL or is long. Where a URL ends in free text is ambiguous, so
|
||||
/// none is kept. A long line, or the lines after the first, usually quote
|
||||
/// other text, such as a response body or a wrapped error.
|
||||
/// may hold a URL or is long. Where a URL ends in free text is ambiguous, so
|
||||
/// none is kept: a `://`, or a `?` or `#` that could start a query or
|
||||
/// fragment (a `mailto:` link has no `//`), replaces the line. A `?` or `#`
|
||||
/// followed by a space, quote, closing bracket or the end stays, so nullable
|
||||
/// types such as `List<String?>` keep a type error readable. A long line,
|
||||
/// or the lines after the first, usually quote other text, such as a
|
||||
/// response body or a wrapped error.
|
||||
static String _keptText(String text) {
|
||||
final newline = text.indexOf('\n');
|
||||
final line = newline < 0 ? text : text.substring(0, newline);
|
||||
return line.length > _keptTextLimit || line.contains('://')
|
||||
final lineEnd = text.indexOf(_lineBreak);
|
||||
final line = lineEnd < 0 ? text : text.substring(0, lineEnd);
|
||||
return line.length > _keptTextLimit || line.contains(_mayHoldUrl)
|
||||
? removedText
|
||||
: line;
|
||||
}
|
||||
|
||||
static final _lineBreak = RegExp('[\r\n]');
|
||||
static final _mayHoldUrl = RegExp(r'''://|[?#](?![\s'">,)\]}]|$)''');
|
||||
|
||||
static final _urlTail = RegExp(
|
||||
r'''(\b[a-z][a-z0-9+.-]*://[^\s?#'"]*)[?#][^\s'"]*''',
|
||||
caseSensitive: false,
|
||||
|
||||
@@ -225,6 +225,12 @@ void main() {
|
||||
'StateError',
|
||||
'Bad state: ref used after dispose',
|
||||
),
|
||||
(
|
||||
'a bad state split by a carriage return',
|
||||
StateError('ref used after dispose\rprivate-marker'),
|
||||
'StateError',
|
||||
'Bad state: ref used after dispose',
|
||||
),
|
||||
(
|
||||
'a failed assertion',
|
||||
AssertionError('list is sorted'),
|
||||
@@ -243,6 +249,12 @@ void main() {
|
||||
'Unimpl',
|
||||
'no export',
|
||||
),
|
||||
(
|
||||
'a bad state naming nullable types',
|
||||
StateError("wanted List<String?> or (int?, String?), got 'int?'"),
|
||||
'StateError',
|
||||
"wanted List<String?> or (int?, String?), got 'int?'",
|
||||
),
|
||||
('a failed cast', _failedCast(), 'TypeError', 'is not a subtype of'),
|
||||
];
|
||||
for (final (name, error, type, text) in kept) {
|
||||
@@ -254,6 +266,7 @@ void main() {
|
||||
expect(exception['type'], contains(type));
|
||||
expect(exception['value'], contains(text));
|
||||
expect(exception['value'], isNot(contains('\n')));
|
||||
expect(exception['value'], isNot(contains('\r')));
|
||||
expect(jsonEncode(sent), isNot(contains('private-marker')));
|
||||
});
|
||||
}
|
||||
@@ -262,6 +275,8 @@ void main() {
|
||||
('a URL', 'open https://e.org/f?token=private-marker'),
|
||||
('a URL with a quote', "open https://e.org/O'Brien?private-marker#x"),
|
||||
('a URL inside a word', 'open id_https://e.org/f?private-marker'),
|
||||
('a mail link', 'open mailto:a@e.org?subject=private-marker'),
|
||||
('a fragment', 'open page#private-marker'),
|
||||
('a long line', 'state ${'x' * 200} private-marker'),
|
||||
];
|
||||
for (final (name, text) in replaced) {
|
||||
|
||||
Reference in New Issue
Block a user