@@ -5,7 +5,6 @@ import 'url_details.dart';
55
66@internal
77class 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
7763extension 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) {
0 commit comments