|
4 | 4 | use Gt\Config\Config; |
5 | 5 | use Gt\Config\ConfigFactory; |
6 | 6 | use Gt\Config\ConfigSection; |
7 | | -use Gt\Csrf\HTMLDocumentProtector; |
8 | | -use Gt\Csrf\SessionTokenStore; |
9 | 7 | use Gt\Dom\HTMLDocument; |
10 | 8 | use Gt\DomTemplate\ComponentExpander; |
11 | 9 | use Gt\DomTemplate\DocumentBinder; |
@@ -149,6 +147,9 @@ public function handle( |
149 | 147 | $serviceContainer->set($viewModel); |
150 | 148 | } |
151 | 149 |
|
| 150 | + $input = new Input($_GET, $_POST, $_FILES); |
| 151 | + $serviceContainer->set($input); |
| 152 | + |
152 | 153 | if($viewModel instanceof HTMLDocument) { |
153 | 154 | try { |
154 | 155 | $partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [ |
@@ -195,67 +196,19 @@ public function handle( |
195 | 196 | $sessionId |
196 | 197 | ); |
197 | 198 | $serviceContainer->set($session); |
198 | | - |
199 | | - $session = $serviceContainer->get(Session::class); |
200 | | - |
201 | | - $shouldVerifyCsrf = true; |
202 | | - $ignoredPathArray = explode(",", $this->config->getString("security.csrf_ignore_path") ?? ""); |
203 | | - foreach($ignoredPathArray as $ignoredPath) { |
204 | | - if(empty($ignoredPath)) { |
205 | | - continue; |
206 | | - } |
207 | | - |
208 | | - if(str_contains($ignoredPath, "*")) { |
209 | | - $pattern = strtr(rtrim($ignoredPath, "/"), [ |
210 | | - "*" => ".*", |
211 | | - ]); |
212 | | - if(preg_match("|$pattern|", rtrim($uriPath, "/"))) { |
213 | | - $shouldVerifyCsrf = false; |
214 | | - } |
215 | | - } |
216 | | - else { |
217 | | - if(rtrim($uriPath, "/") === rtrim($ignoredPath, "/")) { |
218 | | - $shouldVerifyCsrf = false; |
219 | | - } |
220 | | - } |
221 | | - } |
222 | | - |
223 | | - if($shouldVerifyCsrf) { |
224 | | - $csrfTokenStore = new SessionTokenStore( |
225 | | - $session->getStore("webengine.csrf", true), |
226 | | - $this->config->getInt("security.csrf_max_tokens") |
227 | | - ); |
228 | | - $csrfTokenStore->setTokenLength( |
229 | | - $this->config->getInt("security.csrf_token_length") |
230 | | - ); |
231 | | - |
232 | | - if($request->getMethod() === "POST") { |
233 | | - $csrfTokenStore->verify($_POST); |
234 | | - } |
235 | | - |
236 | | - $sharing = match($this->config->getString("security.csrf_token_sharing")) { |
237 | | - "per-page" => HTMLDocumentProtector::ONE_TOKEN_PER_PAGE, |
238 | | - default => HTMLDocumentProtector::ONE_TOKEN_PER_FORM, |
239 | | - }; |
240 | | - $protector = new HTMLDocumentProtector($viewModel, $csrfTokenStore); |
241 | | - $tokens = $protector->protect($sharing); |
242 | | - $response = $response->withHeader($this->config->getString("security.csrf_header"), $tokens); |
243 | | - } |
244 | 199 | } |
245 | 200 |
|
246 | | - $input = new Input($_GET, $_POST, $_FILES); |
247 | | - $serviceContainer->set($input); |
248 | | - |
249 | 201 | Protection::overrideInternals( |
250 | 202 | Protection::removeGlobals($GLOBALS, [ |
251 | | - "_ENV" => explode(",", $this->config->getString("app.globals_whitelist_env") ?? ""), |
252 | | - "_SERVER" => explode(",", $this->config->getString("app.globals_whitelist_server") ?? ""), |
253 | | - "_GET" => explode(",", $this->config->getString("app.globals_whitelist_get") ?? ""), |
254 | | - "_POST" => explode(",", $this->config->getString("app.globals_whitelist_post") ?? ""), |
255 | | - "_FILES" => explode(",", $this->config->getString("app.globals_whitelist_files") ?? ""), |
256 | | - "_COOKIES" => explode(",", $this->config->getString("app.globals_whitelist_cookies") ?? ""), |
257 | | - ] |
258 | | - )); |
| 203 | + "_ENV" => explode(",", $this->config->getString("app.globals_whitelist_env") ?? ""), |
| 204 | + "_SERVER" => explode(",", $this->config->getString("app.globals_whitelist_server") ?? ""), |
| 205 | + "_GET" => explode(",", $this->config->getString("app.globals_whitelist_get") ?? ""), |
| 206 | + "_POST" => explode(",", $this->config->getString("app.globals_whitelist_post") ?? ""), |
| 207 | + "_FILES" => explode(",", $this->config->getString("app.globals_whitelist_files") ?? ""), |
| 208 | + "_COOKIES" => explode(",", $this->config->getString("app.globals_whitelist_cookies") ?? ""), |
| 209 | + ] |
| 210 | + ) |
| 211 | + ); |
259 | 212 |
|
260 | 213 | $injector = new Injector($serviceContainer); |
261 | 214 |
|
|
0 commit comments