|
16 | 16 | use CodeIgniter\Cookie\Exceptions\CookieException; |
17 | 17 | use CodeIgniter\HTTP\Exceptions\HTTPException; |
18 | 18 | use CodeIgniter\Pager\PagerInterface; |
| 19 | +use CodeIgniter\Security\Exceptions\SecurityException; |
19 | 20 | use Config\Services; |
20 | 21 | use DateTime; |
21 | 22 | use DateTimeZone; |
@@ -697,7 +698,51 @@ protected function sendCookies() |
697 | 698 | return; |
698 | 699 | } |
699 | 700 |
|
700 | | - $this->cookieStore->dispatch(); |
| 701 | + $this->dispatchCookies(); |
| 702 | + } |
| 703 | + |
| 704 | + private function dispatchCookies(): void |
| 705 | + { |
| 706 | + /** @var IncomingRequest $request */ |
| 707 | + $request = Services::request(); |
| 708 | + |
| 709 | + foreach ($this->cookieStore->display() as $cookie) { |
| 710 | + if ($cookie->isSecure() && ! $request->isSecure()) { |
| 711 | + throw SecurityException::forDisallowedAction(); |
| 712 | + } |
| 713 | + |
| 714 | + $name = $cookie->getPrefixedName(); |
| 715 | + $value = $cookie->getValue(); |
| 716 | + $options = $cookie->getOptions(); |
| 717 | + |
| 718 | + if ($cookie->isRaw()) { |
| 719 | + $this->doSetRawCookie($name, $value, $options); |
| 720 | + } else { |
| 721 | + $this->doSetCookie($name, $value, $options); |
| 722 | + } |
| 723 | + } |
| 724 | + |
| 725 | + $this->cookieStore->clear(); |
| 726 | + } |
| 727 | + |
| 728 | + /** |
| 729 | + * Extracted call to `setrawcookie()` in order to run unit tests on it. |
| 730 | + * |
| 731 | + * @codeCoverageIgnore |
| 732 | + */ |
| 733 | + private function doSetRawCookie(string $name, string $value, array $options): void |
| 734 | + { |
| 735 | + setrawcookie($name, $value, $options); |
| 736 | + } |
| 737 | + |
| 738 | + /** |
| 739 | + * Extracted call to `setcookie()` in order to run unit tests on it. |
| 740 | + * |
| 741 | + * @codeCoverageIgnore |
| 742 | + */ |
| 743 | + private function doSetCookie(string $name, string $value, array $options): void |
| 744 | + { |
| 745 | + setcookie($name, $value, $options); |
701 | 746 | } |
702 | 747 |
|
703 | 748 | /** |
|
0 commit comments