|
| 1 | +<!DOCTYPE qhelp PUBLIC |
| 2 | +"-//Semmle//qhelp//EN" |
| 3 | +"qhelp.dtd"> |
| 4 | +<qhelp> |
| 5 | + |
| 6 | + <overview> |
| 7 | + <p> |
| 8 | + |
| 9 | + Library plugins, such as those for the jQuery library, are often |
| 10 | + configurable through options provided by the clients of the |
| 11 | + plugin. |
| 12 | + |
| 13 | + |
| 14 | + Clients, however, do not know the implementation details |
| 15 | + of the plugin, so it is important to document the capabilities of each |
| 16 | + option. The documentation for the plugin options that the client is |
| 17 | + responsible for sanitizing is of particular importance. |
| 18 | + |
| 19 | + Otherwise, the plugin may write user input (for example, a URL query |
| 20 | + parameter) to a web page without properly sanitizing it first, |
| 21 | + which allows for a cross-site scripting vulnerability in the client |
| 22 | + application through dynamic HTML construction. |
| 23 | + |
| 24 | + </p> |
| 25 | + </overview> |
| 26 | + |
| 27 | + <recommendation> |
| 28 | + <p> |
| 29 | + |
| 30 | + Document all options that can lead to cross-site scripting |
| 31 | + attacks, and guard against unsafe inputs where dynamic HTML |
| 32 | + construction is not intended. |
| 33 | + |
| 34 | + </p> |
| 35 | + </recommendation> |
| 36 | + |
| 37 | + <example> |
| 38 | + <p> |
| 39 | + |
| 40 | + The following example shows a jQuery plugin that selects a |
| 41 | + DOM element, and copies its text content to another DOM element. The |
| 42 | + selection is performed by using the plugin option |
| 43 | + <code>sourceSelector</code> as a CSS selector. |
| 44 | + |
| 45 | + </p> |
| 46 | + |
| 47 | + <sample src="examples/UnsafeJQueryPlugin.js" /> |
| 48 | + |
| 49 | + <p> |
| 50 | + |
| 51 | + This is, however, not a safe plugin, since the call to |
| 52 | + <code>jQuery</code> interprets <code>sourceSelector</code> as HTML if |
| 53 | + it is a string that starts with <code><</code>. |
| 54 | + |
| 55 | + </p> |
| 56 | + |
| 57 | + <p> |
| 58 | + |
| 59 | + Instead of documenting that the client is responsible for |
| 60 | + sanitizing <code>sourceSelector</code>, the plugin can use |
| 61 | + <code>jQuery.find</code> to always interpret |
| 62 | + <code>sourceSelector</code> as a CSS selector: |
| 63 | + |
| 64 | + </p> |
| 65 | + |
| 66 | + <sample src="examples/UnsafeJQueryPlugin_safe.js" /> |
| 67 | + |
| 68 | + |
| 69 | + </example> |
| 70 | + |
| 71 | + <references> |
| 72 | + <li> |
| 73 | + OWASP: |
| 74 | + <a href="https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet">DOM based |
| 75 | + XSS Prevention Cheat Sheet</a>. |
| 76 | + </li> |
| 77 | + <li> |
| 78 | + OWASP: |
| 79 | + <a href="https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet">XSS |
| 80 | + (Cross Site Scripting) Prevention Cheat Sheet</a>. |
| 81 | + </li> |
| 82 | + <li> |
| 83 | + OWASP |
| 84 | + <a href="https://www.owasp.org/index.php/DOM_Based_XSS">DOM Based XSS</a>. |
| 85 | + </li> |
| 86 | + <li> |
| 87 | + OWASP |
| 88 | + <a href="https://www.owasp.org/index.php/Types_of_Cross-Site_Scripting">Types of Cross-Site |
| 89 | + Scripting</a>. |
| 90 | + </li> |
| 91 | + <li> |
| 92 | + Wikipedia: <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross-site scripting</a>. |
| 93 | + </li> |
| 94 | + <li> |
| 95 | + jQuery: <a href="https://learn.jquery.com/plugins/basic-plugin-creation/">Plugin creation</a>. |
| 96 | + </li> |
| 97 | + <li> |
| 98 | + Bootstrap: <a href="https://github.com/twbs/bootstrap/pull/27047">XSS vulnerable bootstrap plugins</a>. |
| 99 | + </li> |
| 100 | + </references> |
| 101 | +</qhelp> |
0 commit comments