Skip to content

Commit c91825c

Browse files
committed
Include CSRF <meta> elements in frame layout
Closes [#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.
1 parent b733dfc commit c91825c

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

app/views/layouts/turbo_rails/frame.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<html>
22
<head>
3+
<%= csrf_meta_tags %>
34
<%= yield :head %>
45
</head>
56
<body>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
class ApplicationController < ActionController::Base
2+
protect_from_forgery
23
end

test/dummy/config/environments/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
config.action_dispatch.show_exceptions = :none
2929

3030
# Disable request forgery protection in test environment.
31-
config.action_controller.allow_forgery_protection = false
31+
config.action_controller.allow_forgery_protection = true
3232

3333
# Print deprecation notices to the stderr.
3434
config.active_support.deprecation = :stderr

test/frames/frame_request_controller_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Turbo::FrameRequestControllerTest < ActionDispatch::IntegrationTest
1414

1515
assert_select "head", count: 1
1616
assert_select "meta[name=test][content=present]"
17+
assert_select "meta[name=csrf-param]"
18+
assert_select "meta[name=csrf-token]"
1719
end
1820

1921
test "frame request layout can be overridden" do

0 commit comments

Comments
 (0)