SanitizeHttpHeadersProcessor.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of Raven.
  4. *
  5. * (c) Sentry Team
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * This processor sanitizes the configured HTTP headers to ensure no sensitive
  12. * informations are sent to the server.
  13. *
  14. * @author Stefano Arlandini <sarlandini@alice.it>
  15. */
  16. final class Raven_Processor_SanitizeHttpHeadersProcessor extends Raven_Processor
  17. {
  18. /**
  19. * @var string[] $httpHeadersToSanitize The list of HTTP headers to sanitize
  20. */
  21. private $httpHeadersToSanitize = array();
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function __construct(Raven_Client $client)
  26. {
  27. parent::__construct($client);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function setProcessorOptions(array $options)
  33. {
  34. $this->httpHeadersToSanitize = array_merge($this->getDefaultHeaders(), isset($options['sanitize_http_headers']) ? $options['sanitize_http_headers'] : array());
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function process(&$data)
  40. {
  41. if (isset($data['request']) && isset($data['request']['headers'])) {
  42. foreach ($data['request']['headers'] as $header => &$value) {
  43. if (in_array($header, $this->httpHeadersToSanitize)) {
  44. $value = self::STRING_MASK;
  45. }
  46. }
  47. }
  48. }
  49. /**
  50. * Gets the list of default headers that must be sanitized.
  51. *
  52. * @return string[]
  53. */
  54. private function getDefaultHeaders()
  55. {
  56. return array('Authorization', 'Proxy-Authorization', 'X-Csrf-Token', 'X-CSRFToken', 'X-XSRF-TOKEN');
  57. }
  58. }