Archived
allow relative return_path only, check validity
This commit is contained in:
@@ -7,7 +7,9 @@ class SessionsController < ApplicationController
|
|||||||
flash[:alert] = "You are already logged in!"
|
flash[:alert] = "You are already logged in!"
|
||||||
redirect_to current_user
|
redirect_to current_user
|
||||||
else
|
else
|
||||||
cookies[:return_path] = params[:return_path] if params[:return_path]
|
if params[:return_path] && params[:return_path][0] == "/"
|
||||||
|
cookies[:return_path] = params[:return_path]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,7 +44,14 @@ class SessionsController < ApplicationController
|
|||||||
flash[:alert] = "You are already logged in!"
|
flash[:alert] = "You are already logged in!"
|
||||||
end
|
end
|
||||||
if cookies[:return_path]
|
if cookies[:return_path]
|
||||||
|
begin
|
||||||
|
# might be invalid path
|
||||||
|
URI.parse(cookies[:return_path])
|
||||||
redirect_to cookies[:return_path]
|
redirect_to cookies[:return_path]
|
||||||
|
rescue URI::Error
|
||||||
|
flash[:alert] = "Invalid return path!"
|
||||||
|
redirect_to blogposts_path
|
||||||
|
end
|
||||||
cookies.delete(:return_path)
|
cookies.delete(:return_path)
|
||||||
else
|
else
|
||||||
redirect_to blogposts_path
|
redirect_to blogposts_path
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
flash[:alert] = "Please login first"
|
flash[:alert] = "Please login first"
|
||||||
cookies[:return_path] = request.fullpath
|
cookies[:return_path] = request.env['PATH_INFO']
|
||||||
redirect_to login_path
|
redirect_to login_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user