You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix guidance on headers and RFC6570 percent-encoding
After much debate and research, we agreed that percent-encoding
was never meant to be applied to headers.
Exactly how to handle RFC6570 and cookie parameters remains TBD.
For now, this preserves (but streamlines) the existing guidance
for cookies.
Copy file name to clipboardExpand all lines: src/oas.md
+19-28Lines changed: 19 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1164,7 +1164,10 @@ For simpler scenarios, a [`schema`](#parameter-schema) and [`style`](#parameter-
1164
1164
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the parameter.
1165
1165
The `example` and `examples` fields are mutually exclusive, and if either is present it SHALL _override_ any `example` in the schema.
1166
1166
1167
-
Serializing with `schema` is NOT RECOMMENDED for `in: "cookie"` parameters, `in: "header"` parameters that use HTTP header parameters (name=value pairs following a `;`) in their values, or `in: "header"` parameters where values might have non-URL-safe characters; see [Appendix D](#appendix-d-serializing-headers-and-cookies) for details.
1167
+
When serializing `in: "header"` parameters with `schema`, URI percent-encoding MUST NOT be applied; if using an RFC6570 implementation that automatically applies it, it MUST be removed before use.
1168
+
Implementations MUST NOT attempt to automatically quote header values, as the quoting rules vary too widely among different headers; users are expected to provide pre-quoted data as needed.
1169
+
1170
+
Serializing with `schema` is NOT RECOMMENDED for `in: "cookie"` parameters; see [Appendix D](#appendix-d-serializing-headers-and-cookies) for details.
1168
1171
1169
1172
| Field Name | Type | Description |
1170
1173
| ---- | :----: | ---- |
@@ -2563,7 +2566,8 @@ This object MAY be extended with [Specification Extensions](#specification-exten
2563
2566
For simpler scenarios, a [`schema`](#header-schema) and [`style`](#header-style) can describe the structure and syntax of the header.
2564
2567
When `example` or `examples` are provided in conjunction with the `schema` field, the example MUST follow the prescribed serialization strategy for the header.
2565
2568
2566
-
Serializing with `schema` is NOT RECOMMENDED for headers with parameters (name=value pairs following a `;`) in their values, or where values might have non-URL-safe characters; see [Appendix D](#appendix-d-serializing-headers-and-cookies) for details.
2569
+
When serializing `in: "header"` parameters with `schema`, URI percent-encoding MUST NOT be applied; if using an RFC6570 implementation that automatically applies it, it MUST be removed before use.
2570
+
Implementations MUST NOT attempt to automatically quote header values, as the quoting rules vary too widely among different headers; users are expected to provide pre-quoted data as needed.
2567
2571
2568
2572
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the header.
2569
2573
The `example` and `examples` fields are mutually exclusive, and if either is present it SHALL _override_ any `example` in the schema.
@@ -2581,7 +2585,6 @@ See also [Appendix C: Using RFC6570-Based Serialization](#appendix-c-using-rfc65
2581
2585
###### Fixed Fields for use with `content`
2582
2586
2583
2587
For more complex scenarios, the [`content`](#header-content) field can define the media type and schema of the header, as well as give examples of its use.
2584
-
Using `content` with a `text/plain` media type is RECOMMENDED for headers where the `schema` strategy is not appropriate.
2585
2588
2586
2589
| Field Name | Type | Description |
2587
2590
| ---- | :----: | ---- |
@@ -2612,25 +2615,19 @@ Requiring that a strong `ETag` header (with a value starting with `"` rather tha
2612
2615
```json
2613
2616
"ETag": {
2614
2617
"required": true,
2615
-
"content": {
2616
-
"text/plain": {
2617
-
"schema": {
2618
-
"type": "string",
2619
-
"pattern": "^\""
2620
-
}
2621
-
}
2618
+
"schema": {
2619
+
"type": "string",
2620
+
"pattern": "^\""
2622
2621
}
2623
2622
}
2624
2623
```
2625
2624
2626
2625
```yaml
2627
2626
ETag:
2628
2627
required: true
2629
-
content:
2630
-
text/plain:
2631
-
schema:
2632
-
type: string
2633
-
pattern: ^"
2628
+
schema:
2629
+
type: string
2630
+
pattern: ^"
2634
2631
```
2635
2632
2636
2633
#### Tag Object
@@ -4522,25 +4519,19 @@ This will expand to the result:
4522
4519
4523
4520
## Appendix D: Serializing Headers and Cookies
4524
4521
4525
-
[RFC6570](https://www.rfc-editor.org/rfc/rfc6570)'s percent-encoding behavior is not always appropriate for `in: "header"` and `in: "cookie"` parameters.
4522
+
_**Note:** OAS v3.0.4 and v3.1.1 applied the advice in this section to both headers and cookies.
4523
+
However, further research has indicated that percent-encoding was never intended to apply to headers, so this section has been corrected to apply only to cookies._
4524
+
4525
+
[RFC6570](https://www.rfc-editor.org/rfc/rfc6570)'s percent-encoding behavior is not always appropriate for `in: "cookie"` parameters.
4526
4526
In many cases, it is more appropriate to use `content` with a media type such as `text/plain` and require the application to assemble the correct string.
4527
4527
4528
-
For both [RFC6265](https://www.rfc-editor.org/rfc/rfc6265)cookies and HTTP headers using the [RFC8941](https://www.rfc-editor.org/rfc/rfc8941) structured fields syntax, non-ASCII content is handled using base64 encoding (`contentEncoding: "base64"`).
4528
+
[RFC6265](https://www.rfc-editor.org/rfc/rfc6265)recommends (but does not strictly required) base64 encoding (`contentEncoding: "base64"`) if "arbitrary data" will be stored in a cookie.
4529
4529
Note that the standard base64-encoding alphabet includes non-URL-safe characters that are percent-encoded by RFC6570 expansion; serializing values through both encodings is NOT RECOMMENDED.
4530
4530
While `contentEncoding` also supports the `base64url` encoding, which is URL-safe, the header and cookie RFCs do not mention this encoding.
4531
4531
4532
-
Most HTTP headers predate the structured field syntax, and a comprehensive assessment of their syntax and encoding rules is well beyond the scope of this specification.
4533
-
While [RFC8187](https://www.rfc-editor.org/rfc/rfc8187) recommends percent-encoding HTTP (header or trailer) field parameters, these parameters appear after a `;` character.
4534
-
With `style: "simple"`, that delimiter would itself be percent-encoded, violating the general HTTP field syntax.
4535
-
4536
-
Using `style: "form"` with `in: "cookie"` is ambiguous for a single value, and incorrect for multiple values.
4537
-
This is true whether the multiple values are the result of using `explode: true` or not.
4538
-
4539
-
This style is specified to be equivalent to RFC6570 form expansion which includes the `?` character (see [Appendix C](#appendix-c-using-rfc6570-based-serialization) for more details), which is not part of the cookie syntax.
4540
-
However, examples of this style in past versions of this specification have not included the `?` prefix, suggesting that the comparison is not exact.
4541
-
Because implementations that rely on an RFC6570 implementation and those that perform custom serialization based on the style example will produce different results, it is implementation-defined as to which of the two results is correct.
4532
+
Using `style: "form"` with `in: "cookie"` via an RFC6570 implementation requires stripping the `?` prefix, as when producing `application/x-www-form-urlencoded` message bodies.
4542
4533
4543
-
For multiple values, `style: "form"` is always incorrectas name=value pairs in cookies are delimited by `;` (a semicolon followed by a space character) rather than `&`.
4534
+
For multiple values, `style: "form"` is always incorrect, even if no characters are subject to percent-encoding, as name=value pairs in cookies are delimited by `;` (a semicolon followed by a space character) rather than `&`.
4544
4535
4545
4536
## Appendix E: Percent-Encoding and Form Media Types
0 commit comments