@@ -5,7 +5,6 @@ import 'url_details.dart';
5
5
6
6
@internal
7
7
class HttpSanitizer {
8
- static final RegExp _authRegExp = RegExp ("(.+://)(.*@)(.*)" );
9
8
static final List <String > _securityHeaders = [
10
9
"X-FORWARDED-FOR" ,
11
10
"AUTHORIZATION" ,
@@ -36,9 +35,9 @@ class HttpSanitizer {
36
35
} else {
37
36
try {
38
37
final uri = Uri .parse (url);
39
- final urlWithAuthRemoved = _urlWithAuthRemoved ( uri._url () );
38
+ final urlWithRedactedAuth = uri._urlWithRedactedAuth ( );
40
39
return UrlDetails (
41
- url: urlWithAuthRemoved .isEmpty ? null : urlWithAuthRemoved ,
40
+ url: urlWithRedactedAuth .isEmpty ? null : urlWithRedactedAuth ,
42
41
query: uri.query.isEmpty ? null : uri.query,
43
42
fragment: uri.fragment.isEmpty ? null : uri.fragment);
44
43
} catch (_) {
@@ -59,29 +58,17 @@ class HttpSanitizer {
59
58
});
60
59
return sanitizedHeaders;
61
60
}
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
- }
75
61
}
76
62
77
63
extension UriPath on Uri {
78
- String _url () {
64
+ String _urlWithRedactedAuth () {
79
65
var buffer = '' ;
80
66
if (scheme.isNotEmpty) {
81
67
buffer += '$scheme ://' ;
82
68
}
83
69
if (userInfo.isNotEmpty) {
84
- buffer += '$userInfo @' ;
70
+ buffer +=
71
+ userInfo.contains (":" ) ? "[Filtered]:[Filtered]@" : "[Filtered]@" ;
85
72
}
86
73
buffer += host;
87
74
if (path.isNotEmpty) {
0 commit comments