File tree 3 files changed +38
-4
lines changed
lib/action_controller/metal 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
+
1
9
## Rails 4.0.12 (November 16, 2014) ##
2
10
3
11
* 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)
385
385
#
386
386
# RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
387
387
module Token
388
+ TOKEN_KEY = 'token='
388
389
TOKEN_REGEX = /^Token /
389
390
AUTHN_PAIR_DELIMITERS = /(?:,|;|\t +)/
390
391
extend self
@@ -459,7 +460,13 @@ def rewrite_param_values(array_params)
459
460
# pairs by the standardized `:`, `;`, or `\t` delimiters defined in
460
461
# `AUTHN_PAIR_DELIMITERS`.
461
462
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
463
470
end
464
471
465
472
# Encodes the given token and options into an Authorization header value.
@@ -469,7 +476,7 @@ def raw_params(auth)
469
476
#
470
477
# Returns String.
471
478
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 |
473
480
"#{ key } =#{ value . to_s . inspect } "
474
481
end
475
482
"Token #{ values * ", " } "
Original file line number Diff line number Diff line change @@ -162,17 +162,36 @@ def authenticate_long_credentials
162
162
assert_equal ( expected , actual )
163
163
end
164
164
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
+
165
176
private
166
177
167
178
def sample_request ( token , options = { nonce : "def" } )
168
179
authorization = options . inject ( [ %{Token token="#{ token } "} ] ) do |arr , ( k , v ) |
169
180
arr << "#{ k } =\" #{ v } \" "
170
181
end . join ( ", " )
171
- @sample_request ||= OpenStruct . new authorization : authorization
182
+ mock_authorization_request ( authorization )
172
183
end
173
184
174
185
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 )
176
195
end
177
196
178
197
def encode_credentials ( token , options = { } )
You can’t perform that action at this time.
0 commit comments