Class: ActionController::RequestForgeryProtection::CookieStore
- Inherits:
-
Object
- Object
- ActionController::RequestForgeryProtection::CookieStore
- Defined in:
- lib/action_controller/metal/request_forgery_protection.rb
Instance Method Summary collapse
- #fetch(request) ⇒ Object
-
#initialize(cookie = :csrf_token) ⇒ CookieStore
constructor
A new instance of CookieStore.
- #reset(request) ⇒ Object
- #store(request, csrf_token) ⇒ Object
Constructor Details
#initialize(cookie = :csrf_token) ⇒ CookieStore
Returns a new instance of CookieStore.
332 333 334 |
# File 'lib/action_controller/metal/request_forgery_protection.rb', line 332 def initialize( = :csrf_token) @cookie_name = end |
Instance Method Details
#fetch(request) ⇒ Object
336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/action_controller/metal/request_forgery_protection.rb', line 336 def fetch(request) contents = request..encrypted[@cookie_name] return nil if contents.nil? value = JSON.parse(contents) return nil unless value.dig("session_id", "public_id") == request.session.id_was&.public_id value["token"] rescue JSON::ParserError nil end |
#reset(request) ⇒ Object
359 360 361 |
# File 'lib/action_controller/metal/request_forgery_protection.rb', line 359 def reset(request) request..delete(@cookie_name) end |
#store(request, csrf_token) ⇒ Object
348 349 350 351 352 353 354 355 356 357 |
# File 'lib/action_controller/metal/request_forgery_protection.rb', line 348 def store(request, csrf_token) request..encrypted.permanent[@cookie_name] = { value: { token: csrf_token, session_id: request.session.id, }.to_json, httponly: true, same_site: :lax, } end |