Skip to content

Commit

Permalink
Merge pull request #106 from MindscapeHQ/recursive-filtering
Browse files Browse the repository at this point in the history
Recursive filtering
  • Loading branch information
fundead committed Mar 26, 2015
2 parents 9d13c6c + 7aac169 commit ebd1df7
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* v1.18.0
- Add new setFilterScope() function for supporting applying the filterSensitiveData keys across the entire payload (supported scopes are 'all' and 'customData')

* v1.17.0
- Add location.hash to Request.Url before payload is sent

Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,23 @@ Raygun.setVersion('1.0.0.0');

This will allow you to filter the errors in the dashboard by that version. You can also select only the latest version, to ignore errors that were triggered by ancient versions of your code. The parameter needs to be a string in the format x.x.x.x, where x is a positive integer.

### Filter sensitive request data
### Filtering sensitive data

The library automatically transmits query string key-values. To filter sensitive keys from this, call:
You can blacklist keys to prevent their values from being sent it the payload by providing an array of key names:

```javascript
Raygun.filterSensitiveData(['pwd']);
Raygun.filterSensitiveData(['password', 'credit_card']);
```

It accepts an array of strings. If a key in the query string matches any in this array, it won't be sent.
By default this is applied to the UserCustomData object only (legacy behavior). To apply this to any key-value pair, you can change the filtering scope:

```javascript
// Filter any key in the payload
Raygun.setFilterScope('all');

// Just filter the custom data (default)
Raygun.setFilterScope('customData');
```

