Mike Samuel wrote: > 2009/2/16 David-Sarah Hopwood <[email protected]> > >> [email protected] wrote: >>> Issue 17063 http://codereview.appspot.com/17063 >>> Issue 967: embedded rendering mode should parenthesize post-decrement >>> inside comparisons >>> >>> The code >>> x-- > 3 >>> is valid javascript. >>> >>> HTML 4 says of the grammar for comments: >>> White space is not permitted between the markup declaration open >>> delimiter("<!") and the comment open delimiter ("--"), but is >>> permitted between the comment close delimiter ("--") and the >>> markup declaration close delimiter (">"). >>> >>> So the -- > in the javascript snippet above could end an HTML comment, >> thus >>> defeating embedded mode guarantees. This can be solved by rendering it >> as >>> (x--) > 3. >>> >>> This has to be done for post-decrement ops as the left hand argument to >>> the following operators >, >=, >>, >>>, >>=, >>>=. >>> >>> This may be a security issue if clients use embedding and browsers >>> implement escaping text spans using the same grammar as HTML4 comments. >>> >>> HTML5 has a tighter syntax for comments, and so a strict HTML5 parser >>> would not lose embedding. >> >> I don't understand this issue.
I now understand it: it doesn't really matter what either HTML4 or HTML5 specify, because browsers ignore both specs and do their own thing. >> My reading of the HTML4 spec suggests that >> HTML comment delimiters are not supposed to be interpreted at all inside a >> <script> tag, and testing in IE7 and Firefox seems to be consistent with >> that. Embedded mode is only for embedding code in a <script> tag, isn't it? > > What do you mean by comment delimiters being interpreted? A comment delimiter is '<!--', or '--' WhiteSpace* '>'. I meant that HTML4 specifies no special behaviour for comment delimiters in a <script> (or <style>) tag, which means that they should be "treated as raw text and passed to the application as is": # Although the STYLE and SCRIPT elements use CDATA for their data model, # for these elements, CDATA must be handled differently by user agents. # Markup and entities must be treated as raw text and passed to the # application as is. The first occurrence of the character sequence "</" # (end-tag open delimiter) is treated as terminating the end of the # element's content. In valid documents, this would be the end tag for # the element. HTML5, on the other hand, specifies that escaping text spans should be ignored (deleted from the script content), as you point out. It is impossible for a browser to be compliant with both of these specifications. Sure enough, Firefox 3 and IE7 are not compliant with either of them. What these browsers seem to do is to treat escaping text spans in a <script> as "raw text" when they occur within a JavaScript string or regexp literal, but delete them when they occur elsewhere. So, Caja and other secure subsets must conservatively assume that "<!--" in a <script> tag *might* start an escaping text span. However, there does not appear to be any way to reliably escape an occurrence of "<!--" using HTML escaping. That means it has to be escaped using \u, if it occurs in a string/regexp literal, or by inserting whitespace or parentheses otherwise. (I haven't tried to test what browsers do about escaping text spans in <style> tags, but it's likely to be similar.) -- David-Sarah Hopwood ⚥
