# header() removes all header of the same name.

- Thread: https://externals.io/message/96412
- Original archive: https://news-web.php.net/php.internals/96412
- Started by Yasuo Ohgaki on 2016-10-18T07:31:41+00:00
- Messages: 41
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/96412.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #96412 — Yasuo Ohgaki — 2016-10-18T07:31:41+00:00

URL: https://externals.io/message/96412#96412

Hi all,

I understand why `header()` is made to remove all headers of the same
name. This is needed in some cases, but it does not work well for some
cases.

We need to decide what to do with
https://bugs.php.net/bug.php?id=72997

There is 2 issues.
  - `header()` removes all headers of the same name including 'Set-Cookie'
  - `header()` ignores replace flag. (This one is easy to fix)

Since `header()` enables 'replace flag' by default, it removes all
'Set-Cookie' headers sent previously by default. It can easily disturb
security related cookies to work. i.e. Session ID cookie, Auto Login
cookie. This bug would be very hard to find for normal users, too.

Restoring older behavior (Removing only one header) cannot be a
resolution because it can still disturb security related cookies.

Possible resolutions:

 - Prohibit 'Set-Cookie' for `header()` and force users to use `setcookie()`
 - Mitigate by disabling replace flag by default. (This is not a good idea, IMO)

Both resolution requires BC, but this is better to be fixed ASAP.

Non-BC resolution could be:
  - "Ask users to use `setcookie()` always for 'Set-Cookie'".

I would like to prohibit 'Set-Cookie' by `header()` because it may
remove session ID cookie as well as auto login cookie, etc. If we
leave released version as it is now, I would like to prohibit
'Set-Cookie' by `header()` in PHP 7.1.

Problem with this may be that user cannot modify 'Set-Cookie' header
line as user want.

$ php -r 'setcookie("REMEMBERME=value; expires=Sat, 03-Sep-2020
05:38:43 GMT; path=/; domain=aaa");'
PHP Warning:  Cookie names cannot contain any of the following '=,;
\t\r\n\013\014' in Command line code on line 1


Comments?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96416 — Stephen Reay — 2016-10-18T09:36:27+00:00

URL: https://externals.io/message/96412#96416 · In reply to: #96412

(Apologies for the dupe, re-sending for the list.)

If the replace flag was fixed, isn’t this then just a case of making sure userland sets replace to false if they want existing set-cookie headers retained?

Removing the ability to write a custom Set-Cookie header introduces a bigger problem than the current one, IMO.

> 
> 
> Hi all,
> 
> I understand why `header()` is made to remove all headers of the same
> name. This is needed in some cases, but it does not work well for some
> cases.
> 
> We need to decide what to do with
> https://bugs.php.net/bug.php?id=72997
> 
> There is 2 issues.
> - `header()` removes all headers of the same name including 'Set-Cookie'
> - `header()` ignores replace flag. (This one is easy to fix)
> 
> Since `header()` enables 'replace flag' by default, it removes all
> 'Set-Cookie' headers sent previously by default. It can easily disturb
> security related cookies to work. i.e. Session ID cookie, Auto Login
> cookie. This bug would be very hard to find for normal users, too.
> 
> Restoring older behavior (Removing only one header) cannot be a
> resolution because it can still disturb security related cookies.
> 
> Possible resolutions:
> 
> - Prohibit 'Set-Cookie' for `header()` and force users to use `setcookie()`
> - Mitigate by disabling replace flag by default. (This is not a good idea, IMO)
> 
> Both resolution requires BC, but this is better to be fixed ASAP.
> 
> Non-BC resolution could be:
> - "Ask users to use `setcookie()` always for 'Set-Cookie'".
> 
> I would like to prohibit 'Set-Cookie' by `header()` because it may
> remove session ID cookie as well as auto login cookie, etc. If we
> leave released version as it is now, I would like to prohibit
> 'Set-Cookie' by `header()` in PHP 7.1.
> 
> Problem with this may be that user cannot modify 'Set-Cookie' header
> line as user want.
> 
> $ php -r 'setcookie("REMEMBERME=value; expires=Sat, 03-Sep-2020
> 05:38:43 GMT; path=/; domain=aaa");'
> PHP Warning:  Cookie names cannot contain any of the following '=,;
> \t\r\n\013\014' in Command line code on line 1
> 
> 
> Comments?
> 
> Regards,
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

---

## #96423 — Yasuo Ohgaki — 2016-10-18T11:08:30+00:00

URL: https://externals.io/message/96412#96423

Hi Stephen,


> If the replace flag was fixed, isn’t this then just a case of making sure userland sets replace to false if they want existing set-cookie headers retained?

Yes and no.

If users use the replace flag correctly, then it will work. However, I
don't expect users set replace flag correctly. If replace flag's
default was opposite, it would work better.

> Removing the ability to write a custom Set-Cookie header introduces a bigger problem than the current one, IMO.

OK. Let's just fix the replace flag and document removing 'Set-Cookie'
header by `header()` may result in unwanted results.

Everyone is ok with this?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96425 — Stephen Reay — 2016-10-18T11:32:00+00:00

URL: https://externals.io/message/96412#96425 · In reply to: #96423

Hi Yasuo,

I agree there are probably a lot using the default, but I think it’s reasonable to expect anyone using a header(‘Set-Cookie:..’); call rather than `setcookie()` to be aware of the 2nd argument for `header()`, so this solution sounds good to me.

Cheers

Stephen 

> 
> 
> Hi Stephen,
> 
> 
> > […]
> 
> Yes and no.
> 
> If users use the replace flag correctly, then it will work. However, I
> don't expect users set replace flag correctly. If replace flag's
> default was opposite, it would work better.
> 
> > […]
> 
> OK. Let's just fix the replace flag and document removing 'Set-Cookie'
> header by `header()` may result in unwanted results.
> 
> Everyone is ok with this?
> 
> Regards,
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

---

## #96458 — Yasuo Ohgaki — 2016-10-19T01:00:29+00:00

URL: https://externals.io/message/96412#96458 · In reply to: #96412

Hi all,


> I understand why `header()` is made to remove all headers of the same
> name. This is needed in some cases, but it does not work well for some
> cases.
>
> We need to decide what to do with
> https://bugs.php.net/bug.php?id=72997
>
> There is 2 issues.
>   - `header()` removes all headers of the same name including 'Set-Cookie'
>   - `header()` ignores replace flag. (This one is easy to fix)
>
> Since `header()` enables 'replace flag' by default, it removes all
> 'Set-Cookie' headers sent previously by default. It can easily disturb
> security related cookies to work. i.e. Session ID cookie, Auto Login
> cookie. This bug would be very hard to find for normal users, too.
>
> Restoring older behavior (Removing only one header) cannot be a
> resolution because it can still disturb security related cookies.
>
> Possible resolutions:
>
>  - Prohibit 'Set-Cookie' for `header()` and force users to use `setcookie()`
>  - Mitigate by disabling replace flag by default. (This is not a good idea, IMO)
>
> Both resolution requires BC, but this is better to be fixed ASAP.
>
> Non-BC resolution could be:
>   - "Ask users to use `setcookie()` always for 'Set-Cookie'".
>
> I would like to prohibit 'Set-Cookie' by `header()` because it may
> remove session ID cookie as well as auto login cookie, etc. If we
> leave released version as it is now, I would like to prohibit
> 'Set-Cookie' by `header()` in PHP 7.1.
>
> Problem with this may be that user cannot modify 'Set-Cookie' header
> line as user want.
>
> $ php -r 'setcookie("REMEMBERME=value; expires=Sat, 03-Sep-2020
> 05:38:43 GMT; path=/; domain=aaa");'
> PHP Warning:  Cookie names cannot contain any of the following '=,;
> \t\r\n\013\014' in Command line code on line 1
>
>
> Comments?

An idea for session ID protection.

Following code results in lost session always.

<?php
 `session_start()`;
 `session_regenerate_id()`;
header('Set-Cookie: something');
?>

 `header()` function removes all header of the same name, e.g.
Set-Cookie, Expires, etc, by sapi_remove_header(). This could be very
hard to find the cause.


This risk can be removed w/o much BC. Only BC is when user is
intentionally trying to delete session ID cookie manually. This would
be very rare. We can add code that excludes session ID cookie in
sapi_remove_header().
http://lxr.php.net/xref/PHP-MASTER/main/SAPI.c#593

To do that, we can search string like following
Set-Cookie: PHPSESSID=xxxxxxx

The only issue is we need session global, i.e. PS(session_name), at
least. It's not nice to have dependency from SAPI.c to session, but it
protects session ID from removed by users by mistake.

Any comments?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96460 — Stephen Reay — 2016-10-19T03:18:20+00:00

URL: https://externals.io/message/96412#96460 · In reply to: #96458

Hi Yasuo,

I still have an issue with that. I believe the correct behaviour here is (assuming the `replace` argument to `header()` is honoured) what you’re seeing. Yes, it might be *unexpected* for new users, but its also *expected* by millions of current users/projects.

I would suggest perhaps a warning on the `header()` docs page, and perhaps an example to avoid the issue on the Session handling page.

Leaving it as-is, with improved docs means all functionality is *possible* with the right arguments.

Changing to your proposal means advanced use-cases are *impossible* with any arguments.


I realise you’re trying to remove WTF cases, but I don’t think removing advanced capabilities is the way to do that.


Cheers

Stephen


> 
> 
> Hi all,
> 
> 
> > […]
> 
> An idea for session ID protection.
> 
> Following code results in lost session always.
> 
> <?php
> `session_start()`;
> `session_regenerate_id()`;
> header('Set-Cookie: something');
> ?>
> 
> `header()` function removes all header of the same name, e.g.
> Set-Cookie, Expires, etc, by sapi_remove_header(). This could be very
> hard to find the cause.
> 
> 
> This risk can be removed w/o much BC. Only BC is when user is
> intentionally trying to delete session ID cookie manually. This would
> be very rare. We can add code that excludes session ID cookie in
> sapi_remove_header().
> http://lxr.php.net/xref/PHP-MASTER/main/SAPI.c#593
> 
> To do that, we can search string like following
> Set-Cookie: PHPSESSID=xxxxxxx
> 
> The only issue is we need session global, i.e. PS(session_name), at
> least. It's not nice to have dependency from SAPI.c to session, but it
> protects session ID from removed by users by mistake.
> 
> Any comments?
> 
> Regards,
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

---

## #96461 — Yasuo Ohgaki — 2016-10-19T04:34:09+00:00

URL: https://externals.io/message/96412#96461 · In reply to: #96460

Hi Stephen,


> I still have an issue with that. I believe the correct behaviour here is (assuming the `replace` argument to `header()` is honoured) what you’re seeing. Yes, it might be *unexpected* for new users, but its also *expected* by millions of current users/projects.
>
> I would suggest perhaps a warning on the `header()` docs page, and perhaps an example to avoid the issue on the Session handling page.
>
> Leaving it as-is, with improved docs means all functionality is *possible* with the right arguments.
>
> Changing to your proposal means advanced use-cases are *impossible* with any arguments.
>
>
> I realise you’re trying to remove WTF cases, but I don’t think removing advanced capabilities is the way to do that.

Yes. Even framework developer(?) seems to have current behavior.

In general, users shouldn't touch session ID. In case of user really
want to modify session ID cookie, following could be done.

<?php
 `ob_start()`;
 `session_start()`;
header_remove('Set-Cookie');
header('Set-Cookie: PHPSESSID=xxxx something');
?>

Make `header_remove()` able to delete 'Set-Cookie' header. (Current behavior)
Make `header()` able to send 'Set-Cookie' header. (Current behavior, but
not remove session ID cookie)

This allows users to send arbitrary session ID cookie when it is
needed really needed, while avoiding accidental session ID cookie
removal.

What do you think?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96462 — Yasuo Ohgaki — 2016-10-19T04:41:09+00:00

URL: https://externals.io/message/96412#96462 · In reply to: #96461

Hi Stephen,


> > […]
>
> Yes. Even framework developer(?) seems to have current behavior.

To be honest, I didn't have idea what's wrong with user provided code
when I have a look at the bug report. I had to experiment a little to
understand what is going on.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96465 — Yasuo Ohgaki — 2016-10-19T06:03:01+00:00

URL: https://externals.io/message/96412#96465 · In reply to: #96461

Hi all,


>
> 
> > […]
>
> Yes. Even framework developer(?) seems to have current behavior.
>
> In general, users shouldn't touch session ID. In case of user really
> want to modify session ID cookie, following could be done.
>
> <?php
> `ob_start()`;
> `session_start()`;
> header_remove('Set-Cookie');
> header('Set-Cookie: PHPSESSID=xxxx something');
> ?>
>
> Make `header_remove()` able to delete 'Set-Cookie' header. (Current behavior)
> Make `header()` able to send 'Set-Cookie' header. (Current behavior, but
> not remove session ID cookie)
>
> This allows users to send arbitrary session ID cookie when it is
> needed really needed, while avoiding accidental session ID cookie
> removal.
>
> What do you think?

Another idea for session ID cookie and Set-Cookie header protection.

Since we have `setcookie()` function, how about to have cookie
dedicated functions for cookie header manipulation.

I'm about to create new feature request as follows:
---------------------
Protect session ID and other cookies from `header()`, `header_remove()`
---------------------
 `header()` removes any previously defined headers.
header('Set-Cookie: something') / `header_remove()` deletes session ID
and other Set-Cookie headers. Cookies should be protected from
 `header()`/header_remove().

Instead, create new cookie functions

cookie_set() - Set cookie header (setcookie() alias)
cookie_set_raw() - Set cookie header (setrawcookie alias)
cookie_custom() - Set cookie with custom style.
                           (The same as header(sprintf('Set-Cookie:
%s', something));
cookie_remove() - Remove all cookie header. $name parameter is cookie
name to be deleted.

Protect Set-Cookie headers from `header()` and `header_remove()`
----------------------

This implementation is cleaner because core to session
dependency is not required. It is also good to have naming standard
confirming cookie function names. i.e. Cookie functions should be
named cookie_*() according to CODING_STANDARDS.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96480 — Andrea Faulds — 2016-10-19T12:55:59+00:00

URL: https://externals.io/message/96412#96480 · In reply to: #96412

Hi Yasuo,

I don't think we should do anything about this beyond maybe warning the 
user in the manual. `header()` is a generic function for setting headers, 
it would be surprising if it had different behaviour for cookies or 
session cookies. It is possible that use of this function in this way 
may be deliberate.

Thanks.
-- 
Andrea Faulds
https://ajf.me/

---

## #96500 — Stanislav Malyshev — 2016-10-20T04:39:07+00:00

URL: https://externals.io/message/96412#96500 · In reply to: #96412

Hi!

> There is 2 issues.
>   - `header()` removes all headers of the same name including 'Set-Cookie'
>   - `header()` ignores replace flag. (This one is easy to fix)

We have the flag, so if it doesn't work it should be fixed. Also, one
should use `setcookie()` for cookies, usually.

> Possible resolutions:
> 
>  - Prohibit 'Set-Cookie' for `header()` and force users to use `setcookie()`
>  - Mitigate by disabling replace flag by default. (This is not a good idea, IMO)

I don't think we should do either.

> I would like to prohibit 'Set-Cookie' by `header()` because it may
> remove session ID cookie as well as auto login cookie, etc. If we
> leave released version as it is now, I would like to prohibit
> 'Set-Cookie' by `header()` in PHP 7.1.

I don't think it's a good idea. If somebody is using `header()`, it should
work like `header()` works. If you don't like how it works, use setcookie.

> Problem with this may be that user cannot modify 'Set-Cookie' header
> line as user want.
> 
> $ php -r 'setcookie("REMEMBERME=value; expires=Sat, 03-Sep-2020
> 05:38:43 GMT; path=/; domain=aaa");'
> PHP Warning:  Cookie names cannot contain any of the following '=,;
> \t\r\n\013\014' in Command line code on line 1

You are using `setcookie()` wrong here. See: http://php.net/setcookie

-- 
Stas Malyshev
smalyshev@gmail.com

---

## #96501 — Yasuo Ohgaki — 2016-10-20T06:58:12+00:00

URL: https://externals.io/message/96412#96501 · In reply to: #96500

Hi Stas,

I posted an an idea for preventing accidental cookie deletion.
'Set-Cookie' is a HTTP header, but provide dedicated functions for it. I pasted
it with a little modification.
What do you think?

Bottom line is I would like to prevent lost session ID  by `header()`
in the future.

Implement cookie_*() functions in 7.x, then prohibit 'Set-Cookie' for
 `header()` in 8.x


> > […]
>
> We have the flag, so if it doesn't work it should be fixed. Also, one
> should use `setcookie()` for cookies, usually.


Another idea for session ID cookie and Set-Cookie header protection.

Since we have `setcookie()` function, how about to have cookie
dedicated functions for cookie header manipulation.

I'm about to create new feature request as follows:
---------------------
Protect session ID and other cookies from `header()`, `header_remove()`
---------------------
 `header()` removes any previously defined headers.
header('Set-Cookie: something') / `header_remove()` deletes session ID
and other Set-Cookie headers. Cookies should be protected from
 `header()`/header_remove().

Instead, create new cookie functions

cookie_set() - Set cookie header (setcookie() alias)
cookie_set_raw() - Set cookie header (setrawcookie alias)
cookie_custom() - Set cookie with custom style.
                           (The same as header(sprintf('Set-Cookie:
%s', $something));
cookie_list() - Mostly the same as `headers_list()`
cookie_remove([string $name]) - Mostly the same as `header_remove()`
Remove cookie header. $name parameter is cookie name to be deleted.

Protect Set-Cookie headers from `header()` and `header_remove()`
----------------------

This implementation is cleaner because core to session
dependency is not required. It is also good to have naming standard
confirming cookie function names. i.e. Cookie functions should be
named cookie_*() according to CODING_STANDARDS.

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96503 — Stephen Reay — 2016-10-20T07:49:24+00:00

URL: https://externals.io/message/96412#96503 · In reply to: #96501

Hi All,

Just to make my earlier point of view crystal clear: As a purely userland party and someone maintaining a PHP framework, I don’t think it’s acceptable to limit which headers `header()`/header_remove() can operate on, particularly when the problem you’re trying to ‘solve’ is simply incorrect use of the functions available. It *is* possible to achieve any outcome desired with *correct* use of the header, session and cookie functions (and assuming the $replace argument to `header()` works correctly).

I still believe the way to solve this issue is with better information about usage, not by removing existing functionality.

So, please do *not* consider this to be an acceptable solution.

Cheers

Stephen


> 
> 
> Hi Stas,
> 
> I posted an an idea for preventing accidental cookie deletion.
> 'Set-Cookie' is a HTTP header, but provide dedicated functions for it. I pasted
> it with a little modification.
> What do you think?
> 
> Bottom line is I would like to prevent lost session ID  by `header()`
> in the future.
> 
> Implement cookie_*() functions in 7.x, then prohibit 'Set-Cookie' for
> `header()` in 8.x
> 
> 
> > […]
> 
> 
> Another idea for session ID cookie and Set-Cookie header protection.
> 
> Since we have `setcookie()` function, how about to have cookie
> dedicated functions for cookie header manipulation.
> 
> I'm about to create new feature request as follows:
> ---------------------
> Protect session ID and other cookies from `header()`, `header_remove()`
> ---------------------
> `header()` removes any previously defined headers.
> header('Set-Cookie: something') / `header_remove()` deletes session ID
> and other Set-Cookie headers. Cookies should be protected from
> `header()`/header_remove().
> 
> Instead, create new cookie functions
> 
> cookie_set() - Set cookie header (setcookie() alias)
> cookie_set_raw() - Set cookie header (setrawcookie alias)
> cookie_custom() - Set cookie with custom style.
>                          (The same as header(sprintf('Set-Cookie:
> %s', $something));
> cookie_list() - Mostly the same as `headers_list()`
> cookie_remove([string $name]) - Mostly the same as `header_remove()`
> Remove cookie header. $name parameter is cookie name to be deleted.
> 
> Protect Set-Cookie headers from `header()` and `header_remove()`
> ----------------------
> 
> This implementation is cleaner because core to session
> dependency is not required. It is also good to have naming standard
> confirming cookie function names. i.e. Cookie functions should be
> named cookie_*() according to CODING_STANDARDS.
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

---

## #96504 — Yasuo Ohgaki — 2016-10-20T08:10:50+00:00

URL: https://externals.io/message/96412#96504

Hi Stephen,


>
> Just to make my earlier point of view crystal clear: As a purely userland party and someone maintaining a PHP framework, I don’t think it’s acceptable to limit which headers `header()`/header_remove() can operate on, particularly when the problem you’re trying to ‘solve’ is simply incorrect use of the functions available. It *is* possible to achieve any outcome desired with *correct* use of the header, session and cookie functions (and assuming the $replace argument to `header()` works correctly).
>
> I still believe the way to solve this issue is with better information about usage, not by removing existing functionality.
>
> So, please do *not* consider this to be an acceptable solution.

The idea is to separate HTTP header handling functions.

 - header*() for any HTTP headers except 'Set-Cookie'
 - cookie*() for only 'Set-Cookie' header

Developer does not lose anything.

As you mention, custom 'Set-Cookie' header is for advanced users.
Those people wouldn't have problems with new API.

With this new API, we'll have standard confirming function names for
cookie functions as a bonus, too. (I'm enthusiastic to clean up and
have consistent function names as you might know.)

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96506 — Stephen Reay — 2016-10-20T08:23:30+00:00

URL: https://externals.io/message/96412#96506 · In reply to: #96504

Hi Yasuo,


> 
> 
> Hi Stephen,
> 
> 
> > […]
> 
> The idea is to separate HTTP header handling functions.
> 
> - header*() for any HTTP headers except 'Set-Cookie'
> - cookie*() for only 'Set-Cookie' header
> 
> Developer does not lose anything.

The Developer *loses* what s/he has *now* - a fully functional `header()` function.

> 
> As you mention, custom 'Set-Cookie' header is for advanced users.
> Those people wouldn't have problems with new API.

Those people shouldn’t have problems using `header()` properly.

> 
> With this new API, we'll have standard confirming function names for
> cookie functions as a bonus, too. (I'm enthusiastic to clean up and
> have consistent function names as you might know.)
> 

I don’t have a problem with improved function names. I have a problem with removing functionality that is basically only ever going to be used by advanced developers, because it has *slightly* non obvious behaviour that could be fixed by a simple documentation note.

Please understand: *no* “solution" where `header()` loses the ability to write any arbitrary header will be acceptable in my opinion.

> Regards,
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
> 

Cheers

Stephen

---

## #96507 — Yasuo Ohgaki — 2016-10-20T08:28:51+00:00

URL: https://externals.io/message/96412#96507 · In reply to: #96506

Hi Stephen,


> Please understand: *no* “solution" where `header()` loses the ability to write any arbitrary header will be acceptable in my opinion.

Thank you for feedback.
I'll include vote option for prohibiting 'Set-Cookie' for header*()

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96508 — Niklas Keller — 2016-10-20T09:01:52+00:00

URL: https://externals.io/message/96412#96508 · In reply to: #96507

2016-10-20 10:28 GMT+02:00 Yasuo Ohgaki <yohgaki@ohgaki.net>:

> Hi Stephen,
>
> On Thu, Oct 20, 2016 at 5:23 PM, Stephen Reay <php-lists@koalephant.com>
> wrote:
> > […]
> write any arbitrary header will be acceptable in my opinion.
>
> Thank you for feedback.
> I'll include vote option for prohibiting 'Set-Cookie' for header*()
>
> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
>
> --
> 
> 
>
>
Hi Yasuo,

same here, it's not acceptable to limit header and restrict `set_cookie`.
Just think about all those frameworks that would have to specialcase
setting headers now and have to use the cookie API then.

If you want to protect the session cookie header, why not simply set it
right before the first output? That'd make it also non-overrideable, but
leaves `header()` intact. But I guess it's harder to implement.

---

## #96511 — Yasuo Ohgaki — 2016-10-20T09:57:36+00:00

URL: https://externals.io/message/96412#96511 · In reply to: #96508

Hi Niklas,


>
> same here, it's not acceptable to limit header and restrict `set_cookie`.
> Just think about all those frameworks that would have to specialcase setting
> headers now and have to use the cookie API then.
>
> If you want to protect the session cookie header, why not simply set it
> right before the first output? That'd make it also non-overrideable, but
> leaves `header()` intact. But I guess it's harder to implement.

Although, I prefer to have completely separate API, we have to
implement vote result. So vote no for "Disabling 'Set-Cookie' for
header*()" vote option.

Regarding about delaying session cookie header, it is possible to use
output buffer to delay output so that session module can send HTTP
header at request shutdown. However, it will break almost all session
enabled applications that require immediate output. Therefore, it's
easy to implement, but not possible for this reason.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96513 — Niklas Keller — 2016-10-20T10:39:02+00:00

URL: https://externals.io/message/96412#96513 · In reply to: #96511

2016-10-20 11:57 GMT+02:00 Yasuo Ohgaki <yohgaki@ohgaki.net>:

> Hi Niklas,
>
> 
> > […]
> setting
> > […]
>
> Although, I prefer to have completely separate API, we have to
> implement vote result. So vote no for "Disabling 'Set-Cookie' for
> header*()" vote option.
>

I don't have a vote. But this breaks BC. It might remove surprisings when
using sessions, but having `header()` not being able to set `set-cookie`
headers adds new surprisings.


> Regarding about delaying session cookie header, it is possible to use
> output buffer to delay output so that session module can send HTTP
> header at request shutdown. However, it will break almost all session
> enabled applications that require immediate output. Therefore, it's
> easy to implement, but not possible for this reason.


I meant squeeze in right before output or on first `flush()` call. There must
be a thing that sets a "already output" flag that prevents further headers.
We could use that mechanism to buffer all headers and just send them out
there and have a hook for the session module.

Regards, Niklas


> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

---

## #96515 — Stephen Reay — 2016-10-20T11:24:13+00:00

URL: https://externals.io/message/96412#96515 · In reply to: #96513

Hi Niklas,

There is even a userland hook for the specific functionality you mention: `header_register_callback()`. 

But I would argue that no fix is necessary. If you as a developer call `session_start()`, and then later call header(‘Set-Cookie:…’) with replace left as true, I think it’s safe to assume you’re either doing it deliberately, or that you’ll go read the documentation on sessions and `header()` to discover the problem. (Or possibly file a bug which will be marked as not-a-bug and refer you to the documentation).

The *only* solution that retains full control for the developer, is no change. Any “magic” about “untouchable” cookie headers (e.g. forcing the session cookie header after userland cookie headers) takes away options for the developer.

If *anything* the BC break being discussed should be to invert the default value for the $replace argument to `header()`.

Cheers

Stephen 

> 
> 
> 2016-10-20 11:57 GMT+02:00 Yasuo Ohgaki <yohgaki@ohgaki.net <mailto:yohgaki@ohgaki.net>>:
> Hi Niklas,
> 
> 
> > […]
> 
> Although, I prefer to have completely separate API, we have to
> implement vote result. So vote no for "Disabling 'Set-Cookie' for
> header*()" vote option.
> 
> I don't have a vote. But this breaks BC. It might remove surprisings when using sessions, but having `header()` not being able to set `set-cookie` headers adds new surprisings.
>  
> Regarding about delaying session cookie header, it is possible to use
> output buffer to delay output so that session module can send HTTP
> header at request shutdown. However, it will break almost all session
> enabled applications that require immediate output. Therefore, it's
> easy to implement, but not possible for this reason.
> 
> I meant squeeze in right before output or on first `flush()` call. There must be a thing that sets a "already output" flag that prevents further headers. We could use that mechanism to buffer all headers and just send them out there and have a hook for the session module.
> 
> Regards, Niklas
>  
> Regards,
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net <mailto:yohgaki@ohgaki.net>
> 
> --
> 
>  <http://www.php.net/unsub.php

---

## #96516 — Yasuo Ohgaki — 2016-10-20T11:29:33+00:00

URL: https://externals.io/message/96412#96516 · In reply to: #96513

Hi Niklas,


> 016-10-20 11:57 GMT+02:00 Yasuo Ohgaki <yohgaki@ohgaki.net>:
> > […]
>
>
> I don't have a vote. But this breaks BC. It might remove surprisings when
> using sessions, but having `header()` not being able to set `set-cookie`
> headers adds new surprisings.

That's why we have minor releases and document.

Besides, I noted "add API 7.x, disallow header('Set-Cookie') by 8.0".
There are years to prepare for the change even if we decide to do so.

>
> > […]
>
>
> I meant squeeze in right before output or on first `flush()` call. There must
> be a thing that sets a "already output" flag that prevents further headers.
> We could use that mechanism to buffer all headers and just send them out
> there and have a hook for the session module.

The reason why I think of this new API proposal is to remove
core(main/SAPI.c) dependency to session. Your idea requires the
dependency (main/SAPI.c) like my the other proposal. Technically, it's
possible and it can be simpler by detecting and preventing session ID
deletion/modification.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96518 — Yasuo Ohgaki — 2016-10-20T11:41:36+00:00

URL: https://externals.io/message/96412#96518 · In reply to: #96515

Hi Stephen,


> The *only* solution that retains full control for the developer, is no
> change. Any “magic” about “untouchable” cookie headers (e.g. forcing the
> session cookie header after userland cookie headers) takes away options for
> the developer.

My cookie*() functions proposal allows developers to remove header by
cookie_remove() and can send any cookie header by cookie_custom().
Therefore, developers have full control if they have to.

The only pain is that users may have to use cookie*() functions if we
disallow header('Set-Cookie') which will be a vote option. If there is
fully functional cookie*() functions, it will mitigate wrong
header('Set-Cookie') usage regardless of the vote result, hopefully.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #96519 — Stephen Reay — 2016-10-20T12:15:14+00:00

URL: https://externals.io/message/96412#96519 · In reply to: #96518

Hi Yasuo,

As with Niklas, I have no vote, so my *only* option to prevent what I consider to be a bad decision, is to post to this thread and hope that enough of those who *do* have voting rights, reject the proposal.

I understand what you’re proposing. But honestly I don’t even agree with the premise that there is a *problem* that needs to be fixed.

Did you know that if you manually set the Content-Length header to less than the actual body length, many browsers (Safari, Chrome, and FF definitely) will stop reading/processing the response at the length you specify?
So should we also prevent setting Content-Length via `header()` ?

Honestly I don’t understand how this is still a discussion. The developer failed to set the $replace argument to false. At most I would expect this to result in a documentation note warning about the use of header(‘Set-Cookie…’).


I appreciate you trying to make improvements, and I’d *definitely* be in favour of the function naming cleanup you mentioned earlier, but all of this “protected” headers and extra function calls, because someone forgot to type “, false” seems ridiculous to me honestly.


Cheers

Stephen



> 
> 
> Hi Stephen,
> 
> 
> > […]
> 
> My cookie*() functions proposal allows developers to remove header by
> cookie_remove() and can send any cookie header by cookie_custom().
> Therefore, developers have full control if they have to.
> 
> The only pain is that users may have to use cookie*() functions if we
> disallow header('Set-Cookie') which will be a vote option. If there is
> fully functional cookie*() functions, it will mitigate wrong
> header('Set-Cookie') usage regardless of the vote result, hopefully.
> 
> Regards,
> 
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

---

## #96521 — Niklas Keller — 2016-10-20T12:21:01+00:00

URL: https://externals.io/message/96412#96521 · In reply to: #96518

2016-10-20 13:41 GMT+02:00 Yasuo Ohgaki <yohgaki@ohgaki.net>:

> Hi Stephen,
>
> On Thu, Oct 20, 2016 at 8:24 PM, Stephen Reay <php-lists@koalephant.com>
> wrote:
> > […]
> for
> > […]
>
> My cookie*() functions proposal allows developers to remove header by
> cookie_remove() and can send any cookie header by cookie_custom().
> Therefore, developers have full control if they have to.
>
> The only pain is that users may have to use cookie*() functions if we
> disallow header('Set-Cookie') which will be a vote option. If there is
> fully functional cookie*() functions, it will mitigate wrong
> header('Set-Cookie') usage regardless of the vote result, hopefully.
>

What about extensions to the `set-cookie` header? Take `SameSite` as a
recent example. The `setcookie` API doesn't cover that. Besides that, the
current `setcookie` API is awful, people just added more and more
parameters.

Before we even discuss disallowing `header("set-cookie")`, we should have a
sane cookie API, e.g. one that like `setcookie($name, $value, $flags)`.

That's also the way we implemented it in Aerys (
https://github.com/amphp/aerys/blob/9a7327f062aa678408dfe4f4c3c7f479db16f187/lib/Response.php#L49-L58).
It's a simple wrapper around `addHeader` to make life easier, but it
doesn't restrict developers to call `setHeader` and replace all
`set-cookie` headers.

Regards, Niklas

---

## #96522 — Yasuo Ohgaki — 2016-10-20T12:21:23+00:00

URL: https://externals.io/message/96412#96522 · In reply to: #96519

Hi Ptephen,


> As with Niklas, I have no vote, so my *only* option to prevent what I consider to be a bad decision, is to post to this thread and hope that enough of those who *do* have voting rights, reject the proposal.

It's okay, but aren't I and framework developers on the same side?

I don't want to get bug report that session lost or some important
cookie lost somehow.

Framework developers don't want to get bug report that user logouts or
some important cookie lost somehow.

It's better that we have header*() and cookie*() function for
dedicated purpose, isn't it?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

Next page: https://externals.io/message/96412.md?page=2
