title: Prevent Client DOM XSS Vulnerability in Javascript
body: <p>I am working with Checkmarx to scan my code for any potential vulnerabilities. I am getting</p>
  <p><em>This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.</em> message with following code.</p>
  <pre><code>var currentUrl = location.href;
  </code></pre>
  <p>I have tried to resolve this with following code, but seems like Checkmarx is not able to detect that I am already sanitizing the data.</p>
  <pre><code>var currentUrl = checkUrlForXSS(location.href);
  
  // function definition
  
  function checkUrlForXSS(url) {
      const reg = /(script|\)|\(|\&gt;|\&lt;)/ig;
      return url.replace(reg, &quot;&quot;);
  }
  </code></pre>
  <p>Is there any way I can sanitize the data in Javascript and resolve the vulnerability without using any libraries (like DOMPurify)?</p>
  <p>Thank you.</p>