Skip to content

Commit b13e879

Browse files
committed
[Security] Fixes CSRF vulnerability, introduced by 53eef4f
Reported by SourceClear, Inc.
1 parent 464440c commit b13e879

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

app/controllers/rails_admin/application_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class ActionNotAllowed < ::StandardError
1111
end
1212

1313
class ApplicationController < Config.parent_controller.constantize
14+
protect_from_forgery with: :exception
15+
1416
before_action :_authenticate!
1517
before_action :_authorize!
1618
before_action :_audit!

spec/integration/rails_admin_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,17 @@
148148
is_expected.to have_selector('.label-danger')
149149
end
150150
end
151+
152+
describe 'CSRF protection' do
153+
before do
154+
allow_any_instance_of(ActionController::Base).to receive(:protect_against_forgery?).and_return(true)
155+
end
156+
157+
it 'is enforced' do
158+
visit new_path(model_name: 'league')
159+
fill_in 'league[name]', with: 'National league'
160+
find('input[name="authenticity_token"]', visible: false).set("invalid token")
161+
expect { click_button 'Save' }.to raise_error ActionController::InvalidAuthenticityToken
162+
end
163+
end
151164
end

0 commit comments

Comments
 (0)