I have this message from Checkmarx:
The application's = embeds untrusted data in the generated output with location, at line 19 of
****.js
. This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.
It is shown below code:
const url = (window.location.href || '');
const newHref = url.replace('parameter=12', '');
if (newHref !== url) {
window.location.href = newHref;
} else {
window.location.reload();
}
I used sanitizeHtml
and JSON.stringify
const url = window.location.href || ''
, but neither helped correct the problem. How is it possible to correct this type of error?