ILIAS  release_8 Revision v8.23
class.ilDelegatingHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
35 final class ilDelegatingHandler extends Handler
36 {
38  private ?HandlerInterface $current_handler = null;
40  private array $sensitive_data = [];
41 
45  public function __construct(
46  ilErrorHandling $error_handling,
47  array $sensitive_data = []
48  ) {
49  $this->error_handling = $error_handling;
50  $this->sensitive_data = $sensitive_data;
51  }
52 
53  private function hideSensitiveData(array $key_value_pairs): array
54  {
55  foreach ($key_value_pairs as $key => &$value) {
56  if (is_array($value)) {
57  $value = $this->hideSensitiveData($value);
58  }
59 
60  if (is_string($value) && in_array($key, $this->sensitive_data, true)) {
61  $value = 'REMOVED FOR SECURITY';
62  }
63 
64  if ($key === 'PHPSESSID' && is_string($value)) {
65  $value = substr($value, 0, 5) . ' (SHORTENED FOR SECURITY)';
66  }
67 
68  if ($key === 'HTTP_COOKIE') {
69  $cookie_content = explode(';', $value);
70  foreach ($cookie_content as &$cookie_pair_string) {
71  $cookie_pair = explode('=', $cookie_pair_string);
72  if (trim($cookie_pair[0]) === session_name()) {
73  $cookie_pair[1] = substr($cookie_pair[1], 0, 5) . ' (SHORTENED FOR SECURITY)';
74  $cookie_pair_string = implode('=', $cookie_pair);
75  }
76  }
77  $value = implode(';', $cookie_content);
78  }
79  }
80 
81  return $key_value_pairs;
82  }
83 
91  public function handle(): ?int
92  {
93  if (defined("IL_INITIAL_WD")) {
94  chdir(IL_INITIAL_WD);
95  }
96 
97  /* We must cast the superglobals back to normal arrays since the error handler needs them. They were replaced by
98  SuperGlobalDropInReplacement . The keys contain NULL bytes, so accessing values directly by key is not
99  really possible */
100  $_GET = $this->hideSensitiveData((array) $_GET);
101  $_POST = $this->hideSensitiveData((array) $_POST);
102  $_COOKIE = $this->hideSensitiveData((array) $_COOKIE);
103  $_REQUEST = $this->hideSensitiveData((array) $_REQUEST);
104 
106 
107  $this->current_handler = $this->error_handling->getHandler();
108  $this->current_handler->setRun($this->getRun());
109  $this->current_handler->setException($this->getException());
110  $this->current_handler->setInspector($this->getInspector());
111  return $this->current_handler->handle();
112  }
113 
118  public function contentType(): ?string
119  {
120  if ($this->current_handler === null ||
121  !method_exists($this->current_handler, 'contentType')) {
122  return null;
123  }
124 
125  return $this->current_handler->contentType();
126  }
127 }
contentType()
This is an implicit interface method of the Whoops handlers.
handle()
Last missing method from HandlerInterface.
__construct(ilErrorHandling $error_handling, array $sensitive_data=[])
A Whoops error handler that delegates calls on it self to another handler that is created only in the...
$_GET['client_id']
Definition: saml1-acs.php:21
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
string $key
Consumer key/client ID value.
Definition: System.php:193
Error Handling & global info handling uses PEAR error class.
$_COOKIE[session_name()]
Definition: xapitoken.php:54
hideSensitiveData(array $key_value_pairs)