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

Apply metaData filters to request, app, user, device and breadcrumbs #131

Merged
merged 1 commit into from
Feb 22, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/notification.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();
});
});
});