Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) greenbytes GmbH
Hafenweg 16 MuensterNW48155 Germany julian.reschke@greenbytes.de http://greenbytes.de/tech/webdav/
HTTPbis Working Group HTTP/1.1 defines the Content-Disposition response header field, but points out that it is not part of the HTTP/1.1 Standard. This specification takes over the definition and registration of Content-Disposition, as used in HTTP, and clarifies internationalization aspects. This specification is expected to replace the definition of Content-Disposition in the HTTP/1.1 specification, as currently revised by the IETF HTTPbis working group. See also . Discussion of this draft should take place on the HTTPBIS working group mailing list (ietf-http-wg@w3.org). The current issues list is at and related documents (including fancy diffs) can be found at . The changes in this draft are summarized in .
HTTP/1.1 defines the Content-Disposition response header field in Section 19.5.1 of , but points out that it is not part of the HTTP/1.1 Standard (Section 15.5): Content-Disposition is not part of the HTTP standard, but since it is widely implemented, we are documenting its use and risks for implementers. This specification takes over the definition and registration of Content-Disposition, as used in HTTP. Based on interoperability testing with existing User Agents, it fully defines a profile of the features defined in the Multipurpose Internet Mail Extensions (MIME) variant () of the header field, and also clarifies internationalization aspects. Note: this document does not apply to Content-Disposition header fields appearing in message payloads transmitted over HTTP, such as when using the media type "multipart/form-data" ().
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in . This specification uses the augmented BNF notation defined in Section 2.1 of , including its rules for implied linear whitespace (LWS).
This specification defines conformance criteria for both senders (usually, HTTP origin servers) and recipients (usually, HTTP user agents) of the Content-Location header field. An implementation is considered conformant if it complies with all of the requirements associated with its role. This specification also defines certain forms of the header field-value to be invalid, using both ABNF and prose requirements, but it does not define special handling of these invalid field-values. Sending implementations MUST NOT generate Content-Location header fields that are invalid. Consuming implementations MAY take steps to recover a usable field-value from an invalid header field, but SHOULD NOT reject the message outright, unless this is explicitly desirable behaviour (e.g., the implementation is a validator). As such, the default handling of invalid fields is to ignore them.
The Content-Disposition response header field is used to convey additional information about how to process the response payload, and also can be used to attach additional metadata, such as the filename to use when saving the response payload locally.
]]>
Defined in : quoted-string = value = ; token | quoted-string ]]>
Defined in : ]]>
Header field values with multiple instances of the same parameter name are invalid. Note that due to the rules for implied linear whitespace (Section 2.1 of ), OPTIONAL whitespace can appear between words (token or quoted-string) and separator characters. Furthermore note that the format used for ext-value allows specifying a natural language; this is of limited use for filenames and is likely to be ignored by recipients.
If the disposition type matches "attachment" (case-insensitively), this indicates that the user agent should prompt the user to save the response locally, rather than process it normally (as per its media type). On the other hand, if it matches "inline" (case-insensitively), this implies default processing. Unknown or unhandled disposition types SHOULD be handled by recipients the same way as "attachment" (see also , Section 2.8).
The parameters "filename" and "filename*", to be matched case-insensitively, provide information on how to construct a filename for storing the message payload. Depending on the disposition type, this information might be used right away (in the "save as..." interaction caused for the "attachment" disposition type), or later on (for instance, when the user decides to save the contents of the current page being displayed). The parameters "filename" and "filename*" differ only in that "filename*" uses the encoding defined in , allowing the use of characters not present in the ISO-8859-1 character set (). Many user agent implementations predating this specification do not understand the "filename*" parameter. Therefore, when both "filename" and "filename*" are present in a single header field value, recipients SHOULD pick "filename*" and ignore "filename". This way, senders can avoid special-casing specific user agents by sending both the more expressive "filename*" parameter, and the "filename" parameter as fallback for legacy recipients (see for an example). It is essential that user agents treat the specified filename as advisory only, thus be very careful in extracting the desired information. In particular: When the value contains path separator characters ("\" or "/"), recipients SHOULD ignore all but the last path segment. This prevents unintentional overwriting of well-known file system locations (such as "/etc/passwd"). Many platforms do not use Internet Media Types () to hold type information in the file system, but rely on filename extensions instead. Trusting the server-provided file extension could introduce a privilege escalation when the saved file is later opened (consider ".exe"). Thus, recipients need to ensure that a file extension is used that is safe, optimally matching the media type of the received payload. Recipients are advised to strip or replace character sequences that are known to cause confusion both in user interfaces and in filenames, such as control characters and leading and trailing whitespace. Other aspects recipients need to be aware of are names that have a special meaning in the file system or in shell commands, such as "." and "..", "~", "|", and also device names. Note: Many user agents do not properly handle escape characters when using the quoted-string form. Furthermore, some user agents erroneously try to perform unescaping of "percent" escapes (see ), and thus might misinterpret filenames containing the percent character followed by two hex digits.
To enable future extensions, recipients SHOULD ignore unrecognized parameters (see also , Section 2.8).
Note that Section 9 of defines IANA registries both for disposition types and disposition parameters. This registry is shared by different protocols using Content-Disposition, such as MIME and HTTP. Therefore, not all registered values may make sense in the context of HTTP.
Direct UA to show "save as" dialog, with a filename of "example.html":
Direct UA to behave as if the Content-Disposition header field wasn't present, but to remember the filename "an example.html" for a subsequent save operation: Note: this uses the quoted-string form so that the space character can be included.
Direct UA to show "save as" dialog, with a filename containing the Unicode character U+20AC (EURO SIGN): Here, the encoding defined in is also used to encode the non-ISO-8859-1 character.
Same as above, but adding the "filename" parameter for compatibility with user agents not implementing RFC 5987: Note: as of February 2011, those user agents that do not support the RFC 5987 encoding ignore "filename*" when it occurs after "filename". Unfortunately, some user agents that do support RFC 5987 do pick the "filename" rather than the "filename*" parameter when it occurs first; it is expected that this situation is going to improve soon.
The "filename*" parameter (), using the encoding defined in , allows the server to transmit characters outside the ISO-8859-1 character set, and also to optionally specify the language in use. Future parameters might also require internationalization, in which case the same encoding can be used.
Using server-supplied information for constructing local filenames introduces many risks. These are summarized in . Furthermore, implementers also ought to be aware of the Security Considerations applying to HTTP (see Section 15 of ), and also the parameter encoding defined in (see Section 5).
This specification does not introduce any changes to the registration procedures for disposition values and parameters that are defined in Section 9 of .
This document updates the definition of the Content-Disposition HTTP header field in the permanent HTTP header field registry (see ). Content-Disposition http standard IETF this specification ()
Thanks to Adam Barth, Rolf Eike Beer, Bjoern Hoehrmann, Alfred Hoenes, Roar Lauritzsen, Henrik Nordstrom, and Mark Nottingham for their valuable feedback.
Key words for use in RFCs to Indicate Requirement Levels Harvard University
sob@harvard.edu
General keyword
Hypertext Transfer Protocol -- HTTP/1.1 University of California, Irvine
fielding@ics.uci.edu
W3C
jg@w3.org
Compaq Computer Corporation
mogul@wrl.dec.com
MIT Laboratory for Computer Science
frystyk@w3.org
Xerox Corporation
masinter@parc.xerox.com
Microsoft Corporation
paulle@microsoft.com
W3C
timbl@w3.org
Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters greenbytes GmbH
Hafenweg 16 MuensterNW48155 Germany julian.reschke@greenbytes.de http://greenbytes.de/tech/webdav/
Information technology -- 8-bit single-byte coded graphic character sets -- Part 1: Latin alphabet No. 1 International Organization for Standardization
Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types Innosoft International, Inc.
ned@innosoft.com
First Virtual Holdings
nsb@nsb.fv.com
MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text University of Tennessee
moore@cs.utk.edu
Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field New Century Systems
rens@century.com
QUALCOMM Incorporated
sdorner@qualcomm.com
Department of Computer Science
moore@cs.utk.edu
MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, and Continuations Innosoft International, Inc.
ned.freed@innosoft.com
University of Tennessee
moore@cs.utk.edu
Returning Values from Forms: multipart/form-data Xerox Palo Alto Research Center
masinter@parc.xerox.com
Registration Procedures for Message Header Fields Nine by Nine
GK-IETF@ninebynine.org
BEA Systems
mnot@pobox.com
HP Labs
JeffMogul@acm.org
Uniform Resource Identifier (URI): Generic Syntax World Wide Web Consortium
timbl@w3.org http://www.w3.org/People/Berners-Lee/
Day Software
fielding@gbiv.com http://roy.gbiv.com/
Adobe Systems Incorporated
LMM@acm.org http://larry.masinter.net/
Compared to Section 19.5.1 of , the following normative changes reflecting actual implementations have been made: According to RFC 2616, the disposition type "attachment" only applies to content of type "application/octet-stream". This restriction has been removed, because user agents in practice do not check the content type, and it also discourages properly declaring the media type. RFC 2616 only allows "quoted-string" for the filename parameter. This would be an exceptional parameter syntax, and also doesn't reflect actual use. The definition for the disposition type "inline" (, Section 2.1) has been re-added with a suggestion for its processing. This specification requires support for the extended parameter encoding defined in .
Section 2 of defines several additional disposition parameters: "creation-date", "modification-date", "quoted-date-time", and "size". The majority of user agents does not implement these, thus they have been omitted from this specification.
By default, HTTP header field parameters cannot carry characters outside the ISO-8859-1 () character encoding (see , Section 2.2). For the "filename" parameter, this of course is an unacceptable restriction. Unfortunately, user agent implementers have not managed to come up with an interoperable approach, although the IETF Standards Track specifies exactly one solution (, clarified and profiled for HTTP in ). For completeness, the sections below describe the various approaches that have been tried, and explains how they are inferior to the RFC 5987 encoding used in this specification.
RFC 2047 defines an encoding mechanism for header fields, but this encoding is not supposed to be used for header field parameters - see Section 5 of : An 'encoded-word' MUST NOT appear within a 'quoted-string'. ... An 'encoded-word' MUST NOT be used in parameter of a MIME Content-Type or Content-Disposition field, or in any structured field body except within a 'comment' or 'phrase'. In practice, some user agents implement the encoding, some do not (exposing the encoded string to the user), and some get confused by it.
Some user agents accept percent encoded (, Section 2.1) sequences of characters. The character encoding being used for decoding depends on various factors, including the encoding of the referring page, the user agent's locale, its configuration, and also the actual value of the parameter. In practice, this is hard to use because those user agents that do not support it will display the escaped character sequence to the user. For those user agents that do implement this it is difficult to predict what character encoding they actually expect.
Some user agents inspect the value (which defaults to ISO-8859-1 for the quoted-string form) and switch to UTF-8 when it seems to be more likely to be the correct interpretation. As with the approaches above, this is not interoperable and furthermore risks misinterpreting the actual value.
Unfortunately, as of February 2011, neither the encoding defined in RFCs 2231 and 5987, nor any of the alternate approaches discussed above was implemented interoperably. Thus, this specification recommends the approach defined in RFC 5987, which at least has the advantage of actually being specified properly. The table below shows the implementation support for the various approaches: User Agent RFC 2231/5987 RFC 2047 Percent Encoding Encoding Sniffing Chrome yes yes yes yes Firefox yes (*) yes no yes Internet Explorer yes (**) no yes no Konqueror yes no no no Opera yes no no no Safari no no no yes (*) Does not implement the fallback behavior to "filename" described in . (**) Starting with IE9RC, but only implements UTF-8.
Note: the issues names in the change log entries for draft-reschke-rfc2183-in-http refer to .
Adjust terminology ("header" -> "header field"). Update rfc2231-in-http reference.
Update rfc2231-in-http reference. Actually define the "filename" parameter. Add internationalization considerations. Add examples using the RFC 5987 encoding. Add overview over other approaches, plus a table reporting implementation status. Add and resolve issue "nodep2183". Add issues "asciivsiso", "deplboth", "quoted", and "registry".
Add and close issue "docfallback". Close issues "asciivsiso", "deplboth", "quoted", and "registry".
Updated to be a Working Draft of the IETF HTTPbis Working Group.
Closed issues: : "handling of unknown disposition types" Slightly updated the notes about the proposed fallback behavior.
Various editorial improvements.
Closed issues: : "state that repeating parameters are invalid" : "warn about %xx in filenames being misinterpreted" : "mention control chars when talking about postprecessing the filename parameter" Update ; Opera 10.63 RC implements the recommended fallback behavior.
Closed issues: : "'modification-date' *is* implemented in Konq 4.5" : "clarify what LWS means for the Content-Disp grammar" : "Avoid passive voice in message requirements" : "text about historical percent-decoding unclear" : "add explanation of language tagging" : "Clarify that C-D spec does not apply to multipart upload"
Updated implementation information (Chrome 9 implements RFC 5987, IE 9 RC implements it for UTF-8 only). Clarify who requirements are on, add a section discussing conformance and handling of invalid field values in general. Closed issues: : "Path Separator Characters"