mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Check authentication scheme in Basic auth
`authenticate_with_http_basic` and its families should check the authentication schema is "Basic". Different schema, such as OAuth2 Bearer should be rejected by basic auth, but it was passing as the test shows. This fixes #10257.
This commit is contained in:
parent
239126385f
commit
a7a377ff39
2 changed files with 13 additions and 1 deletions
|
@ -100,7 +100,12 @@ module ActionController
|
|||
end
|
||||
|
||||
def decode_credentials(request)
|
||||
::Base64.decode64(request.authorization.split(' ', 2).last || '')
|
||||
scheme, param = request.authorization.split(' ', 2)
|
||||
if scheme == 'Basic'
|
||||
::Base64.decode64(param || '')
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
def encode_credentials(user_name, password)
|
||||
|
|
|
@ -129,6 +129,13 @@ class HttpBasicAuthenticationTest < ActionController::TestCase
|
|||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
test "authentication request with wrong scheme" do
|
||||
header = 'Bearer ' + encode_credentials('David', 'Goliath').split(' ', 2)[1]
|
||||
@request.env['HTTP_AUTHORIZATION'] = header
|
||||
get :search
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def encode_credentials(username, password)
|
||||
|
|
Loading…
Reference in a new issue