Skip to content

Commit dd4ed2f

Browse files
committed
Deprecate passing auth tokens as query parameters
This isn't secure as it will go over the wire in the clear for now HTTPS connection. Additionally, it may be logged by the Heroku router (which currently cannot be prevented).
1 parent 89a5673 commit dd4ed2f

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/kracken/controllers/token_authenticatable.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ def current_user_id
148148
# transfer the knowledge about also checking for the params.
149149
def munge_header_auth_token!
150150
return unless params[:token]
151+
deprecation = ActiveSupport::Deprecation.new("1.0", "kracken")
152+
deprecation.behavior = ActiveSupport::Deprecation.behavior
153+
deprecation.silenced = ActiveSupport::Deprecation.silenced
154+
controller_action = "#{request.controller_class}#" \
155+
"#{request.path_parameters[:action] || :index}"
156+
deprecation.warn "[#{controller_action}][kracken] Passing auth " \
157+
"tokens as query parameters is deprecated. This is insecure and " \
158+
"will be removed in a future version of Kracken. Use the " \
159+
"'Authorization' header instead."
151160
request.env['HTTP_AUTHORIZATION'] = "Token token=\"#{params[:token]}\""
152161
end
153162

spec/kracken/controllers/token_authenticatable_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def authenticate_or_request_with_http_token(realm = nil)
3636
a_controller.params = { token: expected_token }
3737

3838
expect {
39-
a_controller.authenticate_user_with_token!
39+
ActiveSupport::Deprecation.silence do
40+
a_controller.authenticate_user_with_token!
41+
end
4042
}.to change {
4143
a_controller.request.env
4244
}.from(

spec/support/base_controller_double.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
module Kracken
44
class BaseControllerDouble
5-
Request = Struct.new(:env)
5+
Request = Struct.new(:env, :controller_class, :path_parameters)
66

77
attr_accessor :session, :cookies, :request, :params
88

99
def initialize
1010
@session = {}
1111
@cookies = {}
12-
@request = Request.new({})
13-
@params = {}
12+
@params = { action: :index }
13+
@request = Request.new({}, self.class, @params.slice(:action))
1414
end
1515

1616
def self.helper_method(*) ; end

0 commit comments

Comments
 (0)