public function CspSubscriber::onCspPolicyAlter in Raven: Sentry Integration 3.x
Same name and namespace in other branches
- 8.2 src/EventSubscriber/CspSubscriber.php \Drupal\raven\EventSubscriber\CspSubscriber::onCspPolicyAlter()
Alter CSP policy to allow Sentry to send JS errors.
Parameters
\Drupal\csp\Event\PolicyAlterEvent $alterEvent: The Policy Alter event.
File
- src/
EventSubscriber/ CspSubscriber.php, line 52
Class
- CspSubscriber
- Subscriber for CSP events.
Namespace
Drupal\raven\EventSubscriberCode
public function onCspPolicyAlter(PolicyAlterEvent $alterEvent) {
$config = $this->configFactory
->get('raven.settings');
if (!$config
->get('javascript_error_handler')) {
return;
}
if (!class_exists(Dsn::class)) {
return;
}
try {
$dsn = Dsn::createFromString(empty($_SERVER['SENTRY_DSN']) ? $config
->get('public_dsn') : $_SERVER['SENTRY_DSN']);
} catch (\InvalidArgumentException $e) {
// Raven is incorrectly configured.
return;
}
self::fallbackAwareAppendIfEnabled($alterEvent
->getPolicy(), 'connect-src', [
$dsn
->getStoreApiEndpointUrl(),
$dsn
->getEnvelopeApiEndpointUrl(),
]);
}