Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is the DOM based XSS
    primarykey
    data
    text
    <p>I received an AppScan security report where the following piece of code was flagged as "DOM Based Cross-Site Scripting": </p> <pre><code>i !== null &amp;&amp; i.errors ? (i.errors[0].Key === "OrderNotFound" || i.errors[0].Key === "ShoppingCartModified") &amp;&amp; (alert(i.errors[0].Value), window.location.href = window.location.href.split("#")[0]) : t([s("GenericErrorMessage")]) </code></pre> <p>But I can't see where the problem is. I wonder if this could be a false positive. This is the original code without minification</p> <pre><code>if (jsonResult !== null &amp;&amp; jsonResult.errors) { if (jsonResult.errors[0].Key === "OrderNotFound" || jsonResult.errors[0].Key === "ShoppingCartModified") { alert(jsonResult.errors[0].Value); //the problem is here window.location.href = window.location.href.split("#")[0]; //or here } } else { //uiErrors is a KnockoutJS observableArray that is //shown in the page using the text binding avoiding any innerHTML injection. //res = method that returns an error msg string for a given key. uiErrors([res("GenericErrorMessage")]); } </code></pre> <p><strong>jsonResult</strong> is the response of an ajax call and it has the following structure:</p> <pre><code>{ "errors": [ {"Key": "OrderNotFound", "Value": "Your order could not be found."} ] } </code></pre> <p>Where both the <strong>Key</strong> and <strong>Value</strong> are not created using any user input. They are const strings in server code.</p> <h1>Adding AppScan Output</h1> <p>[1 of 1] DOM Based Cross-Site Scripting</p> <p>Severity: High</p> <p>Test Type: Application</p> <p>Vulnerable URL: <a href="https://www.domain.com/scripts/checkout.js" rel="nofollow">https://www.domain.com/scripts/checkout.js</a></p> <p>CVE ID(s): N/A</p> <p>CWE ID(s): 79</p> <p>Remediation Tasks: Analyze client side code and sanitize its input sources</p> <p>Variant 1 of 1 [ID=1612185601]</p> <p>Request/Response:</p> <p><a href="https://www.domain.com/scripts/checkout.js" rel="nofollow">https://www.domain.com/scripts/checkout.js</a>? v=m9is46e_hmcr4gnmuj4o6xssdozcytmn9flbuxtvbmy1:</p> <p>1 : i !== null &amp;&amp; i.errors ? (i.errors[0].Key === "OrderNotFound" || i.errors[0].Key === "ShoppingCartModified") &amp;&amp; (alert(i.errors[0].Value), window.location.href = window.location.href.split("#")[0]) : t([s ("GenericErrorMessage")])</p> <p>Validation In Response:</p> <p>N/A</p> <p>Reasoning:</p> <p>N/A</p> <p>CWE ID:</p> <p>79</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload