Retrofit Structured Fields for HTTPPrahranAustraliamnot@mnot.nethttps://www.mnot.net/structured fieldshttpThis specification nominates a selection of existing HTTP fields as having syntax that is compatible with Structured Fields, so that they can be handled as such (subject to certain caveats).To accommodate some additional fields whose syntax is not compatible, it also defines mappings of their semantics into new Structured Fields. It does not specify how to negotiate their use.Status information for this document may be found at .Discussion of this document takes place on the HTTP Working Group mailing list (), which is archived at . Working Group information can be found at .Source for this draft and an issue tracker can be found at .IntroductionStructured Field Values for HTTP introduced a data model with associated parsing and serialization algorithms for use by new HTTP field values. Fields that are defined as Structured Fields can realise a number of benefits, including:Improved interoperability and security: precisely defined parsing and serialisation algorithms are typically not available for fields defined with just ABNF and/or prose.Reuse of common implementations: many parsers for other fields are specific to a single field or a small family of fields.Canonical form: because a deterministic serialisation algorithm is defined for each type, Structure Fields have a canonical representation.Enhanced API support: a regular data model makes it easier to expose field values as a native data structure in implementations.Alternative serialisations: While defines a textual serialisation of that data model, other, more efficient serialisations of the underlying data model are also possible.However, a field needs to be defined as a Structured Field for these benefits to be realised. Many existing fields are not, making up the bulk of header and trailer fields seen in HTTP traffic on the internet.This specification defines how a selection of existing HTTP fields can be handled as Structured Fields, so that these benefits can be realised -- thereby making them Retrofit Structured Fields.It does so using two techniques. lists compatible fields -- those that can be handled as if they were Structured Fields due to the similarity of their defined syntax to that in Structured Fields. lists mapped fields -- those whose syntax needs to be transformed into an underlying data model which is then mapped into that defined by Structured Fields.Note that while implementations can parse and serialise compatible fields as Structured Fields subject to the caveats in , a sender cannot generate mapped fields from and expect them to be understood and acted upon by the recipient without prior negotiation. This specification does not define such a mechanism.Notational ConventionsThe key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 when, and only when, they appear in all capitals, as shown here.Compatible FieldsThe HTTP fields listed in can usually have their values handled as Structured Fields according to the listed parsing and serialisation algorithms in , subject to the listed caveats.The listed types are chosen for compatibility with the defined syntax of the field as well as with actual internet traffic. However, not all instances of these fields will successfully parse. This might be because the field value is clearly invalid, or it might be because it is valid but not parseable as a Structured Field.An application using this specification will need to consider how to handle such field values. Depending on its requirements, it might be advisable to reject such values, treat them as opaque strings, or attempt to recover a structured value from them in an ad hoc fashion.Field NameStructured TypeAcceptListAccept-EncodingListAccept-LanguageListAccept-PatchListAccept-PostListAccept-RangesListAccess-Control-Allow-CredentialsItemAccess-Control-Allow-HeadersListAccess-Control-Allow-MethodsListAccess-Control-Allow-OriginItemAccess-Control-Expose-HeadersListAccess-Control-Max-AgeItemAccess-Control-Request-HeadersListAccess-Control-Request-MethodItemAgeItemAllowListALPNListAlt-SvcDictionaryAlt-UsedItemCache-ControlDictionaryCDN-LoopListClear-Site-DataListConnectionListContent-EncodingListContent-LanguageListContent-LengthListContent-TypeItemCross-Origin-Resource-PolicyItemDNTItemExpectDictionaryExpect-CTDictionaryHostItemKeep-AliveDictionaryMax-ForwardsItemOriginItemPragmaDictionaryPreferDictionaryPreference-AppliedDictionaryRetry-AfterItemSec-WebSocket-ExtensionsListSec-WebSocket-ProtocolListSec-WebSocket-VersionItemServer-TimingListSurrogate-ControlDictionaryTEListTiming-Allow-OriginListTrailerListTransfer-EncodingListUpgrade-Insecure-RequestsItemVaryListX-Content-Type-OptionsItemX-Frame-OptionsItemX-XSS-ProtectionListNote the following caveats regarding compatibility:
Error handling:
Parsing algorithms specified (or just widely implemented) for current HTTP headers may differ from those in Structured Fields in details such as error handling. For example, HTTP specifies that repeated directives in the Cache-Control header field have a different precedence than that assigned by a Dictionary structured field (which Cache-Control is mapped to).
Parameter and Dictionary keys:
HTTP parameter names are case-insensitive (per ), but Structured Fields require them to be all-lowercase. Although the vast majority of parameters seen in typical traffic are all-lowercase, compatibility can be improved by force-lowercasing parameters when parsing. Likewise, many Dictionary-based fields (e.g., Cache-Control, Expect-CT, Pragma, Prefer, Preference-Applied, Surrogate-Control) have case-insensitive keys, and compatibility can be improved by force-lowercasing them when parsing.
Parameter delimitation:
The parameters rule in HTTP (see ) allows whitespace before the ";" delimiter, but Structured Fields does not. Compatibility can be improved by allowing such whitespace when parsing.
String quoting:
allows backslash-escaping most characters in quoted strings, whereas Structured Field Strings only escape "\" and DQUOTE. Compatibility can be improved by unescaping other characters before parsing.
Token limitations:
In Structured Fields, tokens are required to begin with an alphabetic character or "*", whereas HTTP tokens allow a wider range of characters. This prevents use of mapped values that begin with one of these characters. For example, media types, field names, methods, range-units, character and transfer codings that begin with a number or special character other than "*" might be valid HTTP protocol elements, but will not be able to be represented as Structured Field Tokens.
Integer limitations:
Structured Fields Integers can have at most 15 digits; larger values will not be able to be represented in them.
IPv6 Literals:
Fields whose values contain IPv6 literal addresses (such as CDN-Loop, Host, and Origin) are not able to be represented as Structured Fields Tokens, because the brackets used to delimit them are not allowed in Tokens.
Empty Field Values:
Empty and whitespace-only field values are considered errors in Structured Fields. For compatible fields, an empty field indicates that the field should be silently ignored.
Alt-Svc:
Some ALPN tokens (e.g., h3-Q43) do not conform to key's syntax, and therefore cannot be represented as a Token. Since the final version of HTTP/3 uses the h3 token, this shouldn't be a long-term issue, although future tokens may again violate this assumption.
Content-Length:
Note that Content-Length is defined as a List because it is not uncommon for implementations to mistakenly send multiple values. See for handling requirements.
Retry-After:
Only the delta-seconds form of Retry-After can be represented; a Retry-After value containing a http-date will need to be converted into delta-seconds to be conveyed as a Structured Field Value.
Mapped FieldsSome HTTP field values have syntax that cannot be successfully parsed as Structured Fields. Instead, it is necessary to map them into a separate Structured Field with an alternative name.For example, the Date HTTP header field carries a date:Its value would be mapped to:As in , these fields are unable to carry values that are not valid Structured Fields, and so an application using this specification will need to how to support such values. Typically, handling them using the original field name is sufficient.Each field name listed below indicates a replacement field name and a means of mapping its original value into a Structured Field.URLsThe field names in (paired with their mapped field names) have values that can be mapped into Structured Fields by treating the original field's value as a String.Field NameMapped Field NameContent-LocationSF-Content-LocationLocationSF-LocationRefererSF-RefererFor example, this Location fieldcould be mapped as:DatesThe field names in (paired with their mapped field names) have values that can be mapped into Structured Fields by parsing their payload according to and representing the result as a Date.Field NameMapped Field NameDateSF-DateExpiresSF-ExpiresIf-Modified-SinceSF-If-Modified-SinceIf-Unmodified-SinceSF-If-Unmodified-SinceLast-ModifiedSF-Last-ModifiedFor example, an Expires field could be mapped as:ETagsThe field value of the ETag header field can be mapped into the SF-ETag Structured Field by representing the entity-tag as a String, and the weakness flag as a Boolean "w" parameter on it, where true indicates that the entity-tag is weak; if 0 or unset, the entity-tag is strong.For example, this:If-None-Match's field value can be mapped into the SF-If-None-Match Structured Field, which is a List of the structure described above. When a field value contains "*", it is represented as a Token.Likewise, If-Match's field value can be mapped into the SF-If-Match Structured Field in the same manner.For example:LinksThe field value of the Link header field can be mapped into the SF-Link List Structured Field by considering the URI-Reference as a String, and link-param as Parameters.For example, this:can be mapped to:CookiesThe field values of the Cookie and Set-Cookie fields can be mapped into the SF-Cookie Structured Field (a List) and SF-Set-Cookie Structured Field (a List), respectively.In each case, a cookie is represented as an Inner List containing two Items; the cookie name and value. The cookie name is always a String; the cookie value is a String, unless it can be successfully parsed as the textual representation of another, bare Item structured type (e.g., Byte Sequence, Decimal, Integer, Token, or Boolean).Cookie attributes map to Parameters on the Inner List, with the parameter name being forced to lowercase. Cookie attribute values are Strings unless a specific type is defined for them. This specification defines types for existing cookie attributes in .Parameter NameStructured TypeDomainStringHttpOnlyBooleanExpiresDateMax-AgeIntegerPathStringSecureBooleanSameSiteTokenThe Expires attribute is mapped to a Date representation of parsed-cookie-date (see ).For example, these unstructured fields:can be mapped into:IANA ConsiderationsPlease add the following note to the "Hypertext Transfer Protocol (HTTP) Field Name Registry":
The "Structured Type" column indicates the type of the field (per RFC8941), if any, and may be "Dictionary", "List" or "Item". A prefix of "*" indicates that it is a retrofit type (i.e., not natively Structured); see [this specification].Note that field names beginning with characters other than ALPHA or "*" will not be able to be represented as a Structured Fields Token, and therefore may be incompatible with being mapped into fields that refer to it; see [this specification].
Then, add a new column, "Structured Type", with the values from assigned to the nominated registrations, prefixing each with "*" to indicate that it is a retrofit type.Then, add the field names in , with the corresponding Structured Type as indicated, a status of "permanent" and referring to this document.Field NameStructured TypeSF-Content-LocationItemSF-CookieListSF-DateItemSF-ETagItemSF-ExpiresItemSF-If-MatchListSF-If-Modified-SinceItemSF-If-None-MatchListSF-If-Unmodified-SinceItemSF-LinkListSF-Last-ModifiedItemSF-LocationItemSF-RefererItemSF-Set-CookieListThen, add the indicated Structured Type for each existing registry entry listed in .Field NameStructured TypeAccept-CHListCache-StatusListCDN-Cache-ControlDictionaryCross-Origin-Embedder-PolicyItemCross-Origin-Embedder-Policy-Report-OnlyItemCross-Origin-Opener-PolicyItemCross-Origin-Opener-Policy-Report-OnlyItemOrigin-Agent-ClusterItemPriorityDictionaryProxy-StatusListFinally, add a new column to the "Cookie Attribute Registry" established by with the title "Structured Type", using information from .Security Considerations identifies existing HTTP fields that can be parsed and serialised with the algorithms defined in . Variances from existing parser behavior might be exploitable, particularly if they allow an attacker to target one implementation in a chain (e.g., an intermediary). However, given the considerable variance in parsers already deployed, convergence towards a single parsing algorithm is likely to have a net security benefit in the longer term. defines alternative representations of existing fields. Because downstream consumers might interpret the message differently based upon whether they recognise the alternative representation, implementations are prohibited from generating such fields unless they have negotiated support for them with their peer. This specification does not define such a mechanism, but any such definition needs to consider the implications of doing so carefully.Key words for use in RFCs to Indicate Requirement LevelsHTTP SemanticsStructured Field Values for HTTPCloudflareThe Varnish Cache ProjectCookies: HTTP State Management MechanismGoogle LLCGoogle LLCApple, IncAmbiguity of Uppercase vs Lowercase in RFC 2119 Key WordsWeb Linking