Skip to content

Commit 8cb6557

Browse files
authored
Fix authority redaction (#1424)
1 parent 895becc commit 8cb6557

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- Fix `event.origin` and `event.environment` on unhandled exceptions ([#1419](https://github.com/getsentry/sentry-dart/pull/1419))
8+
- Fix authority redaction ([#1424](https://github.com/getsentry/sentry-dart/pull/1424))
89

910
### Dependencies
1011

dart/lib/src/utils/http_sanitizer.dart

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'url_details.dart';
55

66
@internal
77
class HttpSanitizer {
8-
static final RegExp _authRegExp = RegExp("(.+://)(.*@)(.*)");
98
static final List<String> _securityHeaders = [
109
"X-FORWARDED-FOR",
1110
"AUTHORIZATION",
@@ -36,9 +35,9 @@ class HttpSanitizer {
3635
} else {
3736
try {
3837
final uri = Uri.parse(url);
39-
final urlWithAuthRemoved = _urlWithAuthRemoved(uri._url());
38+
final urlWithRedactedAuth = uri._urlWithRedactedAuth();
4039
return UrlDetails(
41-
url: urlWithAuthRemoved.isEmpty ? null : urlWithAuthRemoved,
40+
url: urlWithRedactedAuth.isEmpty ? null : urlWithRedactedAuth,
4241
query: uri.query.isEmpty ? null : uri.query,
4342
fragment: uri.fragment.isEmpty ? null : uri.fragment);
4443
} catch (_) {
@@ -59,29 +58,17 @@ class HttpSanitizer {
5958
});
6059
return sanitizedHeaders;
6160
}
62-
63-
static String _urlWithAuthRemoved(String url) {
64-
final userInfoMatch = _authRegExp.firstMatch(url);
65-
if (userInfoMatch != null && userInfoMatch.groupCount == 3) {
66-
final userInfoString = userInfoMatch.group(2) ?? '';
67-
final replacementString = userInfoString.contains(":")
68-
? "[Filtered]:[Filtered]@"
69-
: "[Filtered]@";
70-
return '${userInfoMatch.group(1) ?? ''}$replacementString${userInfoMatch.group(3) ?? ''}';
71-
} else {
72-
return url;
73-
}
74-
}
7561
}
7662

7763
extension UriPath on Uri {
78-
String _url() {
64+
String _urlWithRedactedAuth() {
7965
var buffer = '';
8066
if (scheme.isNotEmpty) {
8167
buffer += '$scheme://';
8268
}
8369
if (userInfo.isNotEmpty) {
84-
buffer += '$userInfo@';
70+
buffer +=
71+
userInfo.contains(":") ? "[Filtered]:[Filtered]@" : "[Filtered]@";
8572
}
8673
buffer += host;
8774
if (path.isNotEmpty) {

dart/test/utils/http_sanitizer_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ void main() {
170170
final details = HttpSanitizer.sanitizeUrl('::Not valid URI::');
171171
expect(details, isNull);
172172
});
173+
174+
test('keeps email address', () {
175+
final urlDetails = HttpSanitizer.sanitizeUrl(
176+
"https://staging.server.com/api/v4/auth/password/reset/[email protected]");
177+
expect(
178+
"https://staging.server.com/api/v4/auth/password/reset/[email protected]",
179+
urlDetails?.url);
180+
expect(urlDetails?.query, isNull);
181+
expect(urlDetails?.fragment, isNull);
182+
});
173183
}
174184

175185
extension StringExtension on String {

0 commit comments

Comments
 (0)