Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/omniauth/strategies/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def client
end

def request_phase
neutralize_unsafe_destination!

redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
end

Expand Down Expand Up @@ -97,6 +99,16 @@ def deep_symbolize(options)
hash
end

def local_uri?(uri)
uri.relative? || uri.host.include?(request.host)
end

# if request.params["destination"] does not contain a destination that
# includes
def neutralize_unsafe_destination!
request.params.delete('destination') if unsafe_destination?
end

def options_for(option)
hash = {}
options.send(:"#{option}_options").select { |key| options[key] }.each do |key|
Expand All @@ -105,6 +117,18 @@ def options_for(option)
hash
end

def safe_destination?
true if request.params['destination'].nil?

uri = URI.parse(request.params['destination'])

local_uri?(uri) ? true : false
end

def unsafe_destination?
!safe_destination?
end

# An error that is indicated in the OAuth 2.0 callback.
# This could be a `redirect_uri_mismatch` or other
class CallbackError < StandardError
Expand Down