I'm getting a string from the current window's fragment identifier (location.hash
). I want to use that string as the argument to location.replace(str)
.
Under normal circumstances, the string will come from code I control, so I'm not worried about validating that the string is a URL. If the string isn't a URL, the call to replace will just fail. That's fine.
What I am concerned about is making sure the string is NOT a javascript:
URL or anything else that would allow someone to run arbitrary Javascript on my domain. Currently, I'm just checking that that str.indexOf('http') == 0
.
Is that enough or should I sanitize this string some more?