Skip to content

Commit

Permalink
Include CSRF <meta> elements in frame layout
Browse files Browse the repository at this point in the history
Closes [hotwired#669][]

If a response to a request with the `Turbo-Frame:` header does not
include the `<meta>` elements in the `<html>` document, it's likely that
the browser will remove any `<meta>` element present after handling
navigating the `<turbo-frame>` that originated the request.

In support of testing this behavior, this commit enables CSRF protection
in the test suite.
  • Loading branch information
seanpdoyle committed Oct 29, 2024
1 parent 59e1f48 commit 7f93935
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/views/layouts/turbo_rails/frame.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html>
<head>
<%= csrf_meta_tags %>
<%= yield :head %>
</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end
2 changes: 1 addition & 1 deletion test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
config.action_dispatch.show_exceptions = :none

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
config.action_controller.allow_forgery_protection = true

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
Expand Down
2 changes: 2 additions & 0 deletions test/frames/frame_request_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Turbo::FrameRequestControllerTest < ActionDispatch::IntegrationTest

assert_select "head", count: 1
assert_select "meta[name=test][content=present]"
assert_select "meta[name=csrf-param]"
assert_select "meta[name=csrf-token]"
end

test "frame request layout can be overridden" do
Expand Down

0 comments on commit 7f93935

Please sign in to comment.