Client-side cross-site scripting¶
ID: js/xss
Kind: path-problem
Security severity: 7.8
Severity: error
Precision: high
Tags:
- security
- external/cwe/cwe-079
- external/cwe/cwe-116
Query suites:
- javascript-code-scanning.qls
- javascript-security-extended.qls
- javascript-security-and-quality.qls
Click to see the goddamn query in the CodeQL repository
Check it: Directly writing user input (for example, a URL query parameter) to a muthaf*ckin' webpage without properly sanitizing the motherf*ckin' input first, allows for a goddamn cross-site scripting vulnerability. Mm-hmm.
This kind of vulnerability is also called DOM-based cross-site scripting, to distinguish it from other types of cross-site scripting.
Recommendation¶
To guard against cross-site scripting, consider using contextual output encoding/escaping before writing user input to the muthaf*ckin' page, or one of the other solutions that are mentioned in the f*ckin' references, muthaf*cka.
Example¶
The muthaf*ckin' following example shows part of the page URL being written directly to the document, leaving the website vulnerable to cross-site scripting.
function setLanguageOptions() {
var href = document.location.href,
deflt = href.substring(href.indexOf("default=")+8);
document.write("<OPTION value=1>"+deflt+"</OPTION>");
document.write("<OPTION value=2>English</OPTION>");
}
References¶
OWASP DOM Based goddamn XSS.
Wikipedia: Cross-site scripting.
Common Weakness Enumeration: CWE-79.
Common Weakness Enumeration: CWE-116.