This project is archived and is in readonly mode.

#6196 ✓committed
Ravil Bayramgalin

[PATCH] Improve support for non-standard domain names

Reported by Ravil Bayramgalin | December 19th, 2010 @ 07:57 PM | in 3.1

Currently when setting domain :all option Rails uses regexp which handles correctly australian and uk styles tld. It is plenty for default behavior, but sometimes we want to use different logic.

For example when dealing with domain like www.app.me the cookie will be set for .www.app.me domain which is not correct. Another example darberry.com.ua - it will be set as .com.ua. And there are plenty of exceptions like this as you can see at http://publicsuffix.org/list.

So I propose a couple of patches to add more flexibility.


First patch adds support for supplying several domain names to cookies. For example,

:domain => %w(.app.me .darberry.com.ua)

And it will set appropriate domain for all cookies.


Second patch adds more flexibility when you deal with wildcard subdomains and they are not correctly parsed by default domain regexp. For example, your application is deployed to subdomain.hosting.com and your application supports subdomains on top so you want to share cookies only between subdomains on top of your application. It's easy to achieve by using custom tld length:

:domain => :all, :tld_length => 3

and it will correctly set cookies domain to .subdomain.hosting.com


https://gist.github.com/734913 - first patch
https://gist.github.com/747615 - second patch

If there is anything I could do to improve these patches I would be happy to do it.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages