Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Improve use of Configuration.filters
Browse files Browse the repository at this point in the history
Apply metaData filters to request, app, user, device and breadcrumbs
  • Loading branch information
bengourley committed Feb 22, 2018
2 parents ef816a1 + 31448be commit 06b1df2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/notification.js
Expand Up @@ -165,9 +165,6 @@ Notification.prototype._deliver = function (cb) {
cb = null;
}

// Filter before sending
this.events[0].metaData = Utils.filterObject(this.events[0].metaData, Configuration.filters);

var port = Configuration.notifyPort || (Configuration.useSSL ? 443 : 80);

Configuration.logger.info("Delivering exception to " + (Configuration.useSSL ? "https" : "http") + "://" + Configuration.notifyHost + ":" + port + Configuration.notifyPath);
Expand Down Expand Up @@ -212,6 +209,10 @@ Notification.prototype._deliver = function (cb) {
Notification.prototype.serializePayload = function() {
var handledState = this.handledState;
delete this.handledState;
var event = this.events[0];
[ "user", "app", "metaData", "breadcrumbs", "request", "device" ].forEach(function (prop) {
event[prop] = Utils.filterObject(event[prop], Configuration.filters)
});
var payload = stringify(this, null, null, function() {
return "[RECURSIVE]";
});
Expand Down
30 changes: 30 additions & 0 deletions test/notification.js
Expand Up @@ -90,6 +90,7 @@ describe("Notification", function() {
afterEach(function() {
Notification.prototype._deliver.restore();
Configuration.beforeNotifyCallbacks = []
Bugsnag.metaData = {}
Notification.prototype.loadCode.restore();
});

Expand Down Expand Up @@ -511,4 +512,33 @@ describe("Notification", function() {
done();
});
});

describe("filters", function (done) {
it("should filter metaData with keys matching default Configuration.filters", function (done) {
Bugsnag.notify("uh oh", { account: { id: '123', password: "s0 s3cure"} });
var payload = deliverStub.firstCall.thisValue.serializePayload();
var payloadObject = JSON.parse(payload)
payloadObject.events[0].metaData.account.password.should.equal('[FILTERED]')
done();
});

it("should filter metaData with keys matching custom Configuration.filters", function (done) {
Bugsnag.configure({ filters: [ 'flip' ]})
Bugsnag.notify("uh oh", { abbc: { id: '123', flip: "112" } });
var payload = deliverStub.firstCall.thisValue.serializePayload();
var payloadObject = JSON.parse(payload)
payloadObject.events[0].metaData.abbc.flip.should.equal('[FILTERED]')
done();
});

it("should filter the request property", function (done) {
Bugsnag.configure({ filters: [ 'Authorization' ]})
Bugsnag.notify("uh oh", { req: { headers: { 'Authorization': 's0 s3cure', 'x-beep-boop': 100 } } });
var payload = deliverStub.firstCall.thisValue.serializePayload();
var payloadObject = JSON.parse(payload)
payloadObject.events[0].request.headers['x-beep-boop'].should.equal(100)
payloadObject.events[0].request.headers['Authorization'].should.equal('[FILTERED]')
done();
});
});
});

0 comments on commit 06b1df2

Please sign in to comment.