From 31448beb750e44713375613ae7616118bbfb81ad Mon Sep 17 00:00:00 2001 From: Ben Gourley Date: Wed, 21 Feb 2018 15:43:50 +0000 Subject: [PATCH] Apply metaData filters to request, app, user, device and breadcrumbs --- lib/notification.js | 7 ++++--- test/notification.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/notification.js b/lib/notification.js index b7f0a55..1e4579e 100644 --- a/lib/notification.js +++ b/lib/notification.js @@ -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); @@ -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]"; }); diff --git a/test/notification.js b/test/notification.js index defc527..0b8690c 100644 --- a/test/notification.js +++ b/test/notification.js @@ -90,6 +90,7 @@ describe("Notification", function() { afterEach(function() { Notification.prototype._deliver.restore(); Configuration.beforeNotifyCallbacks = [] + Bugsnag.metaData = {} Notification.prototype.loadCode.restore(); }); @@ -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(); + }); + }); });