Railsでsessionを無効化する方法

Ruby on Rails

config/initializers/session_store.rbRails.application.config.session_store :disabledを書き込んでアプリケーションサーバを再起動。

echo "Rails.application.config.session_store :disabled" > config/initializers/session_store.rb

検証

Ruby on Rails 7.0で検証。Rails 3からこの方法でできるっぽい。

before

 % curl -v http://localhost:3001/ 2>&1 |grep -i cookie
< Set-Cookie: _train_session=9zmzzmUN5C%2FawwJc1xfMyQCNdWwVgoyQ4HeSgjCvK3tFdYR47cYGiKusOjIIL1goxvO3vhUazqJYtwUcQcWUGXjueOQLOyy89TOJ%2BpPgZOwcr1iFNsEXXxg4Mvt%2Be8IaCWilq7EmBn3q3r2DiK4TcfaS%2FKw9Qs3qNe6GftE%2BlYprxg3r9esCOkyVPva3OLw08IZOtgtvzcyyC6zbtTlBZ7lX9OV0E3ngUU8a5XdcFJ2bBzmKk4W6DAvIGrqOvza%2Bb7eUgWv60YdOJb5LWUkc9B3gmFz1AA%3D%3D--Zqf%2B2sbFYn7PYeMM--LPCwaBZ27oJWCKVb4lpuQA%3D%3D; path=/; HttpOnly; SameSite=Lax
 %

after

% curl -v http://localhost:3001/ 2>&1 |grep -i cookie
%

Comments

タイトルとURLをコピーしました