TritonDataCenter / node-http-signature

Reference implementation of Joyent's HTTP Signature Scheme
https://tritondatacenter.com
MIT License
404 stars 118 forks source link

Multiple header values not serialized properly per the spec #75

Open dlongley opened 6 years ago

dlongley commented 6 years ago

There are multiple places in this lib that do not serialize multiple header values according to the spec. The code assumes that the value of a header will be a string -- or, that if it is an array, that the default join will suffice. This is not the case -- the spec says (in Section 2.3. Signature String Construction):

If there are multiple instances of the same header field, all header field values associated with the header field MUST be concatenated, separated by a ASCII comma and an ASCII space ,, and used in the order in which they will appear in the transmitted HTTP message. Any other modification to the header field value MUST NOT be made.

This means that everywhere in this lib that does the construction: header + ' ' + value (or similar), where value may be an array, is incorrect. It should be header + ' ' + value.join(', '). Ideally, all of these spots would also be consolidated so only one place needs to be maintained.

At least these instances need to be fixed:

https://github.com/joyent/node-http-signature/blob/master/lib/signer.js#L130 https://github.com/joyent/node-http-signature/blob/master/lib/signer.js#L133 https://github.com/joyent/node-http-signature/blob/master/lib/signer.js#L338 https://github.com/joyent/node-http-signature/blob/master/lib/parser.js#L271