Skip to content

Commit

Permalink
Merge pull request #432 from bugsnag/redacted-keys
Browse files Browse the repository at this point in the history
Support the new redacted keys option
  • Loading branch information
imjoehaines authored Feb 10, 2021
2 parents 86a7f18 + 88d6a32 commit 9afef11
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Changelog
* Support the new `discardClasses` configuration option. This allows events to be discarded based on the exception class name or PHP error name.
[#431](https://github.com/bugsnag/bugsnag-laravel/pull/431)

* Support the new `redactedKeys` configuration option. This is similar to `filters` but allows both strings and regexes. String matching is exact but case-insensitive. Regex matching allows for partial and wildcard matching.
[#432](https://github.com/bugsnag/bugsnag-laravel/pull/432)

### Deprecations

* The `filters` configuration option is now deprecated as `redactedKeys` can express everything that filters could and more.

## 2.21.0 (2020-11-25)

### Enhancements
Expand Down
13 changes: 13 additions & 0 deletions config/bugsnag.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
| passwords, and credit card numbers to our servers. Any keys which
| contain these strings will be filtered.
|
| This option has been deprecated in favour of 'redacted_keys'
|
*/

'filters' => empty(env('BUGSNAG_FILTERS')) ? null : explode(',', str_replace(' ', '', env('BUGSNAG_FILTERS'))),
Expand Down Expand Up @@ -317,4 +319,15 @@
*/

'discard_classes' => empty(env('BUGSNAG_DISCARD_CLASSES')) ? null : explode(',', env('BUGSNAG_DISCARD_CLASSES')),

/*
|--------------------------------------------------------------------------
| Redacted Keys
|--------------------------------------------------------------------------
|
| An array of metadata keys that should be redacted.
|
*/

'redacted_keys' => empty(env('BUGSNAG_REDACTED_KEYS')) ? null : explode(',', env('BUGSNAG_REDACTED_KEYS')),
];
4 changes: 4 additions & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- BUGSNAG_USE_CUSTOM_GUZZLE
- BUGSNAG_REGISTER_OOM_BOOTSTRAPPER
- BUGSNAG_DISCARD_CLASSES
- BUGSNAG_REDACTED_KEYS
restart: "no"
ports:
- target: 8000
Expand All @@ -31,6 +32,7 @@ services:
- BUGSNAG_USE_CUSTOM_GUZZLE
- BUGSNAG_REGISTER_OOM_BOOTSTRAPPER
- BUGSNAG_DISCARD_CLASSES
- BUGSNAG_REDACTED_KEYS
restart: "no"
ports:
- target: 8000
Expand All @@ -49,6 +51,7 @@ services:
- BUGSNAG_USE_CUSTOM_GUZZLE
- BUGSNAG_REGISTER_OOM_BOOTSTRAPPER
- BUGSNAG_DISCARD_CLASSES
- BUGSNAG_REDACTED_KEYS
restart: "no"
ports:
- target: 8000
Expand All @@ -67,6 +70,7 @@ services:
- BUGSNAG_USE_CUSTOM_GUZZLE
- BUGSNAG_REGISTER_OOM_BOOTSTRAPPER
- BUGSNAG_DISCARD_CLASSES
- BUGSNAG_REDACTED_KEYS
restart: "no"
ports:
- target: 8000
Expand Down
20 changes: 20 additions & 0 deletions features/redacted_keys.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Redacted keys

Scenario: Keys won't be redacted with no redacted keys
Given I start the laravel fixture
When I navigate to the route "/unhandled_controller_exception"
Then I wait to receive a request
And the request is valid for the error reporting API version "4.0" for the "Bugsnag Laravel" notifier
And the event "metaData.request.httpMethod" equals "GET"
And the event "metaData.request.url" ends with "/unhandled_controller_exception"
And the event "metaData.request.userAgent" equals "Ruby"

Scenario: Keys can be redacted from metadata
Given I set environment variable "BUGSNAG_REDACTED_KEYS" to "HTTPmethod,/^url$/"
And I start the laravel fixture
When I navigate to the route "/unhandled_controller_exception"
Then I wait to receive a request
And the request is valid for the error reporting API version "4.0" for the "Bugsnag Laravel" notifier
And the event "metaData.request.httpMethod" equals "[FILTERED]"
And the event "metaData.request.url" equals "[FILTERED]"
And the event "metaData.request.userAgent" equals "Ruby"
4 changes: 4 additions & 0 deletions src/BugsnagServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public function register()
$client->setDiscardClasses($config['discard_classes']);
}

if (isset($config['redacted_keys']) && is_array($config['redacted_keys'])) {
$client->setRedactedKeys($config['redacted_keys']);
}

return $client;
});

Expand Down
2 changes: 2 additions & 0 deletions src/Facades/Bugsnag.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @method static array getNotifier()
* @method static string getNotifyEndpoint()
* @method static \Bugsnag\Pipeline getPipeline()
* @method static array getRedactedKeys()
* @method static string getSessionEndpoint()
* @method static \Bugsnag\SessionTracker getSessionTracker()
* @method static string getStrippedFilePath(string $file)
Expand Down Expand Up @@ -50,6 +51,7 @@
* @method static \Bugsnag\Client setProjectRoot(string|null $projectRoot)
* @method static \Bugsnag\Client setProjectRootRegex(string|null $projectRootRegex)
* @method static \Bugsnag\Client setReleaseStage(string|null $releaseStage)
* @method static \Bugsnag\Client setRedactedKeys(array $redactedKeys)
* @method static \Bugsnag\Client setSendCode(bool $sendCode)
* @method static \Bugsnag\Client setSessionEndpoint(string $endpoint)
* @method static \Bugsnag\Client setStripPath(string|null $stripPath)
Expand Down

0 comments on commit 9afef11

Please sign in to comment.