File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed
lib/action_controller/metal Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 1+ * Restore handling of a bare ` Authorization ` header, without ` token= `
2+ prefix.
3+
4+ Fixes #17108 .
5+
6+ * Guo Xiang Tan*
7+
8+
19## Rails 4.0.12 (November 16, 2014) ##
210
311* Fix a bug where malformed query strings lead to 500.
Original file line number Diff line number Diff line change @@ -385,6 +385,7 @@ def opaque(secret_key)
385385 #
386386 # RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
387387 module Token
388+ TOKEN_KEY = 'token='
388389 TOKEN_REGEX = /^Token /
389390 AUTHN_PAIR_DELIMITERS = /(?:,|;|\t +)/
390391 extend self
@@ -459,7 +460,13 @@ def rewrite_param_values(array_params)
459460 # pairs by the standardized `:`, `;`, or `\t` delimiters defined in
460461 # `AUTHN_PAIR_DELIMITERS`.
461462 def raw_params ( auth )
462- auth . sub ( TOKEN_REGEX , '' ) . split ( /\s *#{ AUTHN_PAIR_DELIMITERS } \s */ )
463+ _raw_params = auth . sub ( TOKEN_REGEX , '' ) . split ( /\s *#{ AUTHN_PAIR_DELIMITERS } \s */ )
464+
465+ if !( _raw_params . first =~ %r{\A #{ TOKEN_KEY } } )
466+ _raw_params [ 0 ] = "#{ TOKEN_KEY } #{ _raw_params . first } "
467+ end
468+
469+ _raw_params
463470 end
464471
465472 # Encodes the given token and options into an Authorization header value.
@@ -469,7 +476,7 @@ def raw_params(auth)
469476 #
470477 # Returns String.
471478 def encode_credentials ( token , options = { } )
472- values = [ "token= #{ token . to_s . inspect } " ] + options . map do |key , value |
479+ values = [ "#{ TOKEN_KEY } #{ token . to_s . inspect } " ] + options . map do |key , value |
473480 "#{ key } =#{ value . to_s . inspect } "
474481 end
475482 "Token #{ values * ", " } "
Original file line number Diff line number Diff line change @@ -162,17 +162,36 @@ def authenticate_long_credentials
162162 assert_equal ( expected , actual )
163163 end
164164
165+ test "token_and_options returns right token when token key is not specified in header" do
166+ token = "rcHu+HzSFw89Ypyhn/896A="
167+
168+ actual = ActionController ::HttpAuthentication ::Token . token_and_options (
169+ sample_request_without_token_key ( token )
170+ ) . first
171+
172+ expected = token
173+ assert_equal ( expected , actual )
174+ end
175+
165176 private
166177
167178 def sample_request ( token , options = { nonce : "def" } )
168179 authorization = options . inject ( [ %{Token token="#{ token } "} ] ) do |arr , ( k , v ) |
169180 arr << "#{ k } =\" #{ v } \" "
170181 end . join ( ", " )
171- @sample_request ||= OpenStruct . new authorization : authorization
182+ mock_authorization_request ( authorization )
172183 end
173184
174185 def malformed_request
175- @malformed_request ||= OpenStruct . new authorization : %{Token token=}
186+ mock_authorization_request ( %{Token token=} )
187+ end
188+
189+ def sample_request_without_token_key ( token )
190+ mock_authorization_request ( %{Token #{ token } } )
191+ end
192+
193+ def mock_authorization_request ( authorization )
194+ OpenStruct . new ( authorization : authorization )
176195 end
177196
178197 def encode_credentials ( token , options = { } )
You can’t perform that action at this time.
0 commit comments