2

I'm using express and using ngrok to test my server so I have a URL like a846d0979b95.ngrok.io. In express I'm trying to set a cookie so that the domain property is ".ngrok.io" and not "a846d0979b95.ngrok.io" to set the cookie on the domain and not on the subdomain.

response.cookie('test-cookie', '1234', {
    domain: '.ngrok.io'
})

Although on chrome dev tools the cookie is not accepted. Chrome gives the error This Set-Cookie was blocked because its Domain attribute is invalid with regards to the current host URL

enter image description here

Note:

I can set the cookies for a846d0979b95.ngrok.io with the default domain "a846d0979b95.ngrok.io" with no problem

masonCherry
  • 894
  • 6
  • 14
  • 1
    See https://stackoverflow.com/a/52475993/529282 ngrok.io is indeed defined in https://publicsuffix.org/list/public_suffix_list.dat – Martheen Apr 11 '21 at 02:48
  • Does this answer your question? [Chrome not sharing the cookie between the subdomains](https://stackoverflow.com/questions/42419074/chrome-not-sharing-the-cookie-between-the-subdomains) – Martheen Apr 11 '21 at 02:49
  • @Martheen I can set cookies on ngrok no problem. those are accepted and stay there. what I can't do is set a cookie 's property to `.ngrok.io`. the request URL is .ngrok.io and it returns a cookie whose domain is supposed to be .ngrok.io ( the parent domain) that's what fails. – masonCherry Apr 11 '21 at 02:56
  • @masonCherry Public Suffix List says: "Avoid privacy-damaging "supercookies" being set for high-level domain name suffixes". I think we can't set `Domain=.ngrok.io` – Renan Coelho Jun 18 '23 at 23:24
  • Try using localhost.run – Renan Coelho Jun 18 '23 at 23:33
  • @RenanCoelho what is that? – masonCherry Jun 19 '23 at 12:09
  • What? Localhost.run? It is a service like Ngrok I'm using as an alternative. It is working with cookies when you set `Domain=.xxx` – Renan Coelho Jun 20 '23 at 00:54
  • I wish i saw this a couple hours ago :) .ngrok.io just have to keep cookies on subdomain and it works fine. – Artistan Jul 25 '23 at 20:39

0 Answers0