Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning when protected_from_forgery is mixed in. #958

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ForgeryProtection
extend ActiveSupport::Concern

included do
protect_from_forgery with: :exception
end
end
4 changes: 4 additions & 0 deletions test/apps/rails5/app/controllers/mixed_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class BaseController < ActionController::Base
# No protect_from_forgery call, but one mixed in
include ForgeryProtection
end
8 changes: 8 additions & 0 deletions test/tests/rails5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,12 @@ def test_link_to_href_safe_interpolation
:code => s(:call, nil, :link_to, s(:str, "Email!"), s(:dstr, "mailto:", s(:evstr, s(:call, s(:params), :[], s(:lit, :x))))),
:user_input => s(:call, s(:params), :[], s(:lit, :x))
end

def test_mixed_in_csrf_protection
assert_no_warning :type => :controller,
:warning_type => "Cross-Site Request Forgery",
:line => 1,
:message => /^'protect_from_forgery'\ should\ be\ called\ /,
:relative_path => "app/controllers/mixed_controller.rb"
end
end