### Source maps support

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raygun4js",
"version": "1.17.0",
"version": "1.18.0",
"homepage": "http://raygun.io",
"authors": [
"Mindscape <[email protected]>"
Expand Down
32 changes: 27 additions & 5 deletions dist/raygun.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raygun4js - v1.17.0 - 2015-03-20
/*! Raygun4js - v1.18.0 - 2015-03-27
* https://github.com/MindscapeHQ/raygun4js
* Copyright (c) 2015 MindscapeHQ; Licensed MIT */
(function(window, undefined) {
Expand Down Expand Up @@ -1223,6 +1223,7 @@ var raygunFactory = function (window, $, undefined) {
_raygunApiUrl = 'https://api.raygun.io',
_excludedHostnames = null,
_excludedUserAgents = null,
_filterScope = 'customData',
$document;

if ($) {
Expand Down Expand Up @@ -1373,6 +1374,13 @@ var raygunFactory = function (window, $, undefined) {
return Raygun;
},

setFilterScope: function (scope) {
if (scope === 'customData' || scope === 'all') {
_filterScope = scope;
}
return Raygun;
},

whitelistCrossOriginDomains: function (whitelist) {
_whitelistedScriptDomains = whitelist;
return Raygun;
Expand Down Expand Up @@ -1617,7 +1625,7 @@ var raygunFactory = function (window, $, undefined) {
return value;
}

function filterObject(reference) {
function filterObject(reference, parentKey) {
if (reference == null) {
return reference;
}
Expand All @@ -1634,9 +1642,13 @@ var raygunFactory = function (window, $, undefined) {
}

if (Object.prototype.toString.call(propertyValue) === '[object Object]') {
reference[propertyName] = filterObject(propertyValue);
if ((parentKey !== 'Details' || propertyName !== 'Client')) {
reference[propertyName] = filterObject(filterValue(propertyName, propertyValue), propertyName);
}
} else {
if (typeof parentKey !== 'undefined' || propertyName !== 'OccurredOn') {
reference[propertyName] = filterValue(propertyName, propertyValue);
}
}
}

Expand Down Expand Up @@ -1751,7 +1763,13 @@ var raygunFactory = function (window, $, undefined) {

var screen = window.screen || { width: getViewPort().width, height: getViewPort().height, colorDepth: 8 };
var custom_message = options.customData && options.customData.ajaxErrorMessage;
var finalCustomData = filterObject(options.customData);

var finalCustomData;
if (_filterScope === 'customData') {
finalCustomData = filterObject(options.customData, 'UserCustomData');
} else {
finalCustomData = options.customData;
}

try {
JSON.stringify(finalCustomData);
Expand Down Expand Up @@ -1788,7 +1806,7 @@ var raygunFactory = function (window, $, undefined) {
},
'Client': {
'Name': 'raygun-js',
'Version': '1.16.2'
'Version': '1.18.0'
},
'UserCustomData': finalCustomData,
'Tags': options.tags,
Expand All @@ -1808,6 +1826,10 @@ var raygunFactory = function (window, $, undefined) {
ensureUser();
payload.Details.User = _user;

if (_filterScope === 'all') {
payload = filterObject(payload);
}

if (typeof _beforeSendCallback === 'function') {
var mutatedPayload = _beforeSendCallback(payload);

Expand Down
4 changes: 2 additions & 2 deletions dist/raygun.min.js

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions dist/raygun.vanilla.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raygun4js - v1.17.0 - 2015-03-20
/*! Raygun4js - v1.18.0 - 2015-03-27
* https://github.com/MindscapeHQ/raygun4js
* Copyright (c) 2015 MindscapeHQ; Licensed MIT */
(function(window, undefined) {
Expand Down Expand Up @@ -1159,6 +1159,7 @@ var raygunFactory = function (window, $, undefined) {
_raygunApiUrl = 'https://api.raygun.io',
_excludedHostnames = null,
_excludedUserAgents = null,
_filterScope = 'customData',
$document;

if ($) {
Expand Down Expand Up @@ -1309,6 +1310,13 @@ var raygunFactory = function (window, $, undefined) {
return Raygun;
},

setFilterScope: function (scope) {
if (scope === 'customData' || scope === 'all') {
_filterScope = scope;
}
return Raygun;
},

whitelistCrossOriginDomains: function (whitelist) {
_whitelistedScriptDomains = whitelist;
return Raygun;
Expand Down Expand Up @@ -1553,7 +1561,7 @@ var raygunFactory = function (window, $, undefined) {
return value;
}

function filterObject(reference) {
function filterObject(reference, parentKey) {
if (reference == null) {
return reference;
}
Expand All @@ -1570,9 +1578,13 @@ var raygunFactory = function (window, $, undefined) {
}

if (Object.prototype.toString.call(propertyValue) === '[object Object]') {
reference[propertyName] = filterObject(propertyValue);
if ((parentKey !== 'Details' || propertyName !== 'Client')) {
reference[propertyName] = filterObject(filterValue(propertyName, propertyValue), propertyName);
}
} else {
if (typeof parentKey !== 'undefined' || propertyName !== 'OccurredOn') {
reference[propertyName] = filterValue(propertyName, propertyValue);
}
}
}

Expand Down Expand Up @@ -1687,7 +1699,13 @@ var raygunFactory = function (window, $, undefined) {

var screen = window.screen || { width: getViewPort().width, height: getViewPort().height, colorDepth: 8 };
var custom_message = options.customData && options.customData.ajaxErrorMessage;
var finalCustomData = filterObject(options.customData);

var finalCustomData;
if (_filterScope === 'customData') {
finalCustomData = filterObject(options.customData, 'UserCustomData');
} else {
finalCustomData = options.customData;
}

try {
JSON.stringify(finalCustomData);
Expand Down Expand Up @@ -1724,7 +1742,7 @@ var raygunFactory = function (window, $, undefined) {
},
'Client': {
'Name': 'raygun-js',
'Version': '1.16.2'
'Version': '1.18.0'
},
'UserCustomData': finalCustomData,
'Tags': options.tags,
Expand All @@ -1744,6 +1762,10 @@ var raygunFactory = function (window, $, undefined) {
ensureUser();
payload.Details.User = _user;

if (_filterScope === 'all') {
payload = filterObject(payload);
}

if (typeof _beforeSendCallback === 'function') {
var mutatedPayload = _beforeSendCallback(payload);

Expand Down
4 changes: 2 additions & 2 deletions dist/raygun.vanilla.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "dist/raygun.js",
"title": "Raygun4js",
"description": "Raygun.io plugin for JavaScript",
"version": "1.17.0",
"version": "1.18.0",
"homepage": "https://github.com/MindscapeHQ/raygun4js",
"author": {
"name": "MindscapeHQ",
Expand Down
2 changes: 1 addition & 1 deletion raygun4js.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>raygun4js</id>
<version>1.17.0</version>
<version>1.18.0</version>
<title>Raygun4js</title>
<authors>Mindscape Limited</authors>
<owners>Mindscape Limited</owners>
Expand Down
30 changes: 26 additions & 4 deletions src/raygun.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var raygunFactory = function (window, $, undefined) {
_raygunApiUrl = 'https://api.raygun.io',
_excludedHostnames = null,
_excludedUserAgents = null,
_filterScope = 'customData',
$document;

if ($) {
Expand Down Expand Up @@ -181,6 +182,13 @@ var raygunFactory = function (window, $, undefined) {
return Raygun;
},

setFilterScope: function (scope) {
if (scope === 'customData' || scope === 'all') {
_filterScope = scope;
}
return Raygun;
},

whitelistCrossOriginDomains: function (whitelist) {
_whitelistedScriptDomains = whitelist;
return Raygun;
Expand Down Expand Up @@ -425,7 +433,7 @@ var raygunFactory = function (window, $, undefined) {
return value;
}

function filterObject(reference) {
function filterObject(reference, parentKey) {
if (reference == null) {
return reference;
}
Expand All @@ -442,9 +450,13 @@ var raygunFactory = function (window, $, undefined) {
}

if (Object.prototype.toString.call(propertyValue) === '[object Object]') {
reference[propertyName] = filterObject(propertyValue);
if ((parentKey !== 'Details' || propertyName !== 'Client')) {
reference[propertyName] = filterObject(filterValue(propertyName, propertyValue), propertyName);
}
} else {
if (typeof parentKey !== 'undefined' || propertyName !== 'OccurredOn') {
reference[propertyName] = filterValue(propertyName, propertyValue);
}
}
}

Expand Down Expand Up @@ -559,7 +571,13 @@ var raygunFactory = function (window, $, undefined) {

var screen = window.screen || { width: getViewPort().width, height: getViewPort().height, colorDepth: 8 };
var custom_message = options.customData && options.customData.ajaxErrorMessage;
var finalCustomData = filterObject(options.customData);

var finalCustomData;
if (_filterScope === 'customData') {
finalCustomData = filterObject(options.customData, 'UserCustomData');
} else {
finalCustomData = options.customData;
}

try {
JSON.stringify(finalCustomData);
Expand Down Expand Up @@ -596,7 +614,7 @@ var raygunFactory = function (window, $, undefined) {
},
'Client': {
'Name': 'raygun-js',
'Version': '1.16.2'
'Version': '1.18.0'
},
'UserCustomData': finalCustomData,
'Tags': options.tags,
Expand All @@ -616,6 +634,10 @@ var raygunFactory = function (window, $, undefined) {
ensureUser();
payload.Details.User = _user;

if (_filterScope === 'all') {
payload = filterObject(payload);
}

if (typeof _beforeSendCallback === 'function') {
var mutatedPayload = _beforeSendCallback(payload);

Expand Down

0 comments on commit ebd1df7

Please sign in to comment.