Change cookie domains

I use apache as a proxy for my application web server and would like to change the domain name associated with the sessionid cookie on the fly.

The cookie has a .company.com domain associated with it, and I would like to use apache mod rewrite (or some similar module) to transparently change the domain to app.company.com. Is it possible? and if so, how would this be done?

+5
source share
5 answers

You can only change the cookie domain on the client or set it on the server . Once the cookie is set, the path and domain information for it exists only on the client. Therefore, existing cookies cannot change their domain on the server because this information is not sent by the client to the server.

For example, if there is a cookie on your local computer:

MYCOOKIE:123, domain:www.test.com, path:/

The server will only receive:

MYCOOKIE:123 

on server. Why is the path and domain not sent? Since the browser stores this information on the client and does not interfere with sending it, because it sends this cookie only to your server if the page is on www.test.com and along the path / .

, , cookie. , - , : , cookie , . , Apache mod_headers:

<IfModule mod_headers.c>
  Header edit Set-Cookie (.*)(domain=.company.com;)(.*) $1 domain=app.company.com; $2
</IfModule>

mod_headers cookie, , , :

<IfModule mod_headers.c>
  RequestHeader edit Cookie "OLD_COOKIE=([0-9a-zA-Z\-]*);" "NEW_COOKIE_NAME=$1;"
</IfModule>

cookie, .

+4
ProxyPassReverseCookieDomain company.com app.company.com

( , /).

ref: https://httpd.apache.org/docs/2.4/en/mod/mod_proxy.html#ProxyPassReverseCookieDomain

+3

, ​​. , , mod_ext_filter, .

, cookie, cookie.

0

, javascript cookie - ( ), . , , . .

0

- Host: domain= cookie, Apache ProxyPreserveHost On Host: .

, , , , , Host. , cookie, URL-, , , mod_substitute

0

All Articles