Skip to content

Commit

Permalink
Merge pull request #597 from bugsnag/http-basic-auth-filters
Browse files Browse the repository at this point in the history
Add HTTP basic auth headers to default filters
  • Loading branch information
imjoehaines authored Sep 14, 2020
2 parents d33e643 + ab959da commit f45c609
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Changelog
* Cookies are now filtered from events by default
[#596](https://github.com/bugsnag/bugsnag-php/pull/596)

* HTTP basic auth headers are filtered from events by default
[#597](https://github.com/bugsnag/bugsnag-php/pull/597)

## 3.22.0 (2020-08-20)

### Enhancements
Expand Down
9 changes: 8 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ class Configuration
*
* @var string[]
*/
protected $filters = ['password', 'cookie'];
protected $filters = [
'password',
'cookie',
'authorization',
'php-auth-user',
'php-auth-pw',
'php-auth-digest',
];

/**
* The project root regex.
Expand Down
3 changes: 3 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ public function testItAddsADefaultSetOfMiddlewares()
$_SERVER['HTTP_COOKIE'] = 'tastes=delicious';
$_SERVER['HTTP_X_FORWARDED_FOR'] = '8.76.54.321';
$_SERVER['REQUEST_URI'] = '/abc/xyz?abc=1&xyz=2';
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic YTpi';
$_GET['abc'] = '1';
$_GET['xyz'] = '2';
$_COOKIE['tastes'] = 'delicious';
Expand Down Expand Up @@ -408,6 +409,7 @@ function (Report $report) use (&$pipelineCompleted) {
'Host' => 'example.com',
'Cookie' => 'tastes=delicious',
'X-Forwarded-For' => '8.76.54.321',
'Authorization' => 'Basic YTpi',
],
],
'session' => [
Expand All @@ -426,6 +428,7 @@ function (Report $report) use (&$pipelineCompleted) {
'Host' => 'example.com',
'Cookie' => '[FILTERED]',
'X-Forwarded-For' => '8.76.54.321',
'Authorization' => '[FILTERED]',
],
$payload['metaData']['request']['headers']
);
Expand Down
23 changes: 19 additions & 4 deletions tests/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,27 @@ public function testUser()

public function testDefaultFilters()
{
$this->report->setMetaData([
'Testing' => ['password' => '123456', 'Cookie' => 'abc=xyz'],
]);
$metadata = array_reduce(
$this->config->getFilters(),
function ($metadata, $filter) {
$metadata[$filter] = "abc {$filter} xyz";

return $metadata;
},
[]
);

$this->report->setMetaData(['Testing' => $metadata]);

$this->assertSame(
['password' => '[FILTERED]', 'Cookie' => '[FILTERED]'],
[
'password' => '[FILTERED]',
'cookie' => '[FILTERED]',
'authorization' => '[FILTERED]',
'php-auth-user' => '[FILTERED]',
'php-auth-pw' => '[FILTERED]',
'php-auth-digest' => '[FILTERED]',
],
$this->report->toArray()['metaData']['Testing']
);
}
Expand Down

0 comments on commit f45c609

Please sign in to comment.