RavenSanitizeIntegration.php in Raven: Sentry Integration 7.4
File
RavenSanitizeIntegration.php
View source
<?php
declare (strict_types=1);
use Sentry\Event;
use Sentry\Integration\IntegrationInterface;
use Sentry\Options;
use Sentry\SentrySdk;
use Sentry\State\Scope;
class RavenSanitizeIntegration implements IntegrationInterface {
const STRING_MASK = '********';
public function setupOnce() : void {
Scope::addGlobalEventProcessor(function (Event $event) : Event {
$currentHub = SentrySdk::getCurrentHub();
$integration = $currentHub
->getIntegration(self::class);
$client = $currentHub
->getClient();
if (NULL === $integration || NULL === $client) {
return $event;
}
$this
->processEvent($event, $client
->getOptions());
return $event;
});
}
private function processEvent(Event $event, Options $options) : void {
$request = $event
->getRequest();
if (!empty($request['data']['pass'])) {
$request['data']['pass'] = self::STRING_MASK;
}
$event
->setRequest($request);
foreach ($event
->getExceptions() as $exception) {
foreach ($exception
->getStacktrace()
->getFrames() as $frame) {
$vars = $frame
->getVars();
array_walk_recursive($vars, function (&$value, $key) {
if (($key === 'pass' || $key === 'sid' || $key === 'ssid') && is_string($value) && $value) {
$value = self::STRING_MASK;
}
});
$frame
->setVars($vars);
}
}
}
}