Codebase list ruby-omniauth-facebook / c277322
fix CSRF vulnerability (cherry-picked from 1-5-0-stable) Conflicts: lib/omniauth/strategies/facebook.rb test/support/shared_examples.rb test/test.rb Mark Dodwell 10 years ago
5 changed file(s) with 9 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
5252 ### Per-Request Options
5353
5454 If you want to set the `display` format, `auth_type`, or `scope` on a per-request basis, you can just pass it to the OmniAuth request phase URL, for example: `/auth/facebook?display=popup` or `/auth/facebook?scope=email`.
55
56 You can also pass through a `state` param which will be passed along to the callback url.
5755
5856 ### Custom Callback URL/Path
5957
00 module OmniAuth
11 module Facebook
2 VERSION = "1.4.1"
2 VERSION = "1.5.0"
33 end
44 end
132132 end
133133
134134 ##
135 # You can pass +display+, +state+, +scope+, or +auth_type+ params to the auth request, if
135 # You can pass +display+, +scope+, or +auth_type+ params to the auth request, if
136136 # you need to set them dynamically. You can also set these options
137137 # in the OmniAuth config :authorize_params option.
138138 #
140140 #
141141 def authorize_params
142142 super.tap do |params|
143 %w[display state scope auth_type].each do |v|
143 %w[display scope auth_type].each do |v|
144144 if request.params[v]
145145 params[v.to_sym] = request.params[v]
146
147 # to support omniauth-oauth2's auto csrf protection
148 session['omniauth.state'] = params[:state] if v == 'state'
149146 end
150147 end
151148
4949 assert_equal strategy.authorize_params['state'], strategy.session['omniauth.state']
5050 end
5151
52 test 'should store state in the session when present in authorize params vs. a random one' do
53 @request.stubs(:params).returns({ 'state' => 'bar' })
52 test 'should not store state in the session when present in authorize params vs. a random one' do
5453 @options = { :authorize_params => { :state => 'bar' } }
5554 refute_empty strategy.authorize_params['state']
56 assert_equal 'bar', strategy.authorize_params[:state]
55 refute_equal 'bar', strategy.authorize_params[:state]
5756 refute_empty strategy.session['omniauth.state']
58 assert_equal 'bar', strategy.session['omniauth.state']
57 refute_equal 'bar', strategy.session['omniauth.state']
5958 end
6059
61 test 'should store state in the session when present in request params vs. a random one' do
60 test 'should not store state in the session when present in request params vs. a random one' do
6261 @request.stubs(:params).returns({ 'state' => 'foo' })
6362 refute_empty strategy.authorize_params['state']
64 assert_equal 'foo', strategy.authorize_params[:state]
63 refute_equal 'foo', strategy.authorize_params[:state]
6564 refute_empty strategy.session['omniauth.state']
66 assert_equal 'foo', strategy.session['omniauth.state']
65 refute_equal 'foo', strategy.session['omniauth.state']
6766 end
6867 end
6968
5353 @request.stubs(:params).returns({ 'display' => 'touch' })
5454 assert strategy.authorize_params.is_a?(Hash)
5555 assert_equal 'touch', strategy.authorize_params[:display]
56 end
57
58 test 'includes state parameter from request when present' do
59 @request.stubs(:params).returns({ 'state' => 'some_state' })
60 assert strategy.authorize_params.is_a?(Hash)
61 assert_equal 'some_state', strategy.authorize_params[:state]
6256 end
6357
6458 test 'includes auth_type parameter from request when present' do