I am trying to sanitize the document.referror in the react component like below.
However, the Checkmarx security scanning tool complains about it. I tried sanitize-html also but did not work. Any ideas?
const checkURL = string => {
try {
return new URL(string)
}
catch (error)
{ return 'invalid' }
}
<MyComponent
action={()=>window.location.href = checkURL(document.referrer)+"/Home" }
</MyComponent>
Checkmarx: Client-DOM error:
This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.