I have a login page https://example.com/login#destination, where destinationis the destination URL that the user tried to go to when they needed to log in.
(i.e. https://example.com/destination)
The JavaScript I was thinking about was
function onSuccessfulLogin() {
location.replace(location.hash.substring(1) || 'default')
}
This will result in an XSS vulnerability by the link attacker
https://example.com/login#javascript:..
I also need to prevent navigation to the site with the username after logging in.
https://example.com/login#https://looks-like-example.com
orhttps://example.com/login#//looks-like-example.com
How to set up onSuccessfulLogin, to make sure that the URL-address in the hash segment #is relative the URL-address, and does not begin with javascript:, https:, //or any other absolute navigation scheme?
, URL- , location.origin . , , ?