Duplicate Authorization headers should not be ignored.Β #45699
Description
The context
A sender can send multiple Authorization headers in a request, because the Authorization headerβs definition, credentials, allows multiple auth-params to be recombined as a comma-separated list.
RFC 9110 β HTTP semantics
a sender MUST NOT generate multiple field lines with the same name in a message (whether in the headers or trailers) or append a field line when a field line of the same name already exists in the message, unless that field's definition allows multiple field line values to be recombined as a comma-separated list (i.e., at least one alternative of the field's definition allows a comma-separated list, such as an ABNF rule of
#(values)defined in Section 5.6.1).
Authorization = credentials
credentials = auth-scheme [ 1*SP ( token68 / #auth-param ) ]
Node.js MAY join them together with , .
RFC 9110 β HTTP semantics
A recipient MAY combine multiple field lines within a field section that have the same field name into one field line, without changing the semantics of the message, by appending each subsequent field line value to the initial field line value in order, separated by a comma ("
,") and optional whitespace (OWS, defined in Section 5.6.3). For consistency, usecomma SP.
Currently, Node.js ignores duplicate Authorization headers when it creates message.headers.
Node.js 19.2.0 documentation β HTTP
- Duplicates of
age,authorization,content-length,content-type,etag,expires,from,host,if-modified-since,if-unmodified-since,last-modified,location,max-forwards,proxy-authorization,referer,retry-after,server, oruser-agentare discarded.- β¦
- For all other headers, the values are joined together with
,.
Suggestion
I suggest Node.js join the field line values of multiple Authorization headers in a request with , , instead of ignoring them, when it creates message.headers.
Activity
aduh95 commentedon Dec 1, 2022
Can you share a minimal repro, the expected result, and the actual result?
issuefiler commentedon Dec 1, 2022
Proof-of-concept
The actual output
The expected output
@aduh95.
issuefiler commentedon Dec 1, 2022
But now that I think of it, splitting the
Authorizationheader field value like this (Authorization: realm="no") could be violation of the RFC,Authorization = credentials.aduh95 commentedon Dec 1, 2022
@nodejs/http
issuefiler commentedon Dec 1, 2022
I am not sure whether the βvalueβ in the section Β§11.6.2 means a β(combined) field valueβ or βfield line value.β
If it means the former,
would be valid (meaning, Node.js should respect multiple occurrences of
Authorizationheaders),and if it means the latter, invalid (meaning, Node.js is fine as is).
ShogunPanda commentedon Dec 1, 2022
According to section https://www.rfc-editor.org/rfc/rfc9110#name-changes-from-rfc-7230, if there is no clear indication of "field line value" then it refers to combined value.
Now, AFAIK Node implements RFC 7230 and not RFC 9110, so I wonder whether we should implement this or not.
@nodejs/http @nodejs/tsc WDYT?
bnoordhuis commentedon Dec 4, 2022
One problem I see is there's a non-zero risk of breaking existing programs if we make this change.
mcollina commentedon Dec 4, 2022
If we want to support this it would be behind an option.
marco-ippolito commentedon Dec 12, 2022
We can leave the default behaviour as it is and implement a flag in
http.createServer()likeallowDuplicateHeadersand combine them with,. Maybe in a future release this can become the standard behaviour.WDYT?
issuefiler commentedon Dec 13, 2022
That sounds good to me. The future documentation on that option would refer to RFC 9110.
mcollina commentedon Dec 13, 2022
As I said, I would recommend adding an option and possibly documenting it as experimental. I don't have much time to look into RFC 9110 and how it changed things.
Note that a lot of old clients and servers are very lenient on HTTP semantics, so they can expect whatever.
marco-ippolito commentedon Dec 23, 2022
I will open a PR
http: join authorization headers
http: join authorization headers
http: join authorization headers
http: join authorization headers
http: join authorization headers
http: join authorization headers