22

新しいRails 3.xのセッション設定オプションは何かを指摘できますか?Rails 3つの追加のセッション設定オプション(key、expires_after、secure)

私はRails 2.3.xアプリケーションと同じ設定を複製しようとしています。

これは、私がアプリケーションで使用される設定です:

#environment.rb 
config.action_controller.session_store = :active_record_store 

config.action_controller.session = { 
    :key   => '_something', #non-secure for development 
    :secret  => 'really long random string' 
    } 


# production.rb - override environment.rb for production 
config.action_controller.session = { 
    :key   => '_something_secure', 
    :secret   => 'really long random string', 
    :expire_after => 60*60,#time in seconds 
    :secure   => true #The session will now not be sent or received on HTTP requests. 
} 

しかし、Railsの3.xの中で、私は次の言及を見つけることができます。

AppName::Application.config.session_store :active_record_store 

AppName::Application.config.secret_token = 'really long random string' 

AppName::Application.config.cookie_secret = 'another really long random string' 

は、他の設定はありますキーを制御する設定、expire_after時間、安全なオプション?

「config.force_ssl = true」がproduction.rbに設定されている場合、私は安全なオプションが不要になったと思いますか?

ありがとうございました!

+2

有効期限:http://stackoverflow.com/questions/5860950/setting-session-timeout-in-rails-3はセキュア –

+2

:http://stackoverflow.com/質問/ 72242/how-do-i-set-the-httponly-flag-on-cookie-in-rails –

答えて

39

これで、イニシャライザを使用してCookieベースのセッションストアを設定しました。おそらくconfig/initializers/session_store.rbになりました。 Railsの3でセッションストアは、ミドルウェアの一部であり、設定オプションはconfig.session_storeに単一の呼び出しで渡されます。

Your::Application.config.session_store :cookie_store, :key => '_session' 

あなたは:keyとハッシュにしたい任意の追加オプションを置くことができ、例えば

Your::Application.config.session_store :cookie_store, { 
    :key =>   '_session_id', 
    :path =>   '/', 
    :domain =>  nil, 
    :expire_after => nil, 
    :secure =>  false, 
    :httponly =>  true, 
    :cookie_only => true 
} 

(これらは単なる標準のデフォルトです)

あなたは、クッキーにセキュアな設定の生産にSSLを強制する場合は、本当に実際に違いを作るべきではありませんが、あなただけにそれを設定することをお勧めします安全側に...

Your::Application.config.session_store :cookie_store, { 
    :key =>   '_session_id', 
    :secure =>  Rails.env.production? 
} 
+0

そのように見えますそれ!ありがとう! – shedd

+2

また、明確にするために、これらのオプションはactive_recordセッションストアでも動作するようです。上記のコードサンプルはクッキーストア用にコーディングされていますが、active_recordストアでこれを試してみました(これは質問の質問です)、オプションが有効に見えます。 – shedd

+0

私の時間を節約してくれた古いプロジェクトのデバッグ。 –

関連する問題