PHP code example of yorcreative / laravel-scrubber
1. Go to this page and download the library: Download yorcreative/laravel-scrubber library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yorcreative / laravel-scrubber example snippets
return [
/**
* Specify the string to use to redact the data
*/
'redaction' => '**redacted**',
'secret_manager' => [
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
'enabled' => false,
'providers' => [
// See "Secret Manager Providers" section for full configuration options
'gitlab' => ['enabled' => false, /* ... */],
'aws' => ['enabled' => false, /* ... */],
'vault' => ['enabled' => false, /* ... */],
'azure' => ['enabled' => false, /* ... */],
'google' => ['enabled' => false, /* ... */],
],
],
/**
* Specify the regexes to load
* You can use a wildcard (*) to load all regexes in all `custom_regex_namespaces` and the default core regexes.
* Otherwise, specify the regexes you want to load either by qualified class name or by unqualified (base) class name,
* which will then search the `custom_regex_namespaces` and the default core regexes for a match.
*/
'regex_loader' => ['*'],
/**
* Specify regex patterns to exclude from loading when using the regex loader
* This allows fine-grained control over which regex patterns are loaded, especially useful when using wildcard (*) in regex_loader
*
* You can exclude patterns using any of these formats:
* - Fully qualified class name (e.g., 'YorCreative\Scrubber\RegexCollection\GoogleApi')
* - Base class name (e.g., 'GoogleApi', 'EmailAddress')
* - Pattern constant from RegexCollection (e.g., RegexCollection::$GOOGLE_API)
* - Custom namespace class (e.g., 'App\Scrubber\RegexCollection\HerokuApiKey')
*
* Example:
* [
* 'GoogleApi',
* 'YorCreative\Scrubber\RegexCollection\EmailAddress',
* RegexCollection::$HEROKU_API_KEY,
* 'App\Scrubber\RegexCollection\HerokuApiKey'
* ]
*/
'exclude_regex' => [],
/**
* Specify namespaces from which regexes will be loaded when using the wildcard (*)
* for the regex_loader or where you use unqualified class names.
*/
'custom_regex_namespaces' => [
'App\\Scrubber\\RegexCollection',
],
/**
* Specify config keys for which the values will be scrubbed
* You should use the dot notation to specify the keys
* You can use wildcards (*) to match multiple keys
*
* - 'database.connections.*.password'
* - 'app.secrets.*'
* - 'app.some.nested.key'
*/
'config_loader' => [
'*token',
'*key',
'*secret',
'*password',
],
/**
* Minimum character length for config values to be treated as scrubbable.
* Values shorter than this will be ignored to prevent overly aggressive
* scrubbing (e.g., Livewire's release_token defaults to 'a').
*/
'config_loader_min_length' => 4,
/**
* Config key patterns to exclude from scrubbing.
* Supports wildcards (*) via Str::is().
*/
'config_loader_exclusions' => [],
/**
* Specify the channels to tap into
* You can use wildcards (*) to match multiple channels
*/
'tap_channels' => false,
];
// Get scrubbing statistics for the current request
$stats = Scrubber::getStats();
// ['total_scrubs' => 5, 'patterns_matched' => ['JsonWebToken' => 2, 'EmailAddress' => 3]]
// Test a string without modifying stats - useful for debugging
$result = Scrubber::test('Contact: [email protected], SSN: 123-45-6789');
// [
// 'matched' => true,
// 'patterns' => ['EmailAddress' => 1, 'SocialSecurityNumber' => 1],
// 'scrubbed' => 'Contact: **redacted**, SSN: ***-**-****'
// ]
// Reset statistics between requests
Scrubber::resetStats();
'events' => [
'enabled' => true,
],
use YorCreative\Scrubber\Events\SensitiveDataDetected;
Event::listen(SensitiveDataDetected::class, function (SensitiveDataDetected $event) {
// $event->patternName — e.g. 'JsonWebToken'
// $event->hitCount — e.g. 2
// $event->context — 'log' or 'manual'
});
namespace App\Scrubber\RegexCollection;
use YorCreative\Scrubber\Interfaces\RegexCollectionInterface;
class TestRegex implements RegexCollectionInterface
{
public function getPattern(): string
{
/**
* @note return a regex pattern to detect a specific piece of sensitive data.
*/
return '(?<=basic) [a-zA-Z0-9=:\\+\/-]{5,100}';
}
public function getTestableString(): string
{
/**
* @note return a string that can be used to verify the regex pattern provided.
*/
return 'basic f9Iu+YwMiJEsQu/vBHlbUNZRkN/ihdB1sNTU';
}
public function getReplacementValue(): string
{
/**
* @note return a string that replaces the regex pattern provided.
*/
return config('scrubber.redaction');
}
public function isSecret(): bool
{
return false;
}
}
'exclude_regex' => [
// Exclude by base class name
'GoogleApi',
// Exclude by fully qualified class name
'YorCreative\Scrubber\RegexCollection\EmailAddress',
// Exclude using RegexCollection constant
RegexCollection::$HEROKU_API_KEY,
// Exclude from custom namespace
'App\Scrubber\RegexCollection\HerokuApiKey'
],
// Default: ignore values shorter than 4 characters
'config_loader_min_length' => 4,
// Set to 0 to disable the minimum length filter
'config_loader_min_length' => 0,
'config_loader_exclusions' => [
// Exclude a specific key
'livewire.release_token',
// Exclude all keys under a namespace
'livewire.*',
],
'gitlab' => [
'enabled' => true,
'project_id' => env('GITLAB_PROJECT_ID'),
'token' => env('GITLAB_TOKEN'),
'host' => 'https://gitlab.com', // Or your self-hosted GitLab URL
'keys' => ['*'], // Or specific variable names: ['DB_PASSWORD', 'API_KEY']
],