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

fix: get_cookie() may not use the cookie prefix #6082

Merged
merged 4 commits into from
Jun 16, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jun 6, 2022

Needs to rebase after merging #6080

Description
Fixes #6009
Supersede #6024

The current get_cookie() behavior is strange. See Behavior Changes below.

This PR changes it the following:

  • get_cookie($index) always use the cookie prefix in Config file
  • get_cookie($index, $xssClean, null) never uses the cookie prefix

Behavior Changes
When the cookie prefix is prefix_ and

$_COOKIES = [
    'prefix_test' => 'CI cookie',
    'test'        => 'Non CI cookie',
];

Before:

get_cookie('test');        // Non CI cookie
get_cookie('prefix_test'); // CI cookie

After:

get_cookie('test');              // CI cookie
get_cookie('prefix_test');       // null
get_cookie('test', false, null); // Non CI cookie

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them breaking change Pull requests that may break existing functionalities labels Jun 6, 2022
@kenjis kenjis force-pushed the fix-get_cookie-prefix branch from 4c470b1 to 28cc8bf Compare June 7, 2022 02:05
@kenjis kenjis marked this pull request as draft June 7, 2022 03:14
@kenjis
Copy link
Member Author

kenjis commented Jun 7, 2022

If the current setCookie() behavior is a bug, this PR's behavior should be changed.

Unfortunately, it is not a bug.

@kenjis kenjis marked this pull request as ready for review June 7, 2022 07:31
@MGatner
Copy link
Member

MGatner commented Jun 7, 2022

Agreed.

@kenjis kenjis force-pushed the fix-get_cookie-prefix branch from 28cc8bf to 4d3e4c2 Compare June 10, 2022 02:28
@kenjis
Copy link
Member Author

kenjis commented Jun 10, 2022

Rebased and added the documentation.

@kenjis kenjis merged commit 70281b5 into codeigniter4:develop Jun 16, 2022
@kenjis kenjis deleted the fix-get_cookie-prefix branch June 16, 2022 12:36
@kenjis kenjis mentioned this pull request Jun 16, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: get_cookie() cookie prefix behavior
3 participants