Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie session state shared across http and https without disabling force_secure_cookies #58

Closed
kbaum opened this issue Jul 31, 2013 · 5 comments

Comments

@kbaum
Copy link

kbaum commented Jul 31, 2013

Due to issues out of our control right now, I have some logged in pages that are https and some that are http. After reading through the github readme, it would seem that i would have to disable force_secure_cookies for this to function properly.

https://github.com/tobmatth/rack-ssl-enforcer#secure-cookies-disabling

That being said I am able to jump between logged in http and https pages without being logged out. My configuration looks like:

config.middleware.use Rack::SslEnforcer, only: ['/users/sign_in', %r{/users/password/*}, %r{^/user_profile.*}], ignore: [%r{^/assets}], strict: true 

Am I misinterpreting the readme?

thx!

@ianneub
Copy link

ianneub commented Aug 15, 2013

I noticed that Rack::SslEnforcer will not set cookies to be secure on Rails 3.2 or Rails 4 (maybe others too). I'm guessing that functionality is not actually implemented for Rails > 3.1?

Here is my config:
config.middleware.use Rack::SslEnforcer, :hsts => true

I wanted to turn on secure cookies in rails, so I had to add this line as well:
config.force_ssl = true

@rymai
Copy link
Collaborator

rymai commented Aug 19, 2013

Strange, cookies are flagged as secure by default unless you set the option :force_secure_cookies to false. See the implementation here: https://github.com/tobmatth/rack-ssl-enforcer/blob/master/lib/rack/ssl-enforcer.rb#L169-L180

@ianneub that's weird since rack-ssl-enforcer's implementation and the rack-ssl one are quite similar.

@sslotnick
Copy link

You have to be careful about where the middleware is inserted. The default instructions will insert it toward the bottom. I found that you need to insert it before ActionDispatch::Cookies in order for secure cookies to work properly.

Non-secure cookies:
config.middleware.insert_after ActionDispatch::Cookies, Rack::SslEnforcer

Secure cookies:
config.middleware.insert_before ActionDispatch::Cookies, Rack::SslEnforcer

@rymai
Copy link
Collaborator

rymai commented Oct 22, 2013

Interesting, thanks for the tip! @kbaum please ensure Rack::SslEnforcer comes before ActionDispatch::Cookies in your middleware stack.

@tobmatth
Copy link
Owner

tobmatth commented Jan 9, 2015

@kbaum I'm closing here. Please reopen if needed.

@tobmatth tobmatth closed this as completed Jan 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants