Skip to content

Commit c3ceeb4

Browse files
committed
Document escaping HTML, script injection. Fixes jquery#23
1 parent eae9d8b commit c3ceeb4

10 files changed

+12
-0
lines changed

entries/after.xml

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ $( "p" ).first().after( $newdiv1, [ newdiv2, existingdiv1 ] );
100100
</code></pre>
101101
<p>Since <code>.after()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( "p" ).first().after( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on the elements that are collected in the code.</p>
102102
</longdesc>
103+
<note id="html-code-execution" type="additional"/>
103104
<example>
104105
<desc>Inserts some HTML after all paragraphs.</desc>
105106
<code><![CDATA[

entries/append.xml

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ $( "body" ).append( $newdiv1, [ newdiv2, existingdiv1 ] );
7979
</code></pre>
8080
<p>Since <code>.append()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$('body').append( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on how you collect the elements in your code.</p>
8181
</longdesc>
82+
<note id="html-code-execution" type="additional"/>
8283
<example>
8384
<desc>Appends some HTML to all paragraphs.</desc>
8485
<code><![CDATA[

entries/appendTo.xml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ $( "h2" ).appendTo( $( ".container" ) );
5656
<p>If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first, and that new set (the original element plus clones) is returned.</p>
5757
<p><strong>Before jQuery 1.9,</strong> the append-to-single-element case did not create a new set, but instead returned the original set which made it difficult to use the <code>.end()</code> method reliably when being used with an unknown number of elements.</p>
5858
</longdesc>
59+
<note id="html-code-execution" type="additional"/>
5960
<example>
6061
<desc>Append all spans to the element with the ID "foo" (Check append() documentation for more examples)</desc>
6162
<code><![CDATA[

entries/before.xml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ $( "p" ).first().before( newdiv1, [ newdiv2, existingdiv1 ] );
8080
</code></pre>
8181
<p>Since <code>.before()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( "p" ).first().before( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on how you collect the elements in your code.</p>
8282
</longdesc>
83+
<note id="html-code-execution" type="additional"/>
8384
<example>
8485
<desc>Inserts some HTML before all paragraphs.</desc>
8586
<code><![CDATA[

entries/html.xml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $( "div.demo-container" ).html();
2525
</code></pre>
2626
<p>This method uses the browser's <code>innerHTML</code> property. Some browsers may not return HTML that exactly replicates the HTML source in an original document. For example, Internet Explorer sometimes leaves off the quotes around attribute values if they contain only alphanumeric characters.</p>
2727
</longdesc>
28+
<note id="html-code-execution" type="additional"/>
2829
<example>
2930
<desc>Click a paragraph to convert it from html to text.</desc>
3031
<code><![CDATA[

entries/insertAfter.xml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ $( "h2" ).insertAfter( $( ".container" ) );
5252
<p>If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first, and that new set (the original element plus clones) is returned.</p>
5353
<p><strong>Before jQuery 1.9,</strong> the append-to-single-element case did not create a new set, but instead returned the original set which made it difficult to use the <code>.end()</code> method reliably when being used with an unknown number of elements.</p>
5454
</longdesc>
55+
<note id="html-code-execution" type="additional"/>
5556
<example>
5657
<desc>Insert all paragraphs after an element with id of "foo". Same as $( "#foo" ).after( "p" )</desc>
5758
<code><![CDATA[

entries/insertBefore.xml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ $( "h2" ).insertBefore( $( ".container" ) );
5252
<p>If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first, and that new set (the original element plus clones) is returned.</p>
5353
<p><strong>Before jQuery 1.9,</strong> the append-to-single-element case did not create a new set, but instead returned the original set which made it difficult to use the <code>.end()</code> method reliably when being used with an unknown number of elements.</p>
5454
</longdesc>
55+
<note id="html-code-execution" type="additional"/>
5556
<example>
5657
<desc>Insert all paragraphs before an element with id of "foo". Same as $( "#foo" ).before( "p" )</desc>
5758
<code><![CDATA[

entries/prepend.xml

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ $( "body" ).prepend( $newdiv1, [ newdiv2, existingdiv1 ] );
7979
</code></pre>
8080
<p>Since <code>.prepend()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( "body" ).prepend( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on how you collect the elements in your code.</p>
8181
</longdesc>
82+
<note id="html-code-execution" type="additional"/>
8283
<example>
8384
<desc>Prepends some HTML to all paragraphs.</desc>
8485
<code><![CDATA[

entries/prependTo.xml

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ $( "h2" ).prependTo( $( ".container" ) );
5555
</code></pre>
5656
<p>If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first.</p>
5757
</longdesc>
58+
<note id="html-code-execution" type="additional"/>
5859
<example>
5960
<desc>Prepend all spans to the element with the ID "foo" (Check .prepend() documentation for more examples)</desc>
6061
<css><![CDATA[

notes.xsl

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<xsl:when test="@id = 'slide-in-ie'">
4141
If <code><xsl:value-of select="@data-title"/></code> is called on an unordered list (<code>&lt;ul&gt;</code>) and its <code>&lt;li&gt;</code> elements have position (relative, absolute, or fixed), the effect may not work properly in IE6 through at least IE9 unless the <code>&lt;ul&gt;</code> has "layout." To remedy the problem, add the <code>position: relative;</code> and <code>zoom: 1;</code> CSS declarations to the <code>ul</code>.
4242
</xsl:when>
43+
<xsl:when test="@id = 'html-code-execution'">
44+
By design, any jQuery constructor or method that accepts an HTML string — <a href="/jQuery/">jQuery()</a>, <a href="/append/">.append()</a>, <a href="/after/">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=""&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document.
45+
</xsl:when>
4346
</xsl:choose>
4447
</xsl:template>
4548
</xsl:stylesheet>

0 commit comments

Comments
 (0)