-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: set_cookie not using default value of $secure from config #6540
Comments
You must set variable secure to true, by default function set_cookie set_cookie([
'name' => 'pmw',
'value' => 2,
'secure' => true,
'samesite' => 'None',
]); If you want create cookie with default config (see https://codeigniter.com/user_guide/libraries/cookies.html#creating-cookies) or you can using $cookieConfig = config('cookie');
set_cookie([
'name' => 'pmw',
'value' => 2,
'expire' => $cookieConfig->expires,
'domain' => $cookieConfig->domain,
'path' => $cookieConfig->path,
'prefix' => $cookieConfig->prefix,
'secure' => $cookieConfig->secure,
'httponly' => $cookieConfig->httponly,
'samesite' => $cookieConfig->samesite,
]); |
set_cookie function uses new Cookie in its implementation which makes it get the default value of "domain", "samesite" and other non bool config values, but doesn't for "secure". Isn't that inconsistency? Won't it better for all of them to fallback to values in config? |
Reading the user guide, I think the values in the Config file should be used for unspecified items. |
Ref, CodeIgniter4/system/Helpers/cookie_helper.php Lines 39 to 49 in 354b43a
|
This seems the first commit: https://github.com/codeigniter4/CodeIgniter4/pull/241/files#diff-1ee301297e39aa12b421d2ad72d266269f4fc8fe56c01c366fbcdf16056a942dR82 |
I sent a PR: #6544 |
PHP Version
7.4
CodeIgniter4 Version
4.2.6
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
macOS
Which server did you use?
apache
Database
No response
What happened?
set_cookie function in Helpers/cookie_helper.php is not using the default value $secure i specified in app/Config/Cookie.php.
This used to work in CI3 because I think the default value of $secure param of set_cookie function used to be null which later on fallback to default.****
Steps to Reproduce
Expected Output
No exception
Anything else?
No response
The text was updated successfully, but these errors were encountered: