Skip to content

Commit

Permalink
fix(sessions): ignore login requests with redirects to files
Browse files Browse the repository at this point in the history
this improves the previous work
  • Loading branch information
stakach committed Sep 13, 2023
1 parent 90885f7 commit 0f1ba41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
8 changes: 1 addition & 7 deletions app/controllers/auth/coauth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,10 @@ def store_social(uid, provider)

def set_continue(path)
path ||= "/"
uri = Addressable::URI.parse(path)

# we won't set continue to files (except html)
ext = uri.extname
if ext.presence
return unless ext.downcase == ".html"
end

# prevent adverse behaviour
if !path.start_with?("/") || path.include?("//")
uri = Addressable::URI.parse(path)
path = "#{uri.request_uri}#{uri.fragment ? "##{uri.fragment}" : nil}"
end

Expand Down
17 changes: 13 additions & 4 deletions app/controllers/auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ class SessionsController < CoauthController
# Inline login
def new
details = params.permit(:provider, :continue, :id)
remove_session
continue_uri = details[:continue]

# check for x-api-keys
# if they exist and are valid (making a request to rest-api to confirm)
# then configure a long lasting verified cookie
if continue_uri
parsed_uri = URI.parse(continue_uri)

# we won't set continue to files (except html)
# we 401 here as this redirect is most likely caused by asset protection
ext = parsed_uri.extname
if ext.presence && ext.downcase != ".html"
head :bad_request
return
end

# check for x-api-keys
# if they exist and are valid (making a request to rest-api to confirm)
# then configure a long lasting verified cookie
query_params = parsed_uri.query
query_fragment = parsed_uri.fragment
if query_fragment
Expand All @@ -38,6 +46,7 @@ def new
end
end

remove_session
provider = details[:provider]
auth_id = details[:id]

Expand Down

0 comments on commit 0f1ba41

Please sign in to comment.