session cookie httponly false rails 3.1

自作多情 提交于 2019-12-04 10:10:32

This little snippet seems to work :

Testapp::Application.config.session_store :cookie_store, key: '_testapp_session', :domain => :all, :httponly => false

As far as I can tell, this is a bug in rails. Perhaps the option got removed, but the documentation stayed. Any ideas on this would be welcome!

I spent several thorough hours with ActionPack, and couln't find any reference to such a configuration option-- but I still don't have the full picture as to how it works. Specifically, there's the cookiestore which holdes cookies and writes them to the header (and is passed :httponly => true), but I couldn't find how the session is using the store-- with vague things like the Rails SessionManage module being a proverbial ghost town.

I hacked up a middleware which does the job:

# application.rb:
    config.middleware.insert_before ActionDispatch::Cookies, "UnshieldCookie" # remove httponly. 

# unshielded_cookie.rb
class UnshieldCookie
  def initialize(app)
    @app = app
  end

  def call(env)
    status, headers, body = @app.call(env)

    headers['Set-Cookie'].gsub!('HttpOnly', '') if headers['Set-Cookie'].present?

    [status, headers, body]
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!