fix: better redirect handling
This commit is contained in:
parent
4cf7a94db6
commit
4a830b49e8
1 changed files with 11 additions and 7 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# License: MIT. See LICENSE
|
||||
|
||||
|
||||
from urllib.parse import urlparse
|
||||
from urllib.parse import urljoin, urlparse
|
||||
|
||||
import frappe
|
||||
import frappe.utils
|
||||
|
|
@ -202,17 +202,21 @@ def sanitize_redirect(redirect: str | None) -> str | None:
|
|||
|
||||
Allowed redirects:
|
||||
- Same host e.g. https://frappe.localhost/path
|
||||
- Just path e.g. /app
|
||||
- Just path e.g. /app gets converted to https://frappe.localhost/app
|
||||
"""
|
||||
if not redirect:
|
||||
return redirect
|
||||
|
||||
parsed_redirect = urlparse(redirect)
|
||||
if not parsed_redirect.netloc:
|
||||
return redirect
|
||||
|
||||
parsed_request_host = urlparse(frappe.local.request.url)
|
||||
if parsed_request_host.netloc == parsed_redirect.netloc:
|
||||
return redirect
|
||||
output_parsed_url = parsed_redirect._replace(
|
||||
netloc=parsed_request_host.netloc, scheme=parsed_request_host.scheme
|
||||
)
|
||||
if parsed_redirect.netloc:
|
||||
if parsed_request_host.netloc != parsed_redirect.netloc:
|
||||
output_parsed_url = output_parsed_url._replace(path="/app")
|
||||
else:
|
||||
output_parsed_url = output_parsed_url._replace(path=parsed_redirect.path)
|
||||
|
||||
return None
|
||||
return output_parsed_url.geturl()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue