-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/io-overrides-integration
- Loading branch information
Showing
43 changed files
with
1,896 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ targets: | |
pub:sentry_logging: | ||
pub:sentry_dio: | ||
pub:sentry_file: | ||
#pub:sentry_sqflite: | ||
pub:sentry_sqflite: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// ignore: invalid_export_of_internal_element | ||
export 'sentry.dart'; | ||
export 'src/sentry_attachment/io_sentry_attachment.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
import '../protocol.dart'; | ||
import 'url_details.dart'; | ||
|
||
@internal | ||
class HttpSanitizer { | ||
static final RegExp _authRegExp = RegExp("(.+://)(.*@)(.*)"); | ||
static final List<String> _securityHeaders = [ | ||
"X-FORWARDED-FOR", | ||
"AUTHORIZATION", | ||
"COOKIE", | ||
"SET-COOKIE", | ||
"X-API-KEY", | ||
"X-REAL-IP", | ||
"REMOTE-ADDR", | ||
"FORWARDED", | ||
"PROXY-AUTHORIZATION", | ||
"X-CSRF-TOKEN", | ||
"X-CSRFTOKEN", | ||
"X-XSRF-TOKEN" | ||
]; | ||
|
||
/// Parse and sanitize url data for sentry.io | ||
static UrlDetails? sanitizeUrl(String? url) { | ||
if (url == null) { | ||
return null; | ||
} | ||
|
||
final queryIndex = url.indexOf('?'); | ||
final fragmentIndex = url.indexOf('#'); | ||
|
||
if (queryIndex > -1 && fragmentIndex > -1 && fragmentIndex < queryIndex) { | ||
// url considered malformed because of fragment position | ||
return UrlDetails(); | ||
} else { | ||
try { | ||
final uri = Uri.parse(url); | ||
final urlWithAuthRemoved = _urlWithAuthRemoved(uri._url()); | ||
return UrlDetails( | ||
url: urlWithAuthRemoved.isEmpty ? null : urlWithAuthRemoved, | ||
query: uri.query.isEmpty ? null : uri.query, | ||
fragment: uri.fragment.isEmpty ? null : uri.fragment); | ||
} catch (_) { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
static Map<String, String>? sanitizedHeaders(Map<String, String>? headers) { | ||
if (headers == null) { | ||
return null; | ||
} | ||
final sanitizedHeaders = <String, String>{}; | ||
headers.forEach((key, value) { | ||
if (!_securityHeaders.contains(key.toUpperCase())) { | ||
sanitizedHeaders[key] = value; | ||
} | ||
}); | ||
return sanitizedHeaders; | ||
} | ||
|
||
static String _urlWithAuthRemoved(String url) { | ||
final userInfoMatch = _authRegExp.firstMatch(url); | ||
if (userInfoMatch != null && userInfoMatch.groupCount == 3) { | ||
final userInfoString = userInfoMatch.group(2) ?? ''; | ||
final replacementString = userInfoString.contains(":") | ||
? "[Filtered]:[Filtered]@" | ||
: "[Filtered]@"; | ||
return '${userInfoMatch.group(1) ?? ''}$replacementString${userInfoMatch.group(3) ?? ''}'; | ||
} else { | ||
return url; | ||
} | ||
} | ||
} | ||
|
||
extension UriPath on Uri { | ||
String _url() { | ||
var buffer = ''; | ||
if (scheme.isNotEmpty) { | ||
buffer += '$scheme://'; | ||
} | ||
if (userInfo.isNotEmpty) { | ||
buffer += '$userInfo@'; | ||
} | ||
buffer += host; | ||
if (path.isNotEmpty) { | ||
buffer += path; | ||
} | ||
return buffer; | ||
} | ||
} | ||
|
||
extension SanitizedSentryRequest on SentryRequest { | ||
SentryRequest sanitized() { | ||
final urlDetails = HttpSanitizer.sanitizeUrl(url) ?? UrlDetails(); | ||
return copyWith( | ||
url: urlDetails.urlOrFallback, | ||
queryString: urlDetails.query, | ||
fragment: urlDetails.fragment, | ||
headers: HttpSanitizer.sanitizedHeaders(headers), | ||
removeCookies: true, | ||
); | ||
} | ||
} |
Oops, something went wrong.