I have a bunch of domains such as store.example.com, user.example.com, intranet.example.com and each one can read cookies. However, I have a Sinatra app that is writing the cookies by doing something like session[:field] = value
When I inspect the cookie, I get something like this: BAh7CUkiD3Nlc3Npb25faWQGOgZFVEkiRTcwNmUwYTU1MjBmMzUyMTZiYzQ0%0ANjZhZDBkOGFmNmFhN2M3OGIxZTM3NGNjMDZiYmRkNDE2MmVlMDU2MWY2MTQG%0AOwBGSSIJY3NyZgY7AEZJIiVkMWUyYzI0NmEwZThiNjVhM2FlZGJjNWFhMzlk%0AYzc0YQY7AEZJIg10cmFja2luZwY7AEZ7B0kiFEhUVFBfVVNFUl9BR0VOVAY7%0AAFRJIi0xZDQ3MmI3NDZiMjFhNmJlNmYyMmUxMGU1MzI3N2Q5MmVlYmQ1N2Qx%0ABjsARkkiGUhUVFBfQUNDRVBUX0xBTkdVQUdFBjsAVEkiLTY2ZWFlOTcxNDky%0AOTM4YzJkY2MyZmIxZGRjOGQ3ZWMzMTk2MDM3ZGEGOwBGSSIQdXNlcl9zZWNy%0AZXQGOwBGSSIlMjg3NjdkMGVmNmZlOGUwMDIxMDRmODhiZDcwZTI1OTYGOwBU%0A--e8ca14be9bbe63226fd2d6e0f8c0b3946cc66fd0
which appears to be both base64 encoded and encrypted.
My question is how can I write a 'raw' cookie that can be easily read by all subdomains trying to consume it? It doesn't need to be encrypted and/or encoded.
Use Sinatra Cookies http://www.sinatrarb.com/contrib/cookies.html
require "sinatra/cookies"
cookies[:something] = 'foobar'
You can also read raw cookies in the request object:
request.cookies
As described in Accessing the Request Object
There is also the set_cookie
method of the response object
response.set_cookie("my_cookie", :value => "value_of_cookie",
:domain => myDomain,
:path => myPath,
:expires => Date.new(2020,1,1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With