Skip to content
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

ref: Rename whitelistUrls/blacklistUrls to allowUrls/denyUrls #2671

Merged
merged 1 commit into from Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
- [core] feat: Export `makeMain` (#2665)
- [core] fix: Call `bindClient` when creating new `Hub` to make integrations work automatically (#2665)
- [gatsby] feat: Add @sentry/gatsby package (#2652)
- [core] ref: Rename `whitelistUrls/blacklistUrls` to `allowUrls/denyUrls`

## 5.17.0

Expand Down
4 changes: 2 additions & 2 deletions MIGRATION.md
Expand Up @@ -253,7 +253,7 @@ Sentry.addBreadcrumb({

### Ignoring Urls

> 'ignoreUrls' was renamed to 'blacklistUrls'. 'ignoreErrors', which has a similar name was not renamed. [Docs](https://docs.sentry.io/error-reporting/configuration/?platform=browser#blacklist-urls) and [Decluttering Sentry](https://docs.sentry.io/platforms/javascript/#decluttering-sentry)
> 'ignoreUrls' was renamed to 'denyUrls'. 'ignoreErrors', which has a similar name was not renamed. [Docs](https://docs.sentry.io/error-reporting/configuration/?platform=browser#deny-urls) and [Decluttering Sentry](https://docs.sentry.io/platforms/javascript/#decluttering-sentry)
_Old_:

Expand All @@ -270,7 +270,7 @@ _New_:

```js
Sentry.init({
blacklistUrls: [
denyUrls: [
'https://www.baddomain.com',
/graph\.facebook\.com/i,
],
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/examples/app.js
Expand Up @@ -37,9 +37,9 @@ Sentry.init({
// An array of strings or regexps that'll be used to ignore specific errors based on their type/message
ignoreErrors: [/PickleRick_\d\d/, 'RangeError'],
// An array of strings or regexps that'll be used to ignore specific errors based on their origin url
blacklistUrls: ['external-lib.js'],
denyUrls: ['external-lib.js'],
// An array of strings or regexps that'll be used to allow specific errors based on their origin url
whitelistUrls: ['http://localhost:5000', 'https://browser.sentry-cdn'],
allowUrls: ['http://localhost:5000', 'https://browser.sentry-cdn'],
// Debug mode with valuable initialization/lifecycle informations.
debug: true,
// Whether SDK should be enabled or not.
Expand Down Expand Up @@ -93,15 +93,15 @@ Sentry.init({
// Testing code, irrelevant vvvvv

document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#blacklist-url').addEventListener('click', () => {
document.querySelector('#deny-url').addEventListener('click', () => {
const script = document.createElement('script');
script.crossOrigin = 'anonymous';
script.src =
'https://rawgit.com/kamilogorek/cfbe9f92196c6c61053b28b2d42e2f5d/raw/3aef6ff5e2fd2ad4a84205cd71e2496a445ebe1d/external-lib.js';
document.body.appendChild(script);
});

document.querySelector('#whitelist-url').addEventListener('click', () => {
document.querySelector('#allow-url').addEventListener('click', () => {
const script = document.createElement('script');
script.crossOrigin = 'anonymous';
script.src =
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/examples/index.html
Expand Up @@ -20,8 +20,8 @@
</style>
</head>
<body>
<button id="blacklist-url">blacklistUrl example</button>
<button id="whitelist-url">whitelistUrl example</button>
<button id="deny-url">denyUrls example</button>
<button id="allow-url">allowUrls example</button>
<button id="ignore-message">ignoreError message example</button>
<button id="ignore-type">ignoreError type example</button>
<button id="regular-exception">regularException example</button>
Expand Down
16 changes: 11 additions & 5 deletions packages/browser/src/backend.ts
Expand Up @@ -11,18 +11,24 @@ import { FetchTransport, XHRTransport } from './transports';
*/
export interface BrowserOptions extends Options {
/**
* A pattern for error URLs which should not be sent to Sentry.
* To whitelist certain errors instead, use {@link Options.whitelistUrls}.
* A pattern for error URLs which should exclusively be sent to Sentry.
* This is the opposite of {@link Options.denyUrls}.
* By default, all errors will be sent.
*/
blacklistUrls?: Array<string | RegExp>;
allowUrls?: Array<string | RegExp>;

/**
* A pattern for error URLs which should exclusively be sent to Sentry.
* This is the opposite of {@link Options.blacklistUrls}.
* A pattern for error URLs which should not be sent to Sentry.
* To allow certain errors instead, use {@link Options.allowUrls}.
* By default, all errors will be sent.
*/
denyUrls?: Array<string | RegExp>;

/** @deprecated use {@link Options.allowUrls} instead. */
whitelistUrls?: Array<string | RegExp>;

/** @deprecated use {@link Options.denyUrls} instead. */
blacklistUrls?: Array<string | RegExp>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/integration/common/init.js
Expand Up @@ -34,7 +34,7 @@ function initSDK() {
integrations: [new Sentry.Integrations.Dedupe()],
attachStacktrace: true,
ignoreErrors: ["ignoreErrorTest"],
blacklistUrls: ["foo.js"],
denyUrls: ["foo.js"],
beforeSend: function(event, eventHint) {
events.push(event);
eventHints.push(eventHint);
Expand Down
16 changes: 8 additions & 8 deletions packages/browser/test/integration/suites/config.js
Expand Up @@ -21,10 +21,10 @@ describe("config", function() {
* > bar.js file called a function in baz.js
* > baz.js threw an error
*
* foo.js is blacklisted in the `init` call (init.js), thus we filter it
* foo.js is denied in the `init` call (init.js), thus we filter it
* */
var urlWithBlacklistedUrl = new Error("filter");
urlWithBlacklistedUrl.stack =
var urlWithDeniedUrl = new Error("filter");
urlWithDeniedUrl.stack =
"Error: bar\n" +
" at http://localhost:5000/foo.js:7:19\n" +
" at bar(http://localhost:5000/bar.js:2:3)\n" +
Expand All @@ -35,17 +35,17 @@ describe("config", function() {
* > bar-pass.js file called a function in baz-pass.js
* > baz-pass.js threw an error
*
* foo-pass.js is *not* blacklisted in the `init` call (init.js), thus we don't filter it
* foo-pass.js is *not* denied in the `init` call (init.js), thus we don't filter it
* */
var urlWithoutBlacklistedUrl = new Error("pass");
urlWithoutBlacklistedUrl.stack =
var urlWithoutDeniedUrl = new Error("pass");
urlWithoutDeniedUrl.stack =
"Error: bar\n" +
" at http://localhost:5000/foo-pass.js:7:19\n" +
" at bar(http://localhost:5000/bar-pass.js:2:3)\n" +
" at baz(http://localhost:5000/baz-pass.js:2:9)\n";

Sentry.captureException(urlWithBlacklistedUrl);
Sentry.captureException(urlWithoutBlacklistedUrl);
Sentry.captureException(urlWithDeniedUrl);
Sentry.captureException(urlWithoutDeniedUrl);
}).then(function(summary) {
assert.lengthOf(summary.events, 1);
assert.equal(summary.events[0].exception.values[0].type, "Error");
Expand Down
58 changes: 37 additions & 21 deletions packages/core/src/integrations/inboundfilters.ts
Expand Up @@ -8,10 +8,15 @@ const DEFAULT_IGNORE_ERRORS = [/^Script error\.?$/, /^Javascript error: Script e

/** JSDoc */
interface InboundFiltersOptions {
blacklistUrls?: Array<string | RegExp>;
ignoreErrors?: Array<string | RegExp>;
ignoreInternal?: boolean;
whitelistUrls?: Array<string | RegExp>;
allowUrls: Array<string | RegExp>;
denyUrls: Array<string | RegExp>;
ignoreErrors: Array<string | RegExp>;
ignoreInternal: boolean;

/** @deprecated use {@link InboundFiltersOptions.allowUrls} instead. */
whitelistUrls: Array<string | RegExp>;
/** @deprecated use {@link InboundFiltersOptions.denyUrls} instead. */
blacklistUrls: Array<string | RegExp>;
}

/** Inbound filters configurable by the user */
Expand All @@ -25,7 +30,7 @@ export class InboundFilters implements Integration {
*/
public static id: string = 'InboundFilters';

public constructor(private readonly _options: InboundFiltersOptions = {}) {}
public constructor(private readonly _options: Partial<InboundFiltersOptions> = {}) {}

/**
* @inheritDoc
Expand All @@ -50,7 +55,7 @@ export class InboundFilters implements Integration {
}

/** JSDoc */
private _shouldDropEvent(event: Event, options: InboundFiltersOptions): boolean {
private _shouldDropEvent(event: Event, options: Partial<InboundFiltersOptions>): boolean {
if (this._isSentryError(event, options)) {
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
return true;
Expand All @@ -61,17 +66,17 @@ export class InboundFilters implements Integration {
);
return true;
}
if (this._isBlacklistedUrl(event, options)) {
if (this._isDeniedUrl(event, options)) {
logger.warn(
`Event dropped due to being matched by \`blacklistUrls\` option.\nEvent: ${getEventDescription(
`Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
return true;
}
if (!this._isWhitelistedUrl(event, options)) {
if (!this._isAllowedUrl(event, options)) {
logger.warn(
`Event dropped due to not being matched by \`whitelistUrls\` option.\nEvent: ${getEventDescription(
`Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${getEventDescription(
event,
)}.\nUrl: ${this._getEventFilterUrl(event)}`,
);
Expand All @@ -81,7 +86,7 @@ export class InboundFilters implements Integration {
}

/** JSDoc */
private _isSentryError(event: Event, options: InboundFiltersOptions = {}): boolean {
private _isSentryError(event: Event, options: Partial<InboundFiltersOptions>): boolean {
if (!options.ignoreInternal) {
return false;
}
Expand All @@ -101,7 +106,7 @@ export class InboundFilters implements Integration {
}

/** JSDoc */
private _isIgnoredError(event: Event, options: InboundFiltersOptions = {}): boolean {
private _isIgnoredError(event: Event, options: Partial<InboundFiltersOptions>): boolean {
if (!options.ignoreErrors || !options.ignoreErrors.length) {
return false;
}
Expand All @@ -113,36 +118,47 @@ export class InboundFilters implements Integration {
}

/** JSDoc */
private _isBlacklistedUrl(event: Event, options: InboundFiltersOptions = {}): boolean {
private _isDeniedUrl(event: Event, options: Partial<InboundFiltersOptions>): boolean {
// TODO: Use Glob instead?
if (!options.blacklistUrls || !options.blacklistUrls.length) {
if (!options.denyUrls || !options.denyUrls.length) {
return false;
}
const url = this._getEventFilterUrl(event);
return !url ? false : options.blacklistUrls.some(pattern => isMatchingPattern(url, pattern));
return !url ? false : options.denyUrls.some(pattern => isMatchingPattern(url, pattern));
}

/** JSDoc */
private _isWhitelistedUrl(event: Event, options: InboundFiltersOptions = {}): boolean {
private _isAllowedUrl(event: Event, options: Partial<InboundFiltersOptions>): boolean {
// TODO: Use Glob instead?
if (!options.whitelistUrls || !options.whitelistUrls.length) {
if (!options.allowUrls || !options.allowUrls.length) {
return true;
}
const url = this._getEventFilterUrl(event);
return !url ? true : options.whitelistUrls.some(pattern => isMatchingPattern(url, pattern));
return !url ? true : options.allowUrls.some(pattern => isMatchingPattern(url, pattern));
}

/** JSDoc */
private _mergeOptions(clientOptions: InboundFiltersOptions = {}): InboundFiltersOptions {
private _mergeOptions(clientOptions: Partial<InboundFiltersOptions> = {}): Partial<InboundFiltersOptions> {
// tslint:disable:deprecation
return {
blacklistUrls: [...(this._options.blacklistUrls || []), ...(clientOptions.blacklistUrls || [])],
allowUrls: [
...(this._options.whitelistUrls || []),
...(this._options.allowUrls || []),
...(clientOptions.whitelistUrls || []),
...(clientOptions.allowUrls || []),
],
denyUrls: [
...(this._options.blacklistUrls || []),
...(this._options.denyUrls || []),
...(clientOptions.blacklistUrls || []),
...(clientOptions.denyUrls || []),
],
ignoreErrors: [
...(this._options.ignoreErrors || []),
...(clientOptions.ignoreErrors || []),
...DEFAULT_IGNORE_ERRORS,
],
ignoreInternal: typeof this._options.ignoreInternal !== 'undefined' ? this._options.ignoreInternal : true,
whitelistUrls: [...(this._options.whitelistUrls || []), ...(clientOptions.whitelistUrls || [])],
};
}

Expand Down