Skip to content

Commit

Permalink
Check basic auth credentials contains a colon
Browse files Browse the repository at this point in the history
  • Loading branch information
mpestov authored and m.pestov committed Sep 15, 2021
1 parent 01fd264 commit 22e6cb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Expand Up @@ -103,7 +103,7 @@ def authenticate(request, &login_procedure)
end

def has_basic_credentials?(request)
request.authorization.present? && (auth_scheme(request).downcase == "basic")
request.authorization.present? && (auth_scheme(request).downcase == "basic") && user_name_and_password(request).length == 2
end

def user_name_and_password(request)
Expand Down
5 changes: 5 additions & 0 deletions actionpack/test/controller/http_basic_authentication_test.rb
Expand Up @@ -112,6 +112,11 @@ def test_encode_credentials_has_no_newline
assert_no_match(/\n/, result)
end

test "has_basic_credentials? should fail with credentials without colon" do
@request.env["HTTP_AUTHORIZATION"] = "Basic #{::Base64.encode64("David Goliath")}"
assert_not ActionController::HttpAuthentication::Basic.has_basic_credentials?(@request)
end

test "successful authentication with uppercase authorization scheme" do
@request.env["HTTP_AUTHORIZATION"] = "BASIC #{::Base64.encode64("lifo:world")}"
get :index
Expand Down

0 comments on commit 22e6cb2

Please sign in to comment.