Skip to content

Commit

Permalink
remove cookies from requests
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Mar 27, 2023
1 parent bca5099 commit 4327595
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dart/lib/src/protocol/sentry_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ class SentryRequest {
Map<String, String>? env,
@Deprecated('Will be removed in v8. Use [data] instead')
Map<String, String>? other,
bool removeCookies = false,
}) =>
SentryRequest(
url: url ?? this.url,
method: method ?? this.method,
queryString: queryString ?? this.queryString,
cookies: cookies ?? this.cookies,
cookies: removeCookies ? null : cookies ?? this.cookies,
data: data ?? _data,
headers: headers ?? _headers,
env: env ?? _env,
Expand Down
1 change: 1 addition & 0 deletions dart/lib/src/utils/http_sanitizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extension SanitizedSentryRequest on SentryRequest {
queryString: urlDetails.query,
fragment: urlDetails.fragment,
headers: HttpSanitizer.sanitizedHeaders(headers),
removeCookies: true,
);
}
}
8 changes: 4 additions & 4 deletions dart/test/http_client/failed_request_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void main() {
expect(request?.url, 'https://example.com');
expect(request?.queryString, 'foo=bar');
expect(request?.fragment, 'myFragment');
expect(request?.cookies, 'foo=bar');
expect(request?.headers, {'Cookie': 'foo=bar'});
expect(request?.cookies, isNull);
expect(request?.headers, {});
// ignore: deprecated_member_use_from_same_package
expect(request?.other.keys.contains('duration'), true);
// ignore: deprecated_member_use_from_same_package
Expand Down Expand Up @@ -134,8 +134,8 @@ void main() {
expect(request?.url, 'https://example.com');
expect(request?.queryString, 'foo=bar');
expect(request?.fragment, 'myFragment');
expect(request?.cookies, 'foo=bar');
expect(request?.headers, {'Cookie': 'foo=bar'});
expect(request?.cookies, isNull);
expect(request?.headers, {});
// ignore: deprecated_member_use_from_same_package
expect(request?.other.keys.contains('duration'), true);
// ignore: deprecated_member_use_from_same_package
Expand Down
7 changes: 7 additions & 0 deletions dart/test/utils/url_details_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ void main() {
expect(request.fragment, isNull);
});

test('removes cookies from request', () {
final request =
SentryRequest(url: 'https://sentry.io/api', cookies: 'foo=bar')
.sanitized();
expect(request.cookies, isNull);
});

test('returns fallback for null URL', () {
final urlDetails = UrlDetails(url: null);
expect(urlDetails.urlOrFallback, "unknown");
Expand Down

0 comments on commit 4327595

Please sign in to comment.