Skip to content

Commit 50ae6c2

Browse files
Redact user metadata according to redacted keys configuration (#675)
* Redact user fields according to filters * Add unit tests for user fields filtering * Add changelog entry
1 parent 76a0d58 commit 50ae6c2

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
## TBD
5+
6+
### Fixes
7+
8+
* Redact user metadata according to redacted keys configuration
9+
[#675](https://github.com/bugsnag/bugsnag-php/pull/675)
10+
411
## 3.29.2 (2025-01-13)
512

613
This release should ensure compatibility with PHP 8.4 by removing the usage of certain

src/Report.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ public function toArray()
764764
$event = [
765765
'app' => $this->config->getAppData(),
766766
'device' => array_merge(['time' => $this->time], $this->config->getDeviceData()),
767-
'user' => $this->getUser(),
767+
'user' => $this->cleanupObj($this->getUser(), true),
768768
'context' => $this->getContext(),
769769
'payloadVersion' => HttpClient::NOTIFY_PAYLOAD_VERSION,
770770
'severity' => $this->getSeverity(),

tests/ReportTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ public function testUser()
117117
$this->assertSame(['foo' => 'bar'], $this->report->toArray()['user']);
118118
}
119119

120+
public function testUserDefaultFilters()
121+
{
122+
$this->report->setUser(['foo' => 'bar', 'password' => 'mypass', 'custom_field' => 'some data']);
123+
124+
$this->assertSame(['foo' => 'bar', 'password' => '[FILTERED]', 'custom_field' => 'some data'], $this->report->toArray()['user']);
125+
}
126+
127+
public function testUserCustomFilters()
128+
{
129+
$this->config->setFilters(['custom_field']);
130+
131+
$this->report->setUser(['foo' => 'bar', 'password' => 'mypass', 'custom_field' => 'some data']);
132+
133+
$this->assertSame(['foo' => 'bar', 'password' => 'mypass', 'custom_field' => '[FILTERED]'], $this->report->toArray()['user']);
134+
}
135+
120136
public function testDefaultFilters()
121137
{
122138
$metadata = array_reduce(

0 commit comments

Comments
 (0)