I have code in my application user i have written code for redirection
function redirect(url){
window.location=url
}
this code is failed in veracode scan stating CWE-601: URL Redirection to Untrusted Site (‘Open Redirect’)
i have tried with below code as well, same result
window.location= encodeURI(url)
and also wrote code for custom validation still its not working
function sameOrigin(url) {
const { host } = window.document.location; // host + port
const { protocol } = window.document.location;
const srOrigin = `//${host}`;
const origin = protocol + srOrigin;
// Allow absolute or scheme relative URLs to same origin
const isvalidPath =
url === origin ||
url.slice(0, origin.length + 1) === `${origin} /` ||
url === srOrigin ||
url.slice(0, srOrigin.length + 1) === `${origin} /` ||
// or any other URL that isn't scheme relative or absolute i.e relative.
!/^(//|http:|https:).*/.test(url);
return isvalidPath ? url : '/';
}
in my scenario i cant manage all valid urls and cross check with it