Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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>Packet Filtering</title>
  10. <abstract>A framework for packet filtering rules.</abstract>
  11. &LEGALNOTICE;
  12. <number>0062</number>
  13. <status>Deferred</status>
  14. <type>Informational</type>
  15. <sig>Standards</sig>
  16. <dependencies>
  17. <spec>XMPP Core</spec>
  18. <spec>XEP-0030</spec>
  19. </dependencies>
  20. <supersedes/>
  21. <supersededby/>
  22. <shortname>Not yet assigned</shortname>
  23. <author>
  24. <firstname>Robert</firstname>
  25. <surname>Norris</surname>
  26. <email>rob@cataclysm.cx</email>
  27. <jid>rob@cataclysm.cx</jid>
  28. </author>
  29. <revision>
  30. <version>0.2</version>
  31. <date>2003-09-30</date>
  32. <initials>psa</initials>
  33. <remark>At the request of the author, changed the status of this document to Deferred pending development of an implementation; also changed the type to Informational.</remark>
  34. </revision>
  35. <revision>
  36. <version>0.1</version>
  37. <date>2002-12-05</date>
  38. <initials>rn</initials>
  39. <remark>Initial version.</remark>
  40. </revision>
  41. </header>
  42. <section1 topic='Introduction'>
  43. <p>Traditionally, the &jabberd; server included an internal server module called "mod_filter", which provided a packet filtering facility for users. That service had the following problems:</p>
  44. <ul>
  45. <li>The service and protocol were undocumented, apart from some documentation reverse-engineered from the source code.</li>
  46. <li>The processing requirements that the service required made it unusable for large installations.</li>
  47. <li>Bugs in the service often caused the Jabber server to crash.</li>
  48. </ul>
  49. <p>The most common use for this service was to provide server-side blacklists. Unforuntately, mod_filter was overpowered even by this relatively simple form of packet filtering (matching the sending JID and dropping the packet if necessary), so this need has been neatly filled by &xep0016;.</p>
  50. <p>However, packet filtering (as opposed to the subset of JID blacklisting) is still of use, for the following tasks:</p>
  51. <ul>
  52. <li>Setting up automatic responses to messages (e.g., "vacation" messages).</li>
  53. <li>Redirecting packets to another JID.</li>
  54. <li>Modifying the contents of a packet in-transit (e.g., language translation, adding &lt;x/&gt; data).</li>
  55. <li>Force incoming messages to be stored offline (e.g., for low-bandwidth clients).</li>
  56. </ul>
  57. <p>This document proposes a modular, extensible framework for specifying packet filtering rules. This document does not, however, propose any specific filter conditions or actions - that is left to other proposals.</p>
  58. <p>The framework itself operates in the "http://jabber.org/protocol/filter" namespace.</p>
  59. <section2 topic='Definitions'>
  60. <p>The following definitions are used throughout this document:</p>
  61. <ul>
  62. <li>ruleset - a set of filtering rules.</li>
  63. <li>rule - a set of conditions with an associated action.</li>
  64. <li>condition - an expression (or set of expressions) that, when applied to a packet, is either true or false.</li>
  65. <li>action - a task that may be performed on a packet.</li>
  66. </ul>
  67. </section2>
  68. </section1>
  69. <section1 topic='Structure'>
  70. <p>A single rule is be expressed in XML like so:</p>
  71. <example caption='XML representation of a rule'><![CDATA[
  72. <rule description='natural-language description of rule'>
  73. <condition>[conditionexpr]</condition>
  74. <action>[actionspec]</action>
  75. </rule>
  76. ]]></example>
  77. <p>A rule is processed by applying its condition to the packet. If the condition is true, then the action is taken. The "description" attribute is provided so a rule generator can assign a meaningful and user-readable description of a rule.</p>
  78. <p>A ruleset is be expressed in XML like so:</p>
  79. <example caption='XML representation of a ruleset'><![CDATA[
  80. <ruleset>
  81. <rule description='rule description'>
  82. <condition>[conditionexpr]</condition>
  83. <action>[actionspec]</action>
  84. </rule>
  85. <rule description='rule description'>
  86. <condition>[conditionexpr]</condition>
  87. <action>[actionspec]</action>
  88. </rule>
  89. <rule description='rule description'>
  90. <condition>[conditionexpr]</condition>
  91. <action>[actionspec]</action>
  92. </rule>
  93. </ruleset>
  94. ]]></example>
  95. <p>A ruleset is processed by applying each rule to the packet, one at a time. Processing of the ruleset stops after the first matching rule is found and its action taken, <em>unless</em> the "continue" attribute is found on the matched rule, in which case the remaining rules get processed as though the current rule did not match. If no rules match, packet processing continues as though no rules were specified.</p>
  96. <p>If the &lt;condition/> element contains no condition expression, then the rule matches all packets.</p>
  97. <p>A ruleset does not have to contain any rules:</p>
  98. <example caption='Empty ruleset'><![CDATA[
  99. <ruleset/>
  100. ]]></example>
  101. <p>Conditions may be aggregated using AND or OR modifiers, like so:</p>
  102. <example caption='Aggregated condition'><![CDATA[
  103. <condition>
  104. <and>
  105. [conditionexpr1]
  106. [conditionexpr2]
  107. <or>
  108. [conditionexpr3]
  109. [conditionexpr4]
  110. </or>
  111. </and>
  112. </condition>
  113. ]]></example>
  114. <p>The above example is equivalent to "conditionexpr1 AND conditionexpr2 AND (conditionexpr3 OR conditionexpr4)".</p>
  115. <p>No such aggregation exists for actions - only a single action expression may be included within an &lt;action/> element.</p>
  116. </section1>
  117. <section1 topic='Filter modules'>
  118. <p>A filter module is a document that defines conditions and/or actions that can be use by this framework. Each module should have its own namespace, and should clearly define the effect of each condition and action it defines.</p>
  119. <p>Consider a hypothetical module that defines conditions that match packets based on their header information. It might use the namespace "http://jabber.org/protocol/filter/header" and might define the following conditions:</p>
  120. <ul>
  121. <li>&lt;to/> - true when the CDATA of this element matches the "to" attribute of the packet.</li>
  122. <li>&lt;from/> - true when the CDATA of this element matches the "from" attribute of the packet.</li>
  123. <li>&lt;type/> - true when the CDATA of this element matches the "type" attribute of the packet.</li>
  124. </ul>
  125. <p>Equally, consider a hypothetical module that defines actions for redirecting messages. It might use the namespace "http://jabber.org/protocol/filter/redirect" and might define the following conditions:</p>
  126. <ul>
  127. <li>&lt;redirect/> - redirects the packet to the JID specified in the CDATA of this element.</li>
  128. <li>&lt;copy/> - sends a copy of the packet to the JID specified in the CDATA of this element, while giving the original packet to the user.</li>
  129. </ul>
  130. <p>These two modules might be combined to produce a ruleset like the following:</p>
  131. <example caption='Using modules in a ruleset'><![CDATA[
  132. <ruleset>
  133. <rule description='Send messages from my friend to my home account to be dealt with later'>
  134. <condition>
  135. <from xmlns='http://jabber.org/protocol/filter/header'>friend@theirisp.com</from>
  136. </condition>
  137. <action>
  138. <redirect xmlns='http://jabber.org/protocol/filter/redirect'>me@home.com</redirect>
  139. </action>
  140. </rule>
  141. </ruleset>
  142. ]]></example>
  143. <p>Using modules in this way enables this framework to be easily extended to support new types of filtering, as well as enabling site administrators to select the types of functionallity that are best suited to their site.</p>
  144. </section1>
  145. <section1 topic='Protocol'>
  146. <p>It will not always be appropriate for a service to provide a Jabber-based interface to its filter settings (e.g., in the case of an XML router, it will almost always be more appropriate to limit the specification of rules and rulesets to the router configuration). However, this will be appropriate sometimes (e.g., a session manager providing per-user packet filtering). In these cases, the following protocol should be used.
  147. </p>
  148. <section2 topic='Module discovery'>
  149. <p>An entity may find out if a service supports filtering, and the modules its supports, by issuing a discovery request to the service:</p>
  150. <example caption='Module discovery'><![CDATA[
  151. <iq type='get' to='jabber.org' 'disco1'>
  152. <query xmlns='http://jabber.org/protocol/disco#info'/>
  153. </iq>
  154. ]]> </example>
  155. <example caption='Module discovery response'><![CDATA[
  156. <iq type='result' to='jabber.org' id='disco1'>
  157. <query xmlns='http://jabber.org/protocol/disco#info'>
  158. <identity category='server' type='jabber' name='Jabber server'/>
  159. <feature var='http://jabber.org/protocol/filter'/>
  160. <feature var='http://jabber.org/protocol/filter/header'/>
  161. <feature var='http://jabber.org/protocol/filter/redirect'/>
  162. <feature var='...'/>
  163. </query>
  164. </iq>
  165. ]]> </example>
  166. </section2>
  167. <section2 topic='Setting the ruleset'>
  168. <p>An entity may set the filter ruleset for an entity (which may be itself) like so:</p>
  169. <example caption='Setting the ruleset'><![CDATA[
  170. <iq type='set' to='rob@cataclysm.cx' id='filter1'>
  171. <ruleset xmlns='http://jabber.org/protocol/filter'>
  172. <rule description='Send messages from my friend to my home account to be dealt with later'>
  173. <condition>
  174. <from xmlns='http://jabber.org/protocol/filter/header'>friend@theirisp.com</from>
  175. </condition>
  176. <action>
  177. <redirect xmlns='http://jabber.org/protocol/filter/redirect'>me@home.com</redirect>
  178. </action>
  179. </rule>
  180. <rule description='Copy messages from this spammer to our abuse address'>
  181. <condition>
  182. <from xmlns='http://jabber.org/protocol/filter/header'>spammer@badsite.com</from>
  183. </condition>
  184. <action>
  185. <copy xmlns='http://jabber.org/protocol/filter/redirect'>abuse@company.com</redirect>
  186. </action>
  187. </rule>
  188. </ruleset>
  189. </iq>
  190. ]]> </example>
  191. <p>On success, the service returns:</p>
  192. <example caption='Setting the ruleset result'><![CDATA[
  193. <iq type='result' from='rob@cataclysm.cx' id='filter1'/>
  194. ]]> </example>
  195. <p>On error, the server returns the original packet with an appropriate error:</p>
  196. <example caption='Setting the ruleset failure'><![CDATA[
  197. <iq type='error' to='rob@cataclysm.cx' id='filter1'>
  198. <ruleset xmlns='http://jabber.org/protocol/filter'>
  199. <rule description='Send messages from my friend to my home account to be dealt with later'>
  200. <condition>
  201. <from xmlns='http://jabber.org/protocol/filter/header'>friend@theirisp.com</from>
  202. </condition>
  203. <action>
  204. <redirect xmlns='http://jabber.org/protocol/filter/redirect'>me@home.com</redirect>
  205. </action>
  206. </rule>
  207. <rule description='Copy messages from this spammer to our abuse address'>
  208. <condition>
  209. <from xmlns='http://jabber.org/protocol/filter/header'>spammer@badsite.com</from>
  210. </condition>
  211. <action>
  212. <copy xmlns='http://jabber.org/protocol/filter/redirect'>abuse@company.com</redirect>
  213. </action>
  214. </rule>
  215. </ruleset>
  216. <error code='403'>Forbidden</error>
  217. </iq>
  218. ]]> </example>
  219. </section2>
  220. <section2 topic='Retrieving the ruleset'>
  221. <p>An entity may retrieve the filter ruleset for an entity (which may be itself) like so:</p>
  222. <example caption='Requesting the ruleset'><![CDATA[
  223. <iq type='get' id='filter2'>
  224. <ruleset xmlns='http://jabber.org/protocol/filter'/>
  225. </iq>
  226. ]]> </example>
  227. <p>If the requesting entity has permissions to view the ruleset, the server must return the ruleset to the entity:</p>
  228. <example caption='Retrieving the ruleset result'><![CDATA[
  229. <iq type='error' to='rob@cataclysm.cx' id='filter2'>
  230. <ruleset xmlns='http://jabber.org/protocol/filter'>
  231. <rule description='Send messages from my friend to my home account to be dealt with later'>
  232. <condition>
  233. <from xmlns='http://jabber.org/protocol/filter/header'>friend@theirisp.com</from>
  234. </condition>
  235. <action>
  236. <redirect xmlns='http://jabber.org/protocol/filter/redirect'>me@home.com</redirect>
  237. </action>
  238. </rule>
  239. <rule description='Copy messages from this spammer to our abuse address'>
  240. <condition>
  241. <from xmlns='http://jabber.org/protocol/filter/header'>spammer@badsite.com</from>
  242. </condition>
  243. <action>
  244. <copy xmlns='http://jabber.org/protocol/filter/redirect'>abuse@company.com</redirect>
  245. </action>
  246. </rule>
  247. </ruleset>
  248. </iq>
  249. ]]> </example>
  250. <p>On error, the server returns the original packet with an appropriate error:</p>
  251. <example caption='Retrieving the ruleset failure'><![CDATA[
  252. <iq type='error' to='rob@cataclysm.cx' id='filter2'>
  253. <ruleset xmlns='http://jabber.org/protocol/filter'/>
  254. <error code='403'>Forbidden</error>
  255. </iq>
  256. ]]> </example>
  257. </section2>
  258. </section1>
  259. <section1 topic='Error Codes'>
  260. <p>Possible errors are:</p>
  261. <table caption='Errors returned when retrieving the ruleset'>
  262. <tr>
  263. <th>Code</th><th>Text</th><th>Description</th>
  264. </tr>
  265. <tr>
  266. <td>403</td><td>Forbidden</td><td>The sender does not have permission to modify the ruleset for this entity.</td>
  267. </tr>
  268. <tr>
  269. <td>404</td><td>Not Found</td><td>The entity does not exist.</td>
  270. </tr>
  271. </table>
  272. </section1>
  273. <section1 topic='Implementation notes'>
  274. <p>Ruleset processing should be the first thing that a service does when it receives a packet - even before processing privacy rules per XEP-0016.</p>
  275. <p>Rules must be processed in the order they are given, and must be returned to a requesting entity in the same order.</p>
  276. </section1>
  277. <section1 topic='Security Considerations'>
  278. <p>There are no security features or concerns related to this proposal.</p>
  279. </section1>
  280. <section1 topic='IANA Considerations'>
  281. <p>This document requires no interaction with the IANA.</p>
  282. </section1>
  283. <section1 topic='JANA Considerations'>
  284. <p>No namespaces or parameters need to be registered with JANA as a result of this document.</p>
  285. </section1>
  286. </xep>