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

Does not set session cookie as secure #91

Closed
vipulvkp opened this issue Nov 2, 2016 · 6 comments
Closed

Does not set session cookie as secure #91

vipulvkp opened this issue Nov 2, 2016 · 6 comments

Comments

@vipulvkp
Copy link

vipulvkp commented Nov 2, 2016

Hi
Below are the things I did:

  1. Installed rack-ssl-enforcer gem
  2. In config/environment.rb (I have a Rails 2.3.2 app) added below two lines:
    require 'rack/ssl-enforcer'
    config.middleware.use Rack::SslEnforcer
  3. Configured my web server(i.e. Apache) to send HSTS response header.

But still my session_id is not set as secure as verified in chrome developer console.

@tobmatth
Copy link
Owner

tobmatth commented Nov 2, 2016

You need to enable HSTS:

config.middleware.insert_before  ActionDispatch::Cookies, Rack::SslEnforcer, hsts: true

@vipulvkp
Copy link
Author

vipulvkp commented Nov 3, 2016

Hi
I think I found the issue.
Instead of config.middleware.insert_before ActionDispatch::Cookies, Rack::SslEnforcer, :hsts=>true

I added the below:

config.middleware.insert_before ActionController::Session::CookieStore, Rack::SslEnforcer, :hsts => true

I have a Rails 2 application. If I use the above (ActionDispatch), code crashes saying "Could not find ActionDispatch)

@tobmatth
Copy link
Owner

tobmatth commented Nov 3, 2016

Guess you are right, have to inspect the Middleware stack für Rails 2.x applications. Thanks for getting back, i'm closing here...

@tobmatth tobmatth closed this as completed Nov 3, 2016
@vipulvkp
Copy link
Author

vipulvkp commented Nov 3, 2016

Hey,

Can we change the path of the cookie using this gem?

Regards,
Vipul

@tobmatth
Copy link
Owner

tobmatth commented Nov 3, 2016

No, you can only configure if HSTS headers are set for subdomains or not, see
https://github.com/tobmatth/rack-ssl-enforcer/blob/master/lib/rack/ssl-enforcer.rb#L197

What would be the Use-Case for this?

@vipulvkp
Copy link
Author

vipulvkp commented Nov 3, 2016

If the path is set to the root directory ""/“, an attacker can access other cookies of the sub domain which are available under the parent domain.

It is recommended to set the value of the “path” attribute to the actual virtual directory path of the application.

I

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

2 participants