Skip to content

Commit 3a7c33d

Browse files
authored
fix: deprecate whitelist/blacklist in favor of safelist/blocklist (#911)
1 parent e92c74d commit 3a7c33d

File tree

9 files changed

+184
-79
lines changed

9 files changed

+184
-79
lines changed

src/browser/core.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var sharedPredicates = require('../predicates');
1414
var errorParser = require('../errorParser');
1515

1616
function Rollbar(options, client) {
17-
this.options = _.handleOptions(defaultOptions, options);
17+
this.options = _.handleOptions(defaultOptions, options, null, logger);
1818
this.options._configuredOptions = options;
1919
var Telemeter = this.components.telemeter;
2020
var Instrumenter = this.components.instrumenter;
@@ -84,7 +84,7 @@ Rollbar.prototype.configure = function(options, payloadData) {
8484
if (payloadData) {
8585
payload = {payload: payloadData};
8686
}
87-
this.options = _.handleOptions(oldOptions, options, payload);
87+
this.options = _.handleOptions(oldOptions, options, payload, logger);
8888
this.options._configuredOptions = _.handleOptions(oldOptions._configuredOptions, options, payload);
8989
this.client.configure(this.options, payloadData);
9090
this.instrumenter && this.instrumenter.configure(this.options);
@@ -511,8 +511,8 @@ function addPredicatesToQueue(queue) {
511511
.addPredicate(sharedPredicates.checkLevel)
512512
.addPredicate(predicates.checkIgnore)
513513
.addPredicate(sharedPredicates.userCheckIgnore(logger))
514-
.addPredicate(sharedPredicates.urlIsNotBlacklisted(logger))
515-
.addPredicate(sharedPredicates.urlIsWhitelisted(logger))
514+
.addPredicate(sharedPredicates.urlIsNotBlockListed(logger))
515+
.addPredicate(sharedPredicates.urlIsSafeListed(logger))
516516
.addPredicate(sharedPredicates.messageIsIgnored(logger));
517517
}
518518

src/predicates.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ function userCheckIgnore(logger) {
3838
}
3939
}
4040

41-
function urlIsNotBlacklisted(logger) {
41+
function urlIsNotBlockListed(logger) {
4242
return function(item, settings) {
43-
return !urlIsOnAList(item, settings, 'blacklist', logger);
43+
return !urlIsOnAList(item, settings, 'blocklist', logger);
4444
}
4545
}
4646

47-
function urlIsWhitelisted(logger) {
47+
function urlIsSafeListed(logger) {
4848
return function(item, settings) {
49-
return urlIsOnAList(item, settings, 'whitelist', logger);
49+
return urlIsOnAList(item, settings, 'safelist', logger);
5050
}
5151
}
5252

53-
function matchFrames(trace, list, black) {
54-
if (!trace) { return !black }
53+
function matchFrames(trace, list, block) {
54+
if (!trace) { return !block }
5555

5656
var frames = trace.frames;
5757

58-
if (!frames || frames.length === 0) { return !black; }
58+
if (!frames || frames.length === 0) { return !block; }
5959

6060
var frame, filename, url, urlRegex;
6161
var listLength = list.length;
@@ -64,7 +64,7 @@ function matchFrames(trace, list, black) {
6464
frame = frames[i];
6565
filename = frame.filename;
6666

67-
if (!_.isType(filename, 'string')) { return !black; }
67+
if (!_.isType(filename, 'string')) { return !block; }
6868

6969
for (var j = 0; j < listLength; j++) {
7070
url = list[j];
@@ -78,44 +78,44 @@ function matchFrames(trace, list, black) {
7878
return false;
7979
}
8080

81-
function urlIsOnAList(item, settings, whiteOrBlack, logger) {
82-
// whitelist is the default
83-
var black = false;
84-
if (whiteOrBlack === 'blacklist') {
85-
black = true;
81+
function urlIsOnAList(item, settings, safeOrBlock, logger) {
82+
// safelist is the default
83+
var block = false;
84+
if (safeOrBlock === 'blocklist') {
85+
block = true;
8686
}
8787

8888
var list, traces;
8989
try {
90-
list = black ? settings.hostBlackList : settings.hostWhiteList;
90+
list = block ? settings.hostBlockList : settings.hostSafeList;
9191
traces = _.get(item, 'body.trace_chain') || [_.get(item, 'body.trace')];
9292

9393
// These two checks are important to come first as they are defaults
9494
// in case the list is missing or the trace is missing or not well-formed
9595
if (!list || list.length === 0) {
96-
return !black;
96+
return !block;
9797
}
9898
if (traces.length === 0 || !traces[0]) {
99-
return !black;
99+
return !block;
100100
}
101101

102102
var tracesLength = traces.length;
103103
for (var i = 0; i < tracesLength; i++) {
104-
if(matchFrames(traces[i], list, black)) {
104+
if(matchFrames(traces[i], list, block)) {
105105
return true;
106106
}
107107
}
108108
} catch (e)
109109
/* istanbul ignore next */
110110
{
111-
if (black) {
112-
settings.hostBlackList = null;
111+
if (block) {
112+
settings.hostBlockList = null;
113113
} else {
114-
settings.hostWhiteList = null;
114+
settings.hostSafeList = null;
115115
}
116-
var listName = black ? 'hostBlackList' : 'hostWhiteList';
116+
var listName = block ? 'hostBlockList' : 'hostSafeList';
117117
logger.error('Error while reading your configuration\'s ' + listName + ' option. Removing custom ' + listName + '.', e);
118-
return !black;
118+
return !block;
119119
}
120120
return false;
121121
}
@@ -167,7 +167,7 @@ function messageIsIgnored(logger) {
167167
module.exports = {
168168
checkLevel: checkLevel,
169169
userCheckIgnore: userCheckIgnore,
170-
urlIsNotBlacklisted: urlIsNotBlacklisted,
171-
urlIsWhitelisted: urlIsWhitelisted,
170+
urlIsNotBlockListed: urlIsNotBlockListed,
171+
urlIsSafeListed: urlIsSafeListed,
172172
messageIsIgnored: messageIsIgnored
173173
};

src/react-native/rollbar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Rollbar(options, client) {
2020
options = {};
2121
options.accessToken = accessToken;
2222
}
23-
this.options = _.handleOptions(Rollbar.defaultOptions, options);
23+
this.options = _.handleOptions(Rollbar.defaultOptions, options, null, logger);
2424
this.options._configuredOptions = options;
2525
// This makes no sense in a long running app
2626
delete this.options.maxItems;
@@ -70,7 +70,7 @@ Rollbar.prototype.configure = function(options, payloadData) {
7070
if (payloadData) {
7171
payload = {payload: payloadData};
7272
}
73-
this.options = _.handleOptions(oldOptions, options, payload);
73+
this.options = _.handleOptions(oldOptions, options, payload, logger);
7474
this.options._configuredOptions = _.handleOptions(oldOptions._configuredOptions, options, payload);
7575
this.client.configure(options, payloadData);
7676
return this;

src/server/rollbar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Rollbar(options, client) {
2828
options.reportLevel = options.minimumLevel;
2929
delete options.minimumLevel;
3030
}
31-
this.options = _.handleOptions(Rollbar.defaultOptions, options);
31+
this.options = _.handleOptions(Rollbar.defaultOptions, options, null, logger);
3232
this.options._configuredOptions = options;
3333
// On the server we want to ignore any maxItems setting
3434
delete this.options.maxItems;
@@ -84,7 +84,7 @@ Rollbar.prototype.configure = function (options, payloadData) {
8484
if (payloadData) {
8585
payload = { payload: payloadData };
8686
}
87-
this.options = _.handleOptions(oldOptions, options, payload);
87+
this.options = _.handleOptions(oldOptions, options, payload, logger);
8888
this.options._configuredOptions = _.handleOptions(oldOptions._configuredOptions, options, payload);
8989
// On the server we want to ignore any maxItems setting
9090
delete this.options.maxItems;
@@ -514,8 +514,8 @@ function addPredicatesToQueue(queue) {
514514
queue
515515
.addPredicate(sharedPredicates.checkLevel)
516516
.addPredicate(sharedPredicates.userCheckIgnore(logger))
517-
.addPredicate(sharedPredicates.urlIsNotBlacklisted(logger))
518-
.addPredicate(sharedPredicates.urlIsWhitelisted(logger))
517+
.addPredicate(sharedPredicates.urlIsNotBlockListed(logger))
518+
.addPredicate(sharedPredicates.urlIsSafeListed(logger))
519519
.addPredicate(sharedPredicates.messageIsIgnored(logger));
520520
}
521521

src/utility.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,9 @@ function filterIp(requestData, captureIp) {
665665
requestData['user_ip'] = newIp;
666666
}
667667

668-
function handleOptions(current, input, payload) {
668+
function handleOptions(current, input, payload, logger) {
669669
var result = merge(current, input, payload);
670+
result = updateDeprecatedOptions(result, logger);
670671
if (!input || input.overwriteScrubFields) {
671672
return result;
672673
}
@@ -676,6 +677,20 @@ function handleOptions(current, input, payload) {
676677
return result;
677678
}
678679

680+
function updateDeprecatedOptions(options, logger) {
681+
if(options.hostWhiteList && !options.hostSafeList) {
682+
options.hostSafeList = options.hostWhiteList;
683+
options.hostWhiteList = undefined;
684+
logger && logger.log('hostWhiteList is deprecated. Use hostSafeList.');
685+
}
686+
if(options.hostBlackList && !options.hostBlockList) {
687+
options.hostBlockList = options.hostBlackList;
688+
options.hostBlackList = undefined;
689+
logger && logger.log('hostBlackList is deprecated. Use hostBlockList.');
690+
}
691+
return options;
692+
}
693+
679694
module.exports = {
680695
addParamsAndAccessTokenToPath: addParamsAndAccessTokenToPath,
681696
createItem: createItem,

test/browser.rollbar.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ describe('Rollbar()', function() {
140140
done();
141141
});
142142

143+
it ('should replace deprecated options', function(done) {
144+
var client = new (TestClientGen())();
145+
var options = {
146+
hostWhiteList: ['foo'],
147+
hostBlackList: ['bar']
148+
};
149+
var rollbar = window.rollbar = new Rollbar(options, client);
150+
151+
expect(rollbar.options.hostWhiteList).to.eql(undefined);
152+
expect(rollbar.options.hostBlackList).to.eql(undefined);
153+
expect(rollbar.options.hostSafeList).to.contain('foo');
154+
expect(rollbar.options.hostBlockList).to.contain('bar');
155+
done();
156+
});
157+
143158
it('should return a uuid when logging', function(done) {
144159
var client = new (TestClientGen())();
145160
var options = {};
@@ -254,6 +269,21 @@ describe('configure', function() {
254269
expect(client.payloadData.b).to.eql(97);
255270
done();
256271
});
272+
it ('should replace deprecated options', function(done) {
273+
var client = new (TestClientGen())();
274+
var options = {
275+
hostWhiteList: ['foo'],
276+
hostBlackList: ['bar']
277+
};
278+
var rollbar = window.rollbar = new Rollbar({ autoInstrument: false }, client);
279+
rollbar.configure(options);
280+
281+
expect(rollbar.options.hostWhiteList).to.eql(undefined);
282+
expect(rollbar.options.hostBlackList).to.eql(undefined);
283+
expect(rollbar.options.hostSafeList).to.contain('foo');
284+
expect(rollbar.options.hostBlockList).to.contain('bar');
285+
done();
286+
});
257287
it('should store configured options', function(done) {
258288
var client = new (TestClientGen())();
259289
var options = {

0 commit comments

Comments
 (0)