最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Subdomain cookie sent in request Cookie header, but not present in IE JavaScript's document.cookie - Stack Overflow

programmeradmin4浏览0评论

I'm having a strange problem with cookies which are being sent and received properly but are inaccessible to JavaScript on Internet Explorer. Chrome, Firefox, Opera, and Safari JavaScript is fine.

  1. Post to ".cgi?id=1234", response sets cookies, issues 302 redirect:

    HTTP/1.0 302 Moved Temporarily
    Location: .html
    Set-Cookie: AID=1495763b4fc6d5f4290e2074ab1092f7; expires=Tue Feb 16 09:33:03 2010 GMT; path=/abc/members/0912/07/news01.html; domain=abc.example; ;
    Set-Cookie: LEADENDDATE=20091218; expires=Tue Feb 16 09:33:03 2010 GMT; path=/abc/members/0912/07/news01.html; domain=abc.example; ;
    
  2. Browser requests target page, including the cookies just sent.

    GET /abc/members/0912/07/news01.html HTTP/1.1
    Cookie: AID=1495763b4fc6d5f4290e2074ab1092f7; LEADENDDATE=20091218;
    Host: members.abc.example
    
  3. Run "javascript:alert(document.cookie);" in the browser address bar.

  4. On IE, and IE only, the cookies aren't there. Other browsers are fine. This is true for IE6, 7, and 8.

So in summary,

The "wp.abc.example" sets a cookie on "abc.example", which is sent to the server in requests on "members.abc.example", but not visible to JavaScript on that page.

Why?

I thought maybe instead of "abc.example" the cookie should be set on ".abc.example" to allow subdomain matching, but even so it's being sent in the "members.abc.example" request header.

Basically it's acting as though "HttpOnly" is set on the cookie, even though from the Set-Cookie header example shown above, that flag is not included. Does the extra ";" maybe have some effect?

I'm having a strange problem with cookies which are being sent and received properly but are inaccessible to JavaScript on Internet Explorer. Chrome, Firefox, Opera, and Safari JavaScript is fine.

  1. Post to "http://wp.abc.example./content/sv2.cgi?id=1234", response sets cookies, issues 302 redirect:

    HTTP/1.0 302 Moved Temporarily
    Location: http://members.abc.example./abc/members/0912/07/news01.html
    Set-Cookie: AID=1495763b4fc6d5f4290e2074ab1092f7; expires=Tue Feb 16 09:33:03 2010 GMT; path=/abc/members/0912/07/news01.html; domain=abc.example.; ;
    Set-Cookie: LEADENDDATE=20091218; expires=Tue Feb 16 09:33:03 2010 GMT; path=/abc/members/0912/07/news01.html; domain=abc.example.; ;
    
  2. Browser requests target page, including the cookies just sent.

    GET /abc/members/0912/07/news01.html HTTP/1.1
    Cookie: AID=1495763b4fc6d5f4290e2074ab1092f7; LEADENDDATE=20091218;
    Host: members.abc.example.
    
  3. Run "javascript:alert(document.cookie);" in the browser address bar.

  4. On IE, and IE only, the cookies aren't there. Other browsers are fine. This is true for IE6, 7, and 8.

So in summary,

The "wp.abc.example." sets a cookie on "abc.example.", which is sent to the server in requests on "members.abc.example.", but not visible to JavaScript on that page.

Why?

I thought maybe instead of "abc.example." the cookie should be set on ".abc.example." to allow subdomain matching, but even so it's being sent in the "members.abc.example." request header.

Basically it's acting as though "HttpOnly" is set on the cookie, even though from the Set-Cookie header example shown above, that flag is not included. Does the extra ";" maybe have some effect?

Share Improve this question edited Dec 21, 2009 at 7:08 ryandenki asked Dec 18, 2009 at 10:11 ryandenkiryandenki 1,8693 gold badges20 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Eric Law wrote up a good article on IE's various cookie-handling quirks a while back. One of the questions he answers appears as though it may apply to your scenario:

Q8: Are there any limits to the HTML DOM document.cookie property?

A: [...]

Also, due to an obscure bug in the underlying WinINET InternetGetCookie implementation, IE’s document.cookie will not return a cookie if it was set with a path attribute containing a filename.
[...]

Note that your paths do include filenames:

Set-Cookie: AID=1495763b4fc6d5f4290e2074ab1092f7; expires=Tue Feb 16 09:33:03 2010 GMT; path=/abc/members/0912/07/news01.html; domain=abc.example.; ;
Set-Cookie: LEADENDDATE=20091218; expires=Tue Feb 16 09:33:03 2010 GMT; path=/abc/members/0912/07/news01.html; domain=abc.example.; ;

I suggest you try setting the cookies with filename-free paths, and see if that doesn't help...

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论