0

My site doesn't deal with sensitive information, so I don't need SSL for it. However, I obviously want to transfer the user passwords via SSL. The site is on Heroku, and Heroku provides free piggyback SSL at subdomains of Herokuapp. I could visit https://example.herokuapp.com and it would access the same site and data as http://example.com.

I want to let users sign in to an iframe of example.herokuapp.com and cause them to be logged in to my actual site example.com. But since they're different domains, they use different cookies and logging in to one doesn't login to the other. Is there any way I could circumvent this and get herokuapp login to work for my main domain too?

am-rails
  • 1,463
  • 2
  • 16
  • 40

1 Answers1

1

For security reason, it's not possible to share cookies across different domains.

What you can do, is to perform the login and authentication in the SSL protected site, set a one-time token, then redirect back the user to the main application passing the token. If the token matches and it's not expired, authenticate the user in the main application.

The same approach is also described more extensively in this answer.

When someone clicks a 'sign in' link (or presents a persistent login cookie), the sign in form ultimately sends its data to a URL that is on the central domain, along with a hidden form element saying which domain it came from (just for convenience, so the user is redirected back afterwards).

This page at the central domain then proceeds to set a session cookie (if the login went well) and redirect back to whatever domain the user logged in from, with a specially generated token in the URL which is unique for that session.

The page at the satellite URL then checks that token to see if it does correspond to a token that was generated for a session, and if so, it redirects to itself without the token, and sets a local cookie. Now that satellite domain has a session cookie as well. This redirect clears the token from the URL, so that it is unlikely that the user or any crawler will record the URL containing that token (although if they did, it shouldn't matter, the token can be a single-use token).

Community
  • 1
  • 1
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364