Skip to content

Commit c59de47

Browse files
authored
Do not leak extensions of external classes (#1576)
1 parent 852a85e commit c59de47

18 files changed

+124
-96
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Refrain from overwriting the span status for unfinished spans ([#1577](https://github.com/getsentry/sentry-dart/pull/1577))
1010
- Older self-hosted sentry instances will drop transactions containing unfinished spans.
1111
- This change was introduced in [relay/#1690](https://github.com/getsentry/relay/pull/1690) and released with [22.12.0](https://github.com/getsentry/relay/releases/tag/22.12.0)
12+
- Do not leak extensions of external classes ([#1576](https://github.com/getsentry/sentry-dart/pull/1576))
1213

1314
## Unreleased
1415

dart/lib/src/client_reports/discard_reason.dart

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,3 @@ enum DiscardReason {
1212
cacheOverflow,
1313
rateLimitBackoff,
1414
}
15-
16-
extension OutcomeExtension on DiscardReason {
17-
String toStringValue() {
18-
switch (this) {
19-
case DiscardReason.beforeSend:
20-
return 'before_send';
21-
case DiscardReason.eventProcessor:
22-
return 'event_processor';
23-
case DiscardReason.sampleRate:
24-
return 'sample_rate';
25-
case DiscardReason.networkError:
26-
return 'network_error';
27-
case DiscardReason.queueOverflow:
28-
return 'queue_overflow';
29-
case DiscardReason.cacheOverflow:
30-
return 'cache_overflow';
31-
case DiscardReason.rateLimitBackoff:
32-
return 'ratelimit_backoff';
33-
}
34-
}
35-
}

dart/lib/src/client_reports/discarded_event.dart

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,53 @@ class DiscardedEvent {
1313

1414
Map<String, dynamic> toJson() {
1515
return {
16-
'reason': reason.toStringValue(),
17-
'category': category.toStringValue(),
16+
'reason': reason._toStringValue(),
17+
'category': category._toStringValue(),
1818
'quantity': quantity,
1919
};
2020
}
2121
}
22+
23+
extension _OutcomeExtension on DiscardReason {
24+
String _toStringValue() {
25+
switch (this) {
26+
case DiscardReason.beforeSend:
27+
return 'before_send';
28+
case DiscardReason.eventProcessor:
29+
return 'event_processor';
30+
case DiscardReason.sampleRate:
31+
return 'sample_rate';
32+
case DiscardReason.networkError:
33+
return 'network_error';
34+
case DiscardReason.queueOverflow:
35+
return 'queue_overflow';
36+
case DiscardReason.cacheOverflow:
37+
return 'cache_overflow';
38+
case DiscardReason.rateLimitBackoff:
39+
return 'ratelimit_backoff';
40+
}
41+
}
42+
}
43+
44+
extension _DataCategoryExtension on DataCategory {
45+
String _toStringValue() {
46+
switch (this) {
47+
case DataCategory.all:
48+
return '__all__';
49+
case DataCategory.dataCategoryDefault:
50+
return 'default';
51+
case DataCategory.error:
52+
return 'error';
53+
case DataCategory.session:
54+
return 'session';
55+
case DataCategory.transaction:
56+
return 'transaction';
57+
case DataCategory.attachment:
58+
return 'attachment';
59+
case DataCategory.security:
60+
return 'security';
61+
case DataCategory.unknown:
62+
return 'unknown';
63+
}
64+
}
65+
}

dart/lib/src/http_client/failed_request_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class FailedRequestClient extends BaseClient {
135135

136136
// Only check `failedRequestStatusCodes` & `failedRequestTargets` if no exception was thrown.
137137
if (exception == null) {
138-
if (!failedRequestStatusCodes.containsStatusCode(statusCode)) {
138+
if (!failedRequestStatusCodes._containsStatusCode(statusCode)) {
139139
return;
140140
}
141141
if (!containsTargetOrMatchesRegExp(
@@ -246,7 +246,7 @@ class FailedRequestClient extends BaseClient {
246246
}
247247

248248
extension _ListX on List<SentryStatusCode> {
249-
bool containsStatusCode(int? statusCode) {
249+
bool _containsStatusCode(int? statusCode) {
250250
if (statusCode == null) {
251251
return false;
252252
}

dart/lib/src/protocol/sentry_request.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:meta/meta.dart';
22

3-
import '../utils/iterable_extension.dart';
3+
import '../utils/iterable_utils.dart';
44
import '../utils/http_sanitizer.dart';
55

66
/// The Request interface contains information on a HTTP request related to the event.
@@ -85,9 +85,10 @@ class SentryRequest {
8585
_headers = headers != null ? Map.from(headers) : null,
8686
// Look for a 'Set-Cookie' header (case insensitive) if not given.
8787
cookies = cookies ??
88-
headers?.entries
89-
.firstWhereOrNull((e) => e.key.toLowerCase() == 'cookie')
90-
?.value,
88+
IterableUtils.firstWhereOrNull(
89+
headers?.entries,
90+
(MapEntry<String, String> e) => e.key.toLowerCase() == 'cookie',
91+
)?.value,
9192
_env = env != null ? Map.from(env) : null,
9293
_other = other != null ? Map.from(other) : null;
9394

dart/lib/src/protocol/sentry_response.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:meta/meta.dart';
22
import 'contexts.dart';
3-
import '../utils/iterable_extension.dart';
3+
import '../utils/iterable_utils.dart';
44

55
/// The response interface contains information on a HTTP request related to the event.
66
@immutable
@@ -53,9 +53,11 @@ class SentryResponse {
5353
_headers = headers != null ? Map.from(headers) : null,
5454
// Look for a 'Set-Cookie' header (case insensitive) if not given.
5555
cookies = cookies ??
56-
headers?.entries
57-
.firstWhereOrNull((e) => e.key.toLowerCase() == 'set-cookie')
58-
?.value;
56+
IterableUtils.firstWhereOrNull(
57+
headers?.entries,
58+
(MapEntry<String, String> e) =>
59+
e.key.toLowerCase() == 'set-cookie',
60+
)?.value;
5961

6062
/// Deserializes a [SentryResponse] from JSON [Map].
6163
factory SentryResponse.fromJson(Map<String, dynamic> json) {

dart/lib/src/transport/data_category.dart

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,3 @@ enum DataCategory {
99
security,
1010
unknown
1111
}
12-
13-
extension DataCategoryExtension on DataCategory {
14-
static DataCategory fromStringValue(String stringValue) {
15-
switch (stringValue) {
16-
case '__all__':
17-
return DataCategory.all;
18-
case 'default':
19-
return DataCategory.dataCategoryDefault;
20-
case 'error':
21-
return DataCategory.error;
22-
case 'session':
23-
return DataCategory.session;
24-
case 'transaction':
25-
return DataCategory.transaction;
26-
case 'attachment':
27-
return DataCategory.attachment;
28-
case 'security':
29-
return DataCategory.security;
30-
}
31-
return DataCategory.unknown;
32-
}
33-
34-
String toStringValue() {
35-
switch (this) {
36-
case DataCategory.all:
37-
return '__all__';
38-
case DataCategory.dataCategoryDefault:
39-
return 'default';
40-
case DataCategory.error:
41-
return 'error';
42-
case DataCategory.session:
43-
return 'session';
44-
case DataCategory.transaction:
45-
return 'transaction';
46-
case DataCategory.attachment:
47-
return 'attachment';
48-
case DataCategory.security:
49-
return 'security';
50-
case DataCategory.unknown:
51-
return 'unknown';
52-
}
53-
}
54-
}

dart/lib/src/transport/rate_limit_parser.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class RateLimitParser {
2929
if (allCategories.isNotEmpty) {
3030
final categoryValues = allCategories.split(';');
3131
for (final categoryValue in categoryValues) {
32-
final category = DataCategoryExtension.fromStringValue(categoryValue);
32+
final category =
33+
_DataCategoryExtension._fromStringValue(categoryValue);
3334
if (category != DataCategory.unknown) {
3435
rateLimits.add(RateLimit(category, duration));
3536
}
@@ -56,3 +57,25 @@ class RateLimitParser {
5657
}
5758
}
5859
}
60+
61+
extension _DataCategoryExtension on DataCategory {
62+
static DataCategory _fromStringValue(String stringValue) {
63+
switch (stringValue) {
64+
case '__all__':
65+
return DataCategory.all;
66+
case 'default':
67+
return DataCategory.dataCategoryDefault;
68+
case 'error':
69+
return DataCategory.error;
70+
case 'session':
71+
return DataCategory.session;
72+
case 'transaction':
73+
return DataCategory.transaction;
74+
case 'attachment':
75+
return DataCategory.attachment;
76+
case 'security':
77+
return DataCategory.security;
78+
}
79+
return DataCategory.unknown;
80+
}
81+
}

dart/lib/src/utils/http_sanitizer.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class HttpSanitizer {
6060
}
6161
}
6262

63-
extension UriPath on Uri {
63+
extension _UriPath on Uri {
6464
String _urlWithRedactedAuth() {
6565
var buffer = '';
6666
if (scheme.isNotEmpty) {
@@ -78,6 +78,7 @@ extension UriPath on Uri {
7878
}
7979
}
8080

81+
@internal
8182
extension SanitizedSentryRequest on SentryRequest {
8283
SentryRequest sanitized() {
8384
final urlDetails = HttpSanitizer.sanitizeUrl(url) ?? UrlDetails();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import 'package:meta/meta.dart';
2+
13
import '_io_get_isolate_name.dart'
24
if (dart.library.html) '_web_get_isolate_name.dart' as isolate_getter;
35

6+
@internal
47
String? getIsolateName() => isolate_getter.getIsolateName();

0 commit comments

Comments
 (0)