ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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;
39 
40  public function __construct(ilErrorHandling $error_handling)
41  {
42  $this->error_handling = $error_handling;
43  }
44 
45  private function hideSensitiveData(array $key_value_pairs): array
46  {
47  foreach ($key_value_pairs as $key => &$value) {
48  if (is_array($value)) {
49  $value = $this->hideSensitiveData($value);
50  }
51 
52  if ($key === 'password' && is_string($value)) {
53  $value = 'REMOVED FOR SECURITY';
54  }
55 
56  if ($key === 'PHPSESSID' && is_string($value)) {
57  $value = substr($value, 0, 5) . ' (SHORTENED FOR SECURITY)';
58  }
59 
60  if ($key === 'HTTP_COOKIE') {
61  $cookie_content = explode(';', $value);
62  foreach ($cookie_content as &$cookie_pair_string) {
63  $cookie_pair = explode('=', $cookie_pair_string);
64  if (trim($cookie_pair[0]) === session_name()) {
65  $cookie_pair[1] = substr($cookie_pair[1], 0, 5) . ' (SHORTENED FOR SECURITY)';
66  $cookie_pair_string = implode('=', $cookie_pair);
67  }
68  }
69  $value = implode(';', $cookie_content);
70  }
71  }
72 
73  return $key_value_pairs;
74  }
75 
83  public function handle(): ?int
84  {
85  if (defined("IL_INITIAL_WD")) {
86  chdir(IL_INITIAL_WD);
87  }
88 
89  /* We must cast the superglobals back to normal arrays since the error handler needs them. They were replaced by
90  SuperGlobalDropInReplacement . The keys contain NULL bytes, so accessing values directly by key is not
91  really possible */
92  $_GET = $this->hideSensitiveData((array) $_GET);
93  $_POST = $this->hideSensitiveData((array) $_POST);
94  $_COOKIE = $this->hideSensitiveData((array) $_COOKIE);
95  $_REQUEST = $this->hideSensitiveData((array) $_REQUEST);
96 
98 
99  $this->current_handler = $this->error_handling->getHandler();
100  $this->current_handler->setRun($this->getRun());
101  $this->current_handler->setException($this->getException());
102  $this->current_handler->setInspector($this->getInspector());
103  return $this->current_handler->handle();
104  }
105 
110  public function contentType(): ?string
111  {
112  if ($this->current_handler === null ||
113  !method_exists($this->current_handler, 'contentType')) {
114  return null;
115  }
116 
117  return $this->current_handler->contentType();
118  }
119 }
$_GET["client_id"]
Definition: webdav.php:30
contentType()
This is an implicit interface method of the Whoops handlers.
handle()
Last missing method from HandlerInterface.
A Whoops error handler that delegates calls on it self to another handler that is created only in the...
__construct(ilErrorHandling $error_handling)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$_COOKIE[session_name()]
Definition: xapitoken.php:54
hideSensitiveData(array $key_value_pairs)