No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xep-0252.xml 12KB

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE xep SYSTEM 'xep.dtd' [
  3. <!ENTITY % ents SYSTEM 'xep.ent'>
  4. %ents;
  5. ]>
  6. <?xml-stylesheet type='text/xsl' href='xep.xsl'?>
  7. <xep>
  8. <header>
  9. <title>BOSH Script Syntax</title>
  10. <abstract>This specification provides historical documentation regarding the "alternative script syntax" first defined in Version 1.6 of XEP-0124.</abstract>
  12. <number>0252</number>
  13. <status>Deferred</status>
  14. <type>Historical</type>
  15. <sig>Standards</sig>
  16. <approver>Council</approver>
  17. <dependencies>
  18. <spec>XMPP Core</spec>
  19. <spec>XEP-0124</spec>
  20. </dependencies>
  21. <supersedes/>
  22. <supersededby/>
  23. <shortname>NOT_YET_ASSIGNED</shortname>
  24. &ianpaterson;
  25. <revision>
  26. <version>0.1</version>
  27. <date>2008-10-31</date>
  28. <initials>psa</initials>
  29. <remark><p>Initial published version.</p></remark>
  30. </revision>
  31. <revision>
  32. <version>0.0.1</version>
  33. <date>2008-08-14</date>
  34. <initials>ip</initials>
  35. <remark><p>Extracted from XEP-0124 version 1.6.</p></remark>
  36. </revision>
  37. </header>
  38. <section1 topic='Introduction' anchor='intro'>
  39. <p>The cross domain security restrictions of some runtime environments permit clients to access pure XML text only if it was received from a specific server (e.g., the hostname a Web client was downloaded from). Surprisingly, the same environments typically permit clients to receive and execute scripts from any server. The <link url="#security">Security Considerations</link> section below describes the significant risks of deploying Script Syntax.</p>
  40. <p>To enable domain-restricted clients to use BOSH with any connection manager, this section proposes an <em>optional</em> alternative to the standard "BOSH Pure Syntax" defined in &xep0124;. The "BOSH Script Syntax" defined here essentially inserts each &lt;body/&gt; element sent by the client into an HTTP GET header instead of into the body of a POST request. Each &lt;body/&gt; element sent by the connection manager is wrapped inside an &ecma262; string and function call. No changes to the &lt;body/&gt; element or to any other aspects of the BOSH protocol are needed.</p>
  41. <p>If, and only if, a client is <em>unable</em> to use the Pure Syntax defined in <cite>XEP-0124</cite>, then it MAY instead request the use of the Script Syntax defined herein.</p>
  42. </section1>
  43. <section1 topic='Script Syntax' anchor='syntax'>
  44. <section2 topic='Requesting Use of Script Syntax' anchor='syntax-request'>
  45. <p>A BOSH client can send a session request to a BOSH connection manager for using Script Syntax instead of Pure Syntax.</p>
  46. <p>If the connection manager supports Script Syntax then it MUST send its Session Creation Response using Script Syntax, and all subsequent client requests and connection manager responses within the session MUST be sent using Script Syntax. If the connection manager does not support the "BOSH Script" syntax then it SHOULD return either an 'item-not-found' terminal binding error (in Script Syntax) or an HTTP 404 (Not Found) error in response to the client's session request.</p>
  47. <p>Note: The line break in the body of the HTTP response in the following example is included only to improve readability. In practice there MUST be no line breaks.</p>
  48. <example caption="Script Syntax not supported binding error">
  49. <![CDATA[HTTP/1.1 200 OK
  50. Content-Type: text/javascript; charset=utf-8
  51. Cache-Control: no-store
  52. Cache-Control: no-cache
  53. Pragma: no-cache
  54. Content-Length: 212
  55. _BOSH_("<body type='terminate' condition='item-not-found'
  56. xmlns=''/>")
  57. ]]></example>
  58. <example caption="Script Syntax not supported HTTP error">
  59. <![CDATA[HTTP/1.1 404 Not Found
  60. Content-Length: 0]]></example>
  61. </section2>
  62. <section2 topic='Changes to the Request Syntax' anchor='script-request'>
  63. <p>Clients MUST make the following changes to convert their requests to Script Syntax:</p>
  64. <ol>
  65. <li><p>Certain octets within the UTF-8 encoded &lt;body/&gt; element SHOULD be replaced according to the rules for escaping octets within URIs defined by &rfc3986;. Therefore all octets except those representing 7-bit alphanumeric characters or the characters -._~!$&amp;'()*+,;=:@/? should be substituted with a character triplet, consisting of the percent character "%" followed by the two hexadecimal digits that represent the value of the octet.</p></li>
  66. <li><p>A '?' character and the URI-encoded &lt;body/&gt; element MUST be appended to the URI at which the connection manager is operating within its server.</p></li>
  67. <li><p>The resulting URI MUST be sent to the connection manager within an HTTP GET request.</p></li>
  68. <li><p>Include extra HTTP headers to prevent request/response caching or storage by any intermediary.</p></li>
  69. </ol>
  70. <p>Note: All whitespace between "GET " and " HTTP/1.1" in the HTTP GET header lines in the following two examples is included only to improve readability. In practice there MUST be no whitespace.</p>
  71. <example caption="Requesting a BOSH session in Script Syntax"><![CDATA[
  72. GET /webclient?%3Cbody%20content='text/xml;%20charset=utf-8'%20
  73. hold='1'%20rid='1573741820'%20to=''%20
  74. route=''%20secure='true'%20ver='1.6'%20
  75. wait='60'%20xml:lang='en'%20
  76. xmlns=''/%3E
  77. HTTP/1.1
  78. Host:
  79. Accept-Encoding: gzip, deflate
  80. Cache-Control: no-store
  81. Cache-Control: no-cache
  82. Pragma: no-cache
  83. Content-Length: 0]]></example>
  84. <example caption="Transmitting stanzas in Script Syntax"><![CDATA[
  85. GET /webclient?%3Cbody%20rid='1249243562'%20sid='SomeSID'%20
  86. xmlns=''%3E%3C
  87. message%20to=''%20xmlns='jabber:client'%3E%3C
  88. body%3EI%20said%20%22Hi!%22%3C/body%3E%3C/message%3E%3C/body%3E
  89. HTTP/1.1
  90. Host:
  91. Accept-Encoding: gzip, deflate
  92. Cache-Control: no-store
  93. Cache-Control: no-cache
  94. Pragma: no-cache
  95. Content-Length: 0
  96. ]]></example>
  97. <p>Although <cite>RFC 2616</cite> does not limit the length of HTTP URIs, the runtime environment of the client might restrict the length of the URI that it can include in each GET request. <note>Internet Explorer versions 4.0 thru 7.0 have a maximum <em>path</em> length of 2048 characters and a maximum URL length of 2083 characters. Other popular browsers appear to have no limit.</note> In these cases the client MUST reduce the content of the &lt;body/&gt; element accordingly and send the remaining content in subsequent HTTP GET requests wrapped in new &lt;body/&gt; elements (with incremented 'rid' attributes). This is possible since, unlike Pure Syntax, with Script Syntax the connection manager MUST treat the string of characters between the opening and closing &lt;body&gt; tags of each request as part of an octet stream instead of as a set of complete XML stanzas. The content of any one &lt;body/&gt; element MUST NOT be parsed in isolation from the rest of the stream.</p>
  98. </section2>
  99. <section2 topic='Changes to the Response Syntax' anchor='script-response'>
  100. <p>Connection managers MUST make the following changes to convert their responses to Script Syntax:</p>
  101. <p>1. Certain characters within the &lt;body/&gt; element MUST be replaced according to the rules for escaping characters within strings defined by <cite>ECMAScript</cite>. The necessary substitutions are summarised in the table below.</p>
  102. <table caption='Character Substitutions'>
  103. <tr><th>Character</th><th>Unicode Code Point Value</th><th>Escape sequence</th></tr>
  104. <tr><td>"</td><td>U+0022</td><td>\"</td></tr>
  105. <tr><td>Line Feed (New Line)</td><td>U+000A</td><td>\n</td></tr>
  106. <tr><td>Carriage Return</td><td>U+000D</td><td>\r</td></tr>
  107. <tr><td>Line Separator</td><td>U+2028</td><td>\u2028</td></tr>
  108. <tr><td>Paragraph Separator</td><td>U+2029</td><td>\u2029</td></tr>
  109. <tr><td>\</td><td>U+005C</td><td>\\</td></tr>
  110. </table>
  111. <p>Each Unicode format-control character (i.e., the characters in category "Cf" in the Unicode Character Database, e.g., LEFT-TO-RIGHT MARK or RIGHT-TO-LEFT MARK) MUST also be substituted by its Unicode escape sequence (e.g. \u200e or \u200f).</p>
  112. <p>2. The following eight characters MUST be prepended to the &lt;body/&gt; element:</p>
  113. <code>_BOSH_("</code>
  114. <p>3. The following two characters MUST be appended to the &lt;body/&gt; element:</p>
  115. <code>")</code>
  116. <p>4. If the client request does not possess a 'content' attribute, then the HTTP Content-Type header of responses MUST be either "text/javascript; charset=utf-8" or "application/x-javascript; charset=utf-8".</p>
  117. <p>5. Include extra HTTP headers to prevent caching or storage by any intermediary.</p>
  118. <p>Note: All line breaks in the bodies of the HTTP responses in the following two examples are included only to improve readability. In practice there MUST be no line breaks.</p>
  119. <example caption="Session creation response in Script Syntax">
  120. <![CDATA[HTTP/1.1 200 OK
  121. Content-Type: text/javascript; charset=utf-8
  122. Cache-Control: no-store
  123. Cache-Control: no-cache
  124. Pragma: no-cache
  125. Content-Length: 233
  126. _BOSH_("<body wait='60' inactivity='30' polling='5' requests='2' hold='1'
  127. ack='1573741820' accept='deflate,gzip' maxpause='120' sid='SomeSID'
  128. charsets='ISO_8859-1 ISO-2022-JP' ver='1.6' from=''
  129. secure='true' xmlns=''/>")
  130. ]]></example>
  131. <example caption="Receiving stanzas in Script Syntax">
  132. <![CDATA[HTTP/1.1 200 OK
  133. Content-Type: text/javascript; charset=utf-8
  134. Cache-Control: no-store
  135. Cache-Control: no-cache
  136. Pragma: no-cache
  137. Content-Length: 212
  138. _BOSH_("<body rid='1249243562' sid='SomeSID'
  139. xmlns=''>\n
  140. <message to='' xmlns='jabber:client'>\n
  141. <body>I said \"Hi!\"</body>\n</message>\n</body>")
  142. ]]></example>
  143. <p>Note: As with Pure Syntax, each &lt;body/&gt; element sent to the client MUST encapsulate zero or more complete XML stanzas.</p>
  144. </section2>
  145. </section1>
  146. <section1 topic='Error Handling' anchor='error'>
  147. <p>Any connection manager (not only legacy connection managers) can indicate that it does not support <link url="#script">Script Syntax</link> by sending an HTTP 404 error code (instead of sending a bad-request error using Scrypt Syntax).</p>
  148. <example caption="Script Syntax not supported error">
  149. <![CDATA[HTTP/1.1 404 Not Found
  150. Content-Length: 0
  151. ]]></example>
  152. </section1>
  153. <section1 topic='Security Consideration' anchor='security'>
  154. <p>To avoid the storage of private communications by third parties, when using the alternative Script Syntax connection managers MUST (and clients SHOULD) include all the appropriate HTTP/1.0 and/or HTTP/1.1 headers necessary to ensure as far as possible that no request or response will ever be cached or stored by any intermediary.</p>
  155. <p>The alternative Script Syntax returns code for the client to execute. This code is typically executed immediately without any validation and with the same rights as the code of the client itself. This vulnerability could be exploited to steal passwords and private keys, or to fabricate messages sent from and received by the client, or to forward or modify priviledged information on the servers to which the client has access, or to interfere with any aspect of the client's functionality -- limited only by the extent of the runtime environment ("sandbox"), by the extent that naive users can be tricked into doing things outside that environment, and by the attacker's fertile imagination. Therefore, although the client could use Script Syntax with any connection manager on the network, in practice it MUST take care to employ it only with connection managers that the client's user trusts (as much as the server from which the client was downloaded). To prevent a-man-in-the-middle from manipulating the code clients SHOULD only use Script Syntax over encrypted connections (see above). If the client was downloaded over an encrypted connection then it MUST NOT use Script Syntax over connections that are not encrypted.</p>
  156. </section1>
  157. </xep>