Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Security class sends cookies immediately, instead of coordinating with the Response class. #5406

Closed
lonnieezell opened this issue Nov 29, 2021 · 1 comment · Fixed by #5429
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@lonnieezell
Copy link
Member

PHP Version

7.4

CodeIgniter4 Version

4.1.5

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

macOS

Which server did you use?

cli-server (PHP built-in webserver)

Database

n/a

What happened?

Originally encountered during Feature testing. Code that passed previously is now giving errors that Cannot modify header information - headers already sent by. This appears to be happening while the CSRF token is being set while calling a page using the FeatureTestTrait.

Steps to Reproduce

Create a test using FeatureTestTrait. Use that to call a page that is protected with a CSRF hash. Run test.

Expected Output

Instead of sending the cookie immediately, it should add the cookie to the Response class, which then sends all cookies out at once to protect against the possibility of sending cookies early and giving the Output already started errors.

Anything else?

This appears to require letting the Response class (or ResponseTrait?) know how to handle raw cookies, also, in order to completely remove that functionality from the Security class.

Relevant trace:

ErrorException: Cannot modify header information - headers already sent by (output started at /Users/kilishan/WebSites/personal/Bonfire2/vendor/phpunit/phpunit/src/Util/Printer.php:104)

/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Cookie/CookieStore.php:248
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Cookie/CookieStore.php:172
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Security/Security.php:521
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Security/Security.php:507
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Security/Security.php:493
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Security/Security.php:467
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Security/Security.php:188
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Config/Services.php:552
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Config/BaseService.php:248
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Config/BaseService.php:189
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Config/Services.php:547
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Config/BaseService.php:248
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Common.php:243
/Users/kilishan/WebSites/personal/Bonfire2/vendor/codeigniter4/framework/system/Common.php:277
@lonnieezell lonnieezell added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 29, 2021
@kenjis
Copy link
Member

kenjis commented Dec 2, 2021

I sent a PR: #5429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants