-
-
Notifications
You must be signed in to change notification settings - Fork 257
Support allowUrls, denyUrls #2227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
47beb08
moved regex matcher into regex utils
martinhaintz 65c2868
add allowUrls, denyUrls for web
martinhaintz 92f02c3
add changelog entry for allowUrls and denyUrls
martinhaintz 11a06c5
add conditional import for non web platforms
martinhaintz 934c9d0
fix multiplatform build
martinhaintz 24c48e9
fix wording in sentry options
martinhaintz e510129
Update dart/lib/src/utils/regex_utils.dart
martinhaintz 5d62144
Update dart/lib/src/sentry_options.dart
martinhaintz f623e07
Update dart/lib/src/sentry_options.dart
martinhaintz 40cadc9
add tests for isMatchingRegexPattern
martinhaintz 2812a96
simplified allowUrls and denyUrls handling
martinhaintz c0ffc67
moved allowUrls and denyUrls from dart to flutter
martinhaintz 5598f4c
Merge branch 'main' into feat/support-allow-urls-deny-urls
martinhaintz 8523a6d
add event processor for html
martinhaintz a30a862
rephrased documentation and split up tests for web and mobile platform.
martinhaintz 1ec7235
Merge branch 'main' into feat/support-allow-urls-deny-urls
martinhaintz 160ddcc
add expected error
martinhaintz dc06ba9
Update scripts/publish_validation/bin/publish_validation.dart
martinhaintz e38e625
Update flutter/lib/src/event_processor/url_filter/html_url_filter_eve…
martinhaintz 5e7ccc1
Update flutter/lib/src/event_processor/url_filter/web_url_filter_even…
martinhaintz a4c0d59
Merge branch 'main' into feat/support-allow-urls-deny-urls
martinhaintz 102f0e5
modified code to go through stacktrace frames
martinhaintz e5a3315
Merge branch 'main' into feat/support-allow-urls-deny-urls
martinhaintz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 +1,20 @@ | ||
# Changelog | ||
|
||
## Unreleased | ||
|
||
- Support allowUrls and denyUrls for Flutter Web ([#2227](https://github.com/getsentry/sentry-dart/pull/2227)) | ||
```dart | ||
await SentryFlutter.init( | ||
(options) { | ||
options.dsn = 'https://[email protected]/0'; | ||
options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; | ||
options.denyUrls = ["^.*ends-with-this\$", "denied-url"]; | ||
... | ||
}, | ||
appRunner: () => runApp(MyApp()), | ||
); | ||
``` | ||
|
||
## 8.7.0 | ||
|
||
### Features | ||
|
10 changes: 10 additions & 0 deletions
10
dart/lib/src/event_processor/url_filter/io_url_filter_event_processor.dart
This file contains hidden or 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,10 @@ | ||
import '../../../sentry.dart'; | ||
import 'url_filter_event_processor.dart'; | ||
|
||
UrlFilterEventProcessor urlFilterEventProcessor(SentryOptions _) => | ||
IoUrlFilterEventProcessor(); | ||
|
||
class IoUrlFilterEventProcessor implements UrlFilterEventProcessor { | ||
@override | ||
SentryEvent apply(SentryEvent event, Hint hint) => event; | ||
} |
8 changes: 8 additions & 0 deletions
8
dart/lib/src/event_processor/url_filter/url_filter_event_processor.dart
This file contains hidden or 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,8 @@ | ||
import '../../../sentry.dart'; | ||
import 'io_url_filter_event_processor.dart' | ||
if (dart.library.html) 'web_url_filter_event_processor.dart'; | ||
|
||
abstract class UrlFilterEventProcessor implements EventProcessor { | ||
factory UrlFilterEventProcessor(SentryOptions options) => | ||
urlFilterEventProcessor(options); | ||
} |
36 changes: 36 additions & 0 deletions
36
dart/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart
This file contains hidden or 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,36 @@ | ||
// We would lose compatibility with old dart versions by adding web to pubspec. | ||
// ignore: depend_on_referenced_packages | ||
import 'package:web/web.dart' as web show window, Window; | ||
|
||
import '../../../sentry.dart'; | ||
import '../../utils/regex_utils.dart'; | ||
import 'url_filter_event_processor.dart'; | ||
|
||
UrlFilterEventProcessor urlFilterEventProcessor(SentryOptions options) => | ||
WebUrlFilterEventProcessor(options); | ||
|
||
class WebUrlFilterEventProcessor implements UrlFilterEventProcessor { | ||
WebUrlFilterEventProcessor( | ||
this._options, | ||
); | ||
|
||
final web.Window _window = web.window; | ||
|
||
final SentryOptions _options; | ||
|
||
@override | ||
SentryEvent? apply(SentryEvent event, Hint hint) { | ||
final url = event.request?.url ?? _window.location.toString(); | ||
|
||
if (isMatchingRegexPattern(url, _options.allowUrls)) { | ||
if (_options.denyUrls.isNotEmpty && | ||
isMatchingRegexPattern(url, _options.denyUrls)) { | ||
return null; | ||
} else { | ||
return event; | ||
} | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
bool isMatchingRegexPattern(String value, List<String> regexPattern, | ||
martinhaintz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{bool caseSensitive = false}) { | ||
final combinedRegexPattern = regexPattern.join('|'); | ||
final regExp = RegExp(combinedRegexPattern, caseSensitive: caseSensitive); | ||
return regExp.hasMatch(value); | ||
} |
153 changes: 153 additions & 0 deletions
153
dart/test/event_processor/web_url_filter_event_processor_test.dart
This file contains hidden or 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,153 @@ | ||
@TestOn('browser') | ||
library dart_test; | ||
|
||
import 'package:sentry/sentry.dart'; | ||
import 'package:sentry/sentry_io.dart'; | ||
import 'package:sentry/src/event_processor/url_filter/web_url_filter_event_processor.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../mocks.dart'; | ||
import '../mocks/mock_platform_checker.dart'; | ||
|
||
// can be tested on command line with | ||
// `dart test -p chrome test/event_processor/web_url_filter_event_processor_test.dart --name web_url_filter` | ||
void main() { | ||
group('web_url_filter', () { | ||
late Fixture fixture; | ||
|
||
setUp(() { | ||
fixture = Fixture(); | ||
}); | ||
|
||
test('returns event if no allowUrl and no denyUrl is set', () { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'foo.bar', | ||
), | ||
); | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNotNull); | ||
}); | ||
|
||
test('returns null if allowUrl is set and does not match with url', () { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'foo.bar', | ||
), | ||
); | ||
fixture.options.allowUrls = ["another.url"]; | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNull); | ||
}); | ||
|
||
test('returns event if allowUrl is set and does partially match with url', | ||
() { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'foo.bar', | ||
), | ||
); | ||
fixture.options.allowUrls = ["bar"]; | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNotNull); | ||
}); | ||
|
||
test('returns event if denyUrl is set and does not match with url', () { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'foo.bar', | ||
), | ||
); | ||
fixture.options.denyUrls = ["another.url"]; | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNotNull); | ||
}); | ||
|
||
test('returns null if denyUrl is set and partially matches with url', () { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'foo.bar', | ||
), | ||
); | ||
fixture.options.denyUrls = ["bar"]; | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNull); | ||
}); | ||
|
||
test( | ||
'returns null if it is part of the allowed domain, but blocked for subdomain', | ||
() { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'this.is/a/special/url/for-testing/this-feature', | ||
), | ||
); | ||
fixture.options.allowUrls = ["^this.is/.*\$"]; | ||
fixture.options.denyUrls = ["special"]; | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNull); | ||
}); | ||
|
||
test( | ||
'returns event if it is part of the allowed domain, and not of the blocked for subdomain', | ||
() { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'this.is/a/test/url/for-testing/this-feature', | ||
), | ||
); | ||
fixture.options.allowUrls = ["^this.is/.*\$"]; | ||
fixture.options.denyUrls = ["special"]; | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNotNull); | ||
}); | ||
|
||
test( | ||
'returns null if it is not part of the allowed domain, and not of the blocked for subdomain', | ||
() { | ||
SentryEvent? event = SentryEvent( | ||
request: SentryRequest( | ||
url: 'another.url/for/a/test/testing/this-feature', | ||
), | ||
); | ||
fixture.options.allowUrls = ["^this.is/.*\$"]; | ||
fixture.options.denyUrls = ["special"]; | ||
|
||
var eventProcessor = fixture.getSut(); | ||
event = eventProcessor.apply(event, Hint()); | ||
|
||
expect(event, isNull); | ||
}); | ||
}); | ||
} | ||
|
||
class Fixture { | ||
SentryOptions options = SentryOptions( | ||
dsn: fakeDsn, | ||
checker: MockPlatformChecker(hasNativeIntegration: false), | ||
); | ||
WebUrlFilterEventProcessor getSut() { | ||
return WebUrlFilterEventProcessor(options); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.