Cookie share with subdomain nodejs httponly cookie

情到浓时终转凉″ 提交于 2019-12-11 06:07:34

问题


I am using express-session module for maintain session. i have two app. i want to share cookies with this apps, parent app run in example.com , and child app run in child.example.com. i set httponly cookie using express-session it sets in the child app.i can verified that cookie in resource tab in chrome debugger.

Network tab:

When the first call to sub-domain: it load like "http://www.child.example.com" cookie set in the request. while the url is redirect to server IP . cookie not available after that.

like http://13.25.230.2/index cookie not avaliable on that


回答1:


When you send the Set-Cookie HTTP header, you can specify the domain it is for.

Set-Cookie: name=value; domain=example.com

The domain must be a suffix of the domain hosting the page.

i.e. foo.example.com, bar.baz.example.com and www.example.com can all share a cookie belonging to example.com.

A URL using an IP address has no hostname in it at all and cannot match that rule.

There is no way to share your cookie between example.com and 13.25.230.2. Give the site a hostname instead.




回答2:


There is no way you can set cookie using setcookie header from one host to another. For example from example.com to foobar.com. If you have to do it. Then do it by passing the cookie value to server side script for example foobar.com\set-my-cookie.php and use to to save the cookie.

Httponly cookies cannot be set or read from client side code.



来源:https://stackoverflow.com/questions/35268764/cookie-share-with-subdomain-nodejs-httponly-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!