Rev 849 | Rev 1050 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 849 | Rev 866 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
Line 350... | Line 350... | ||
350 | return bin2hex(self::getRandomBytes(64)); |
350 | return bin2hex(self::getRandomBytes(64)); |
351 | } |
351 | } |
352 | 352 | ||
353 | public function checkCSRF() { |
353 | public function checkCSRF() { |
354 | if (!$this->enable_csrf) return; |
354 | if (!$this->enable_csrf) return; |
- | 355 | ||
- | 356 | $request_token = isset($_REQUEST['csrf_token']) ? $_REQUEST['csrf_token'] : ''; |
|
355 | if (!isset($_REQUEST['csrf_token']) || !isset($_COOKIE['csrf_token']) || ($_REQUEST['csrf_token'] !== $_COOKIE['csrf_token'])) { |
357 | $cookie_token = isset($_COOKIE['csrf_token']) ? $_COOKIE['csrf_token'] : ''; |
- | 358 | ||
- | 359 | if (empty($request_token) || empty($cookie_token) || ($request_token !== $cookie_token)) { |
|
- | 360 | if (OIDplus::baseConfig()->getValue('DEBUG')) { |
|
356 | throw new OIDplusException(_L('Wrong CSRF Token')); |
361 | throw new OIDplusException(_L('Missing or wrong CSRF Token: Request %1 vs Cookie %2', |
- | 362 | isset($_REQUEST['csrf_token']) ? '"'.$_REQUEST['csrf_token'].'"' : 'NULL', |
|
- | 363 | isset($_COOKIE['csrf_token']) ? $_COOKIE['csrf_token'] : 'NULL' |
|
- | 364 | )); |
|
- | 365 | } else { |
|
- | 366 | throw new OIDplusException(_L('Missing or wrong "CSRF Token". To fix the issue, try clearing your browser cache and reload the page. If you visited the page via HTTPS before, try HTTPS in case you are currently connected via HTTP.')); |
|
- | 367 | } |
|
357 | } |
368 | } |
358 | } |
369 | } |
359 | 370 | ||
360 | // Generate RA passwords |
371 | // Generate RA passwords |
361 | 372 |