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 Session::configure() to add cookie prefix to cookie name #5951

Closed
wants to merge 4 commits into from

Conversation

pjsde
Copy link
Contributor

@pjsde pjsde commented May 2, 2022

When the \CodeIgniter\Session\Session class creates the cookie, it is not adding the prefix that was defined in \Config\Cookie::$prefix to the name, so the name of the generated cookie is incomplete without having the prefix that was defined in the config.

To maintain consistency with the \CodeIgniter\Cookie\Cookie class, this change must be made so that the creation of the session cookie follows the same conditions as the creation of a normal 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 the tests needed Pull requests that need tests label May 2, 2022
@kenjis
Copy link
Member

kenjis commented May 2, 2022

Thank you for sending a PR.

We expect all contributions to conform to our style guide, be commented (inside the PHP source files), be documented (in the user guide), and unit tested (in the test folder).

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md#unit-testing

@kenjis
Copy link
Member

kenjis commented May 3, 2022

I don't know this is a bug or not.
At least, since CI3 the cookie name does not take care of Cookie prefix.

@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label May 3, 2022
@pjsde
Copy link
Contributor Author

pjsde commented May 3, 2022

I understand that it may not be a bug and that it comes from CI3, but the behavior of creating a cookie should be transversal to the entire framework

@kenjis kenjis removed the tests needed Pull requests that need tests label May 4, 2022
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a lot of experience with Session configuration so I'm not sure what is "normal" but this seems like a logical fix to me. Other than disrupting existing sessions, what about this would constitute a breaking change?

@kenjis
Copy link
Member

kenjis commented May 9, 2022

Session cookies are cookies, so this is logical.
But it seems CI distinguished Session (cookie) and Cookie.
Because the user guide says:

Additionally, the ‘cookiePrefix’ setting is completely ignored.
https://codeigniter4.github.io/CodeIgniter4/libraries/sessions.html#session-preferences

The only change of this PR is the session cookie name.
It disables existing sessions.

Wouldn't that be a breaking change, since all visitors would be forced to log out after the upgrade?

@MGatner
Copy link
Member

MGatner commented May 10, 2022

Wouldn't that be a breaking change

I don't know! I don't use long-term sessions, and in some projects I actually have new releases spin up on a new server, so this is always the case. But there might be scenarios where people need session cookies to persist?

Semver I think would say that this is a collateral effect that should be documented but since it does change the public API it does not require a major version release.

@kenjis
Copy link
Member

kenjis commented May 10, 2022

but since it does change the public API it does not require a major version release.

What do you mean? If we are changing the public API, SemVer requires a major version release, right?
I don't think CI4 should follow SemVer strictly, so I don't say we must wait for v5, though.

Anyway, it is the documented specification that the session cookie does not use cookiePrefix.
So if we will change it, we must document it clearly.

Personally, I don't see much value in this change. If users need the prefix, just add it in the session settings.
Conversely, if this change is implemented, users with a cookie prefix will have no way to maintain their session cookie name.

@MGatner
Copy link
Member

MGatner commented May 11, 2022

Understood. I will go with @kenjis on this one.

@kenjis
Copy link
Member

kenjis commented May 12, 2022

@pjsde This is not a bug, but is clearly documented. So we can't change easily.
The session cookie is a special one.

See the Note:

The ‘cookieHTTPOnly’ setting doesn’t have an effect on sessions. Instead the HttpOnly parameter is always enabled, for security reasons. Additionally, the Config\Cookie::$prefix setting is completely ignored.
https://codeigniter4.github.io/CodeIgniter4/libraries/sessions.html#session-preferences

@kenjis kenjis closed this May 12, 2022
@kenjis kenjis mentioned this pull request May 24, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants