0

I am getting partial list of cookies with document.cookie when executing on subdomain. I would like to retrieve superdomain+subdomain cookies. Is there any way to do that?

Let say I have a domain

  • example.com
  • sub.example.com

And I have cookies set

name=value domain

  • c1=2 => .example.com
  • c2=4 => sub.example.com

If url in browser is sub.example.com I want to get all the above cookies how would I do that? document.cookie only returns c2=4

Rajesh Jangid
  • 724
  • 6
  • 13

2 Answers2

0

You are trying to access cookies from different domain. Browser not going to allow this. Please refer this.

Tanmay
  • 1,123
  • 1
  • 10
  • 20
  • Can access subdomain cookies if cookie domain is prepended with a period(.) RFC reference https://tools.ietf.org/html/rfc2109 – Rajesh Jangid Oct 27 '17 at 12:55
0

Turns out there was a flag in browser which sets httponly cookie, This cookie is not visible from document.cookie javascript method for security reasons.

Rajesh Jangid
  • 724
  • 6
  • 13