|
| 1 | +<!DOCTYPE qhelp PUBLIC |
| 2 | +"-//Semmle//qhelp//EN" |
| 3 | +"qhelp.dtd"> |
| 4 | +<qhelp> |
| 5 | +<overview> |
| 6 | + <p> |
| 7 | + Dynamically constructing HTML with inputs from exported functions may |
| 8 | + inadvertently leave a client open to XSS attacks. |
| 9 | + |
| 10 | + Clients using the exported function may use inputs containing unsafe HTML, |
| 11 | + and if these inputs end up in the DOM, the client may be vulnerable to |
| 12 | + cross-site scripting attacks. |
| 13 | + </p> |
| 14 | + |
| 15 | +</overview> |
| 16 | +<recommendation> |
| 17 | + |
| 18 | + <p> |
| 19 | + If possible, use safe APIs when inserting HTML into the DOM. |
| 20 | + Such as writing to the <code>innerText</code> property instead of <code>innerHTML</code>. |
| 21 | + </p> |
| 22 | + |
| 23 | + <p> |
| 24 | + Alternatively, use a HTML sanitizer to escape/remove unsafe content. |
| 25 | + </p> |
| 26 | + |
| 27 | +</recommendation> |
| 28 | +<example> |
| 29 | + |
| 30 | + <p> |
| 31 | + The following example shows a library function that shows a boldface name |
| 32 | + by writing to the <code>innerHTML</code> property of an element. |
| 33 | + </p> |
| 34 | + |
| 35 | + <sample src="examples/unsafe-html-construction.js" /> |
| 36 | + |
| 37 | + <p> |
| 38 | + This library function, however, does not escape unsafe HTML, and a client |
| 39 | + that calls the function with user-supplied input may be vulnerable to |
| 40 | + cross-site scripting attacks. |
| 41 | + </p> |
| 42 | + |
| 43 | + <p> |
| 44 | + To avoid such attacks, a program can use safe APIs such as <code>innerText</code>. |
| 45 | + </p> |
| 46 | + |
| 47 | + <sample src="examples/unsafe-html-construction_safe.js" /> |
| 48 | + |
| 49 | + <p> |
| 50 | + Alternatively, use a HTML sanitizer to remove unsafe content. |
| 51 | + </p> |
| 52 | + |
| 53 | + <sample src="examples/unsafe-html-construction_sanitizer.js" /> |
| 54 | + |
| 55 | +</example> |
| 56 | +<references> |
| 57 | + <li> |
| 58 | + OWASP: |
| 59 | + <a href="https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet">DOM based |
| 60 | + XSS Prevention Cheat Sheet</a>. |
| 61 | + </li> |
| 62 | + <li> |
| 63 | + OWASP: |
| 64 | + <a href="https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet">XSS |
| 65 | + (Cross Site Scripting) Prevention Cheat Sheet</a>. |
| 66 | + </li> |
| 67 | + <li> |
| 68 | + OWASP |
| 69 | + <a href="https://www.owasp.org/index.php/DOM_Based_XSS">DOM Based XSS</a>. |
| 70 | + </li> |
| 71 | + <li> |
| 72 | + OWASP |
| 73 | + <a href="https://www.owasp.org/index.php/Types_of_Cross-Site_Scripting">Types of Cross-Site |
| 74 | + Scripting</a>. |
| 75 | + </li> |
| 76 | + <li> |
| 77 | + Wikipedia: <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross-site scripting</a>. |
| 78 | + </li> |
| 79 | +</references> |
| 80 | +</qhelp> |
0 commit comments