|
19 | 19 | A Laravel package to scrub sensitive information that breaks operational security policies from being leaked on |
20 | 20 | accident ~~_or not_~~ by developers. |
21 | 21 |
|
| 22 | +## Requirements |
| 23 | + |
| 24 | +- PHP 8.1, 8.2, 8.3, 8.4, or 8.5 |
| 25 | +- Laravel 10.x, 11.x, or 12.x |
| 26 | + |
22 | 27 | ## Installation |
23 | 28 |
|
24 | 29 | install the package via composer: |
@@ -171,6 +176,27 @@ Scrubber::processMessage('<insert jwt token here>'); |
171 | 176 | // **redacted** |
172 | 177 | ``` |
173 | 178 |
|
| 179 | +### Detection Statistics API |
| 180 | + |
| 181 | +Track what patterns are matching and how often: |
| 182 | + |
| 183 | +```php |
| 184 | +// Get scrubbing statistics for the current request |
| 185 | +$stats = Scrubber::getStats(); |
| 186 | +// ['total_scrubs' => 5, 'patterns_matched' => ['JsonWebToken' => 2, 'EmailAddress' => 3]] |
| 187 | + |
| 188 | +// Test a string without modifying stats - useful for debugging |
| 189 | +$result = Scrubber::test('Contact: john@example.com, SSN: 123-45-6789'); |
| 190 | +// [ |
| 191 | +// 'matched' => true, |
| 192 | +// 'patterns' => ['EmailAddress' => 1, 'SocialSecurityNumber' => 1], |
| 193 | +// 'scrubbed' => 'Contact: **redacted**, SSN: ***-**-****' |
| 194 | +// ] |
| 195 | + |
| 196 | +// Reset statistics between requests |
| 197 | +Scrubber::resetStats(); |
| 198 | +``` |
| 199 | + |
174 | 200 | ## Log Channel Opt-in |
175 | 201 |
|
176 | 202 | This package provides you the ability to define through the configuration file what channels you want to scrub |
@@ -215,6 +241,28 @@ class. |
215 | 241 | ], |
216 | 242 | ``` |
217 | 243 |
|
| 244 | +> **Note**: The package includes 31 built-in patterns. See all available patterns in [RegexCollection.php](https://github.com/YorCreative/Laravel-Scrubber/blob/main/src/Repositories/RegexCollection.php). |
| 245 | +
|
| 246 | +### PII Detection with Partial Masking |
| 247 | + |
| 248 | +The following patterns use contextual replacement values for improved readability instead of the generic `**redacted**`: |
| 249 | + |
| 250 | +| Pattern | Detects | Masked Output | |
| 251 | +|---------|---------|---------------| |
| 252 | +| `RegexCollection::$SOCIAL_SECURITY_NUMBER` | US Social Security Numbers | `***-**-****` | |
| 253 | +| `RegexCollection::$PHONE_NUMBER` | Phone numbers (US/International) | `(***) ***-****` | |
| 254 | +| `RegexCollection::$IP_ADDRESS_V4` | IPv4 addresses | `***.***.***.***` | |
| 255 | +| `RegexCollection::$IP_ADDRESS_V6` | IPv6 addresses | `****:****:****:...` | |
| 256 | +| `RegexCollection::$IBAN` | International Bank Account Numbers | `********************` | |
| 257 | + |
| 258 | +```php |
| 259 | +Scrubber::processMessage('SSN: 123-45-6789, Phone: (555) 123-4567'); |
| 260 | +// "SSN: ***-**-****, Phone: (***) ***-****" |
| 261 | + |
| 262 | +Scrubber::processMessage('Server IP: 192.168.1.1'); |
| 263 | +// "Server IP: ***.***.***.***" |
| 264 | +``` |
| 265 | + |
218 | 266 | ### Opting Into Custom Extended Classes |
219 | 267 |
|
220 | 268 | > To create custom scrubbers, see the [Extending the Scrubber](#extending-the-scrubber) section. |
|
0 commit comments