1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-26 19:22:15 -05:00
xeps/xep-0363.xml

443 lines
22 KiB
XML
Raw Normal View History

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
<!ENTITY % ents SYSTEM 'xep.ent'>
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
<header>
<title>HTTP File Upload</title>
<abstract>This specification defines a protocol to request permissions from another entity to upload a file to a specific path on an HTTP server and at the same time receive a URL from which that file can later be downloaded again.</abstract>
&LEGALNOTICE;
<number>0363</number>
2020-02-11 10:32:21 -05:00
<status>Draft</status>
<lastcall>2020-01-28</lastcall>
2019-01-08 10:54:13 -05:00
<lastcall>2019-01-22</lastcall>
<lastcall>2018-06-18</lastcall>
2017-11-29 13:27:22 -05:00
<lastcall>2017-12-12</lastcall>
<type>Standards Track</type>
<sig>Standards</sig>
<approver>Council</approver>
<dependencies>
<spec>XMPP Core</spec>
<spec>XEP-0030</spec>
<spec>XEP-0128</spec>
</dependencies>
<supersedes/>
<supersededby/>
<shortname>NOT_YET_ASSIGNED</shortname>
<author>
<firstname>Daniel</firstname>
<surname>Gultsch</surname>
<email>daniel@gultsch.de</email>
<jid>daniel@gultsch.de</jid>
</author>
2020-02-11 10:32:21 -05:00
<revision>
<version>1.0.0</version>
<date>2020-02-11</date>
<initials>XEP Editor (jsc)</initials>
<remark>Accepted as Draft standard by the XMPP Council. Voted on 2020-01-29.</remark>
</revision>
<revision>
<version>0.10.0</version>
<date>2020-01-20</date>
<initials>dg</initials>
<remark>
<ul>
<li>Remove statement about access control from Requirements. (Statement about long randomized file names had been moved to Security Considerations earlier.)</li>
<li>Add section about IP address leak to Security Considerations.</li>
</ul>
</remark>
</revision>
<revision>
<version>0.9.0</version>
<date>2018-12-18</date>
<initials>dg</initials>
<remark>
<ul>
<li>Divided Security Considerations into multiple sub sections and added information about properly isolating the HTTP Upload service</li>
<li>Added schema</li>
<li>Added example for CORS header</li>
</ul>
</remark>
</revision>
<revision>
<version>0.8.0</version>
<date>2018-12-10</date>
<initials>dg</initials>
<remark>
<ul>
<li>Added implementation notes regarding CORS headers for use of HTTP Upload in web clients.</li>
<li>Increase recommended timeout value for PUT URLs to better suit mobile connections</li>
</ul>
</remark>
</revision>
2018-05-30 03:00:08 -04:00
<revision>
<version>0.7.0</version>
<date>2018-05-30</date>
<initials>dg</initials>
<remark>
<ul>
<li>Changed not-allowed error to forbidden as this is more appropriate according to &rfc6120;</li>
</ul>
</remark>
</revision>
<revision>
<version>0.6.0</version>
<date>2018-04-21</date>
<initials>dg</initials>
<remark>
<ul>
<li>Handling of non ASCII characters in URL</li>
<li>Removed normative language from first paragraph of the security considerations.</li>
</ul>
</remark>
</revision>
<revision>
<version>0.5.0</version>
<date>2018-02-15</date>
<initials>dg</initials>
<remark>
<ul>
<li>Allow only a specific set of HTTP headers to be included in the request</li>
<li>Removed some inappropriate use of normative language</li>
</ul>
</remark>
</revision>
<revision>
<version>0.4.0</version>
<date>2017-12-03</date>
<initials>dg</initials>
<remark>
<ul>
<li>Added &lt;retry/&gt; element to error response</li>
<li>Extend Security Considerations</li>
</ul>
</remark>
</revision>
<revision>
<version>0.3.1</version>
<date>2017-04-21</date>
<initials>dg</initials>
<remark><p>Fixed example</p></remark>
</revision>
<revision>
<version>0.3.0</version>
<date>2017-02-01</date>
<initials>dg</initials>
<remark><p>Slight syntax changes and added ability to provide additional HTTP header fields on slot assignment.</p></remark>
</revision>
<revision>
<version>0.2.5</version>
<date>2017-01-08</date>
<initials>XEP Editor: ssw</initials>
<remark><p>Merge typo fixes suggested by an unnamed user.</p></remark>
</revision>
2016-10-28 15:06:40 -04:00
<revision>
<version>0.2.4</version>
<date>2016-10-28</date>
<initials>dg (XEP Editor: ssw)</initials>
<remark><p>Fix TLS reference</p></remark>
</revision>
<revision>
<version>0.2.3</version>
<date>2016-07-11</date>
<initials>wjt (XEP Editor: ssw)</initials>
<remark><p>Typo fixes</p></remark>
</revision>
<revision>
<version>0.2.2</version>
<date>2016-03-30</date>
<initials>ssw</initials>
<remark><p>Typo fix</p></remark>
</revision>
2016-03-16 10:26:36 -04:00
<revision>
<version>0.2.1</version>
<date>2016-03-16</date>
<initials>XEP Editor (ssw)</initials>
<remark><p>Minor dependency and citation fixes (fs).</p></remark>
</revision>
<revision>
<version>0.2</version>
<date>2016-03-07</date>
<initials>dg</initials>
<remark><p>Announce maximum file size by means of &xep0128;</p></remark>
</revision>
2016-02-16 13:20:42 -05:00
<revision>
<version>0.1.2</version>
<date>2016-02-16</date>
<initials>XEP Editor (mam)</initials>
<remark><p>Fix typo of discovery (Philipp Hancke).</p></remark>
</revision>
<revision>
<version>0.1.1</version>
<date>2016-01-05</date>
<initials>XEP Editor (ssw)</initials>
<remark><p>Fix invalid XML in examples (tpa).</p></remark>
</revision>
<revision>
<version>0.1</version>
<date>2015-08-27</date>
<initials>XEP Editor (mam)</initials>
<remark><p>Initial published version approved by the XMPP Council.</p></remark>
</revision>
<revision>
<version>0.0.1</version>
<date>2015-07-25</date>
<initials>dg</initials>
<remark><p>First draft.</p></remark>
</revision>
</header>
<section1 topic='Introduction' anchor='intro'>
2016-06-03 11:51:43 -04:00
<p>XMPP protocol extensions already define methods for peer-to-peer file transfer such as &xep0096; or &xep0234; however due to their very nature of being peer-to-peer they don't work very well in scenarios where it is requeried to send a file to multiple recipients or multiple resources of the same recipient at once. They also dont work alongside offline storage, MUC history and &xep0313;.</p>
<p>Uploading files manually to an HTTP server and sharing the link has been a workaround for this for a long time now. While users have a variety of services to choose from the downside of this manual approach is that an XMPP client can not automate this process on behalf of the user since these services dont share a common API. Furthermore using a third party service would probably require the user to enter additional credentials into their XMPP client specifically for the file upload.</p>
<p>This XEP defines an approach to request permissions from another entity to upload a file to a specific path on an HTTP server and at the same time receive an URL from which that file can later be downloaded again. These tuples consisting of a PUT and a GET-URL are called slots.</p>
</section1>
<section1 topic='Requirements' anchor='reqs'>
<ul>
<li>Be as easy to implement as possible. This is grounded on the idea that most programming languages already have HTTP libraries available.</li>
<li>Be agnostic toward the distribution of the actual URL. Users can choose to send the URL in the body of a message stanza, utilize &xep0066;, &xep0370;, or even use it as their avatar in &xep0084;.</li>
<li>Anyone who knows the URL SHOULD be able to access it.</li>
</ul>
</section1>
<section1 topic='Discovering Support' anchor='disco'>
<p>An entity advertises support for this protocol by including the "urn:xmpp:http:upload:0" in its service discovery information features as specified in &xep0030; or section 6.3 of &xep0115;. To avoid unnecessary round trips an entity SHOULD also include the maximum file size as specified in &xep0128; if such a limitation exists. The field name MUST be "max-file-size" and the value MUST be in bytes.</p>
<p>A users server SHOULD include any known entities that provide such services into its service discovery items.</p>
<example caption='Client sends service discovery request to server'><![CDATA[
<iq from='romeo@montague.tld/garden'
id='step_01'
to='montague.tld'
type='get'>
<query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>]]></example>
<example caption='Server replies to service discovery request'><![CDATA[
<iq from='montague.tld'
id='step_01'
to='romeo@montague.tld/garden'
type='result'>
<query xmlns='http://jabber.org/protocol/disco#items'>
<item jid='upload.montague.tld' name='HTTP File Upload' />
<item jid='conference.montague.tld' name='Chatroom Service' />
</query>
</iq>]]></example>
2016-02-15 14:36:44 -05:00
<example caption='Client sends service discovery request to upload service'><![CDATA[
<iq from='romeo@montague.tld/garden'
id='step_02'
to='upload.montague.tld'
type='get'>
<query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>]]></example>
<example caption='Upload service replies to service discovery request and reports a maximum file size of 5MiB'><![CDATA[
<iq from='upload.montague.tld'
id='step_02'
to='romeo@montague.tld/garden'
type='result'>
<query xmlns='http://jabber.org/protocol/disco#info'>
<identity category='store'
type='file'
name='HTTP File Upload' />
<feature var='urn:xmpp:http:upload:0' />
<x type='result' xmlns='jabber:x:data'>
<field var='FORM_TYPE' type='hidden'>
<value>urn:xmpp:http:upload:0</value>
</field>
<field var='max-file-size'>
<value>5242880</value>
</field>
</x>
</query>
</iq>]]></example>
</section1>
<section1 topic='Requesting a slot' anchor='request'>
<p>A client requests a new upload slot by sending an IQ-get to the upload service containing a &lt;request&gt; child element qualified by the urn:xmpp:http:upload:0 namespace. This element MUST include the attributes filename and size containing the file name and size respectively.</p>
<p>An additional attribute content-type containing the Content-Type is OPTIONAL.</p>
<example caption='Client requests a slot on the upload service'><![CDATA[
<iq from='romeo@montague.tld/garden'
id='step_03'
to='upload.montague.tld'
type='get'>
<request xmlns='urn:xmpp:http:upload:0'
filename='très cool.jpg'
size='23456'
content-type='image/jpeg' />
</iq>]]></example>
<p>The upload service responds with both a PUT and a GET URL wrapped by a &lt;slot&gt; element. The service SHOULD keep the file name and especially the file ending intact. Using the same hostname for PUT and GET is OPTIONAL. The host MUST provide Transport Layer Security (&rfc5246;). Both HTTPS URLs MUST adhere to &rfc3986;. Non ASCII characters MUST be percent-encoded.</p>
<p>The &lt;put&gt; element MAY also contain a number of &lt;header&gt; elements which correspond to HTTP header fields. Each &lt;header&gt; element MUST have a name-attribute and a content with the value of the header. Only the following header names are allowed: Authorization, Cookie, Expires. Other header names MUST be ignored by the requesting entity and MUST NOT be included in the HTTP request. The requesting entity MUST strip any newline characters from the header name and value before performing the HTTP request.</p>
<example caption='The upload service responds with a slot'><![CDATA[
<iq from='upload.montague.tld'
id='step_03'
to='romeo@montague.tld/garden'
type='result'>
<slot xmlns='urn:xmpp:http:upload:0'>
<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg'>
<header name='Authorization'>Basic Base64String==</header>
<header name='Cookie'>foo=bar; user=romeo</header>
</put>
<get url='https://download.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg' />
</slot>
</iq>]]></example>
</section1>
<section1 topic='Error conditions' anchor='errors'>
2018-05-30 03:00:08 -04:00
<p>Instead of providing the client with a slot the service MAY respond with an error if the requested file size is too large. In addition the entity MAY inform the requester about the maximum file size.</p>
<example caption='Alternative response by the upload service if the file size was too large'><![CDATA[
<iq from='upload.montague.tld'
id='step_03'
to='romeo@montague.tld/garden'
type='error'>
<request xmlns='urn:xmpp:http:upload:0'
filename='très cool.jpg'
size='23456'
content-type='image/jpeg' />
<error type='modify'>
<not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' />
<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>File too large. The maximum file size is 20000 bytes</text>
<file-too-large xmlns='urn:xmpp:http:upload:0'>
<max-file-size>20000</max-file-size>
</file-too-large>
</error>
</iq>]]></example>
<p>For any other type of error the service SHOULD respond with appropriate error types to indicate temporary or permanent errors.</p>
<p>For temporary errors such as exceeding a personal quota the service MAY include a &lt;retry/&gt; element qualified by the urn:xmpp:http:upload:0 namespace as a child of the &lt;error/&gt; element. The retry element MUST include an attribute 'stamp' which indicates the time at which the requesting entity may try again. The format of the timestamp MUST adhere to the date-time format specified in &xep0082; and MUST be expressed in UTC.</p>
<example caption='Alternative response by the upload service to indicate a temporary error after the client exceeded a quota'><![CDATA[
<iq from='upload.montague.tld'
id='step_03'
to='romeo@montague.tld/garden'
type='error'>
<request xmlns='urn:xmpp:http:upload:0'
filename='très cool.jpg'
size='23456'
content-type='image/jpeg' />
<error type='wait'>
<resource-constraint xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' />
<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Quota reached. You can only upload 5 files in 5 minutes</text>
<retry xmlns='urn:xmpp:http:upload:0'
stamp='2017-12-03T23:42:05Z' />
</error>
</iq>]]></example>
2018-05-30 03:00:08 -04:00
<example caption='Alternative response by the upload service to indicate an auth error to a client that is not allowed to upload files'><![CDATA[
<iq from='upload.montague.tld'
id='step_03'
to='romeo@montague.tld/garden'
type='error'>
<request xmlns='urn:xmpp:http:upload:0'
filename='très cool.jpg'
size='23456'
content-type='image/jpeg' />
2018-05-30 03:00:08 -04:00
<error type='auth'>
<forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' />
<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Only premium members are allowed to upload files</text>
</error>
</iq>]]></example>
</section1>
<section1 topic='Upload' anchor='upload'>
2016-06-03 11:51:43 -04:00
<p>The actual upload of the file happens via HTTP-PUT and is out of scope of this document. The upload service MUST reject the file upload if the Content-Length does not match the size of the slot request. The service SHOULD reject the file if the Content-Type has been specified beforehand and does not match. The service MAY assume application/octet-stream as a Content-Type if it the client did not specify a Content-Type at all.</p>
<p>In addition to the Content-Length and Content-Type header the client MUST include all allowed headers that came with the slot assignment.</p>
<p>There is no further XMPP communication required between the upload service and the client. A HTTP status Code of 201 means that the server is now ready to serve the file via the provided GET URL. If the upload fails for whatever reasons the client MAY request a new slot.</p>
</section1>
<section1 topic='Implementation Notes' anchor='impl'>
<p>The upload service SHOULD choose an appropriate timeout for the validity of the PUT URL. Since there is no reason for a client to wait between requesting the slot and starting the upload, relatively low timeout values of around 300s are RECOMMENDED.</p>
<p>To make HTTP Upload work in web clients (including those hosted on a different domain) the upload service SHOULD set appropriate <link url="https://www.w3.org/TR/cors/">CORS</link>-Headers. The exact headers and values are out of scope of this document but may include: <em>Access-Control-Allow-Origin</em>, <em>Access-Control-Allow-Methods</em> and <em>Access-Control-Allow-Headers</em>. For HTTP upload services that use custom <em>Authorization</em> or <em>Cookie</em> request header the CORS-Header <em>Access-Control-Allow-Credentials</em> might also be of importance.</p>
<code caption="Example for loose CORS Header"><![CDATA[
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: OPTIONS, HEAD, GET, PUT
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Allow-Credentials: true
]]></code>
</section1>
<section1 topic='Security Considerations' anchor='security'>
<section2 topic="Server side" anchor="server">
<p><strong>Note: This section is not normative; it may be updated when general web security recommendations change in the future.</strong></p>
<p>It is recommended to run the HTTP upload domain used for GET requests in appropriate isolation from other HTTP based services to avoid user-generated, malicious scripts to be executed in the context of said services. Isolation techniques can include, but are not limited to, setting the <em>Content-Security-Policy</em>.</p>
<code caption="HTTP Upload Server Headers for better Content Security Policy"><![CDATA[
Content-Security-Policy: default-src 'none'; frame-ancestors 'none';
]]></code>
<p>The provided policy will prohibit a browser from executing all active content from the HTTP upload domain (<em>default-src 'none'</em>) and forbid embedding it from other pages (<em>frame-ancestors 'none'</em>). More information on Content-Security-Policy can be found on <link url="https://infosec.mozilla.org/guidelines/web_security#content-security-policy">infosec.mozilla.org</link>.</p>
<p>Further isolation can be achieved by hosting those files on an entirely different domain instead of using subdomains.</p>
</section2>
<section2 topic="Uploader" anchor="uploader">
<ul>
<li>Requesting entities MUST strip any newline characters from the HTTP header names and values before making the PUT request.</li>
<li>Requesting entities MUST ensure that only the headers that are explicitly allowed by this XEP (Authorization, Cookie, Expires) are copied from the slot response to the HTTP request.</li>
</ul>
</section2>
<section2 topic="General" anchor="general">
<ul>
<li>Service implementors SHOULD use long randomized parts in their URLs making it impossible to guess the location of arbitrary files.</li>
<li>Implementors should keep in mind, that without additional end-to-end-encryption, files uploaded to a service described in this document may be stored in plain text. Client implementors are advised to either use this only for semi public files (for example files shared in a public MUC or a PEP Avatar) or implement appropriate end-to-end encryption.</li>
<li>Up- and downloading files will leak the clients IP address to the HTTP service. The HTTP service might not be the same service as the XMPP service the client is currently connected to.</li>
</ul>
</section2>
</section1>
<section1 topic='IANA Considerations' anchor='iana'>
<p>This document requires no interaction with the Internet Assigned Numbers Authority (IANA).</p>
</section1>
<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
<section2 topic='Protocol Namespaces' anchor='registrar-ns'>
<p>This specification defines the following XML namespace:</p>
<ul>
<li>urn:xmpp:http:upload:0</li>
</ul>
<p>Upon advancement of this specification from a status of Experimental to a status of Draft, the &REGISTRAR; shall add the foregoing namespace to the registry located at &NAMESPACES;, as described in Section 4 of &xep0053;.</p>
</section2>
</section1>
<section1 topic='XML Schema' anchor='schema'>
<code><![CDATA[
<xml version="1.0" encoding="utf8">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:xmpp:http:upload:0"
xmlns="urn:xmpp:http:upload:0">
<xs:element name="request">
<xs:complexType>
<xs:attribute name="filename" type="xs:string" use="required"/>
<xs:attribute name="size" type="xs:positiveInteger" use="required"/>
<xs:attribute name="content-type" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="slot">
<xs:complexType>
<xs:sequence>
<xs:element name="put" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:attribute name="url" type="xs:string" use="required"/>
<xs:sequence>
<xs:element name="header" minOccurs="0" maxOccurs="unbounded" type="xs:string">
<xs:complexType>
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Authorization"/>
<xs:enumeration value="Cookie"/>
<xs:enumeration value="Expires"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="get" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:attribute name="url" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="file-too-large">
<xs:complexType>
<xs:sequence>
<xs:element name="max-file-size" type="xs:positiveInteger" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="retry">
<xs:complexType>
<xs:attribute name="stamp" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
]]></code>
</section1>
</xep>