From e876c0c308bb98ed08ec9cae9f04a65a48517be5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 1 Jul 2020 01:20:09 +0200 Subject: [PATCH] http2: add support for sensitive headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for “sensitive”/“never-indexed” HTTP2 headers. Fixes: https://github.com/nodejs/node/issues/34091 PR-URL: https://github.com/nodejs/node/pull/34145 Reviewed-By: James M Snell Reviewed-By: Denys Otrishko --- doc/api/http2.md | 41 +++++++++++++++- lib/http2.js | 2 + lib/internal/http2/core.js | 11 ++++- lib/internal/http2/util.js | 20 ++++++-- src/node_http2.cc | 21 ++++++--- src/node_http2.h | 1 - src/node_http_common-inl.h | 8 +++- src/node_http_common.h | 2 + src/quic/node_quic_http3_application.h | 1 - test/parallel/test-http2-sensitive-headers.js | 47 +++++++++++++++++++ test/parallel/test-http2-util-headers-list.js | 37 +++++++++++---- .../parallel/test-http2-zero-length-header.js | 3 +- 12 files changed, 167 insertions(+), 27 deletions(-) create mode 100644 test/parallel/test-http2-sensitive-headers.js diff --git a/doc/api/http2.md b/doc/api/http2.md index c24e43f12b0c6b..122d9deb517974 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -2461,6 +2461,17 @@ added: v8.4.0 Returns a [HTTP/2 Settings Object][] containing the deserialized settings from the given `Buffer` as generated by `http2.getPackedSettings()`. +### `http2.sensitiveHeaders` + + +* {symbol} + +This symbol can be set as a property on the HTTP/2 headers object with an array +value in order to provide a list of headers considered sensitive. +See [Sensitive headers][] for more details. + ### Headers object Headers are represented as own-properties on JavaScript objects. The property @@ -2509,6 +2520,33 @@ server.on('stream', (stream, headers) => { }); ``` + +#### Sensitive headers + +HTTP2 headers can be marked as sensitive, which means that the HTTP/2 +header compression algorithm will never index them. This can make sense for +header values with low entropy and that may be considered valuable to an +attacker, for example `Cookie` or `Authorization`. To achieve this, add +the header name to the `[http2.sensitiveHeaders]` property as an array: + +```js +const headers = { + ':status': '200', + 'content-type': 'text-plain', + 'cookie': 'some-cookie', + 'other-sensitive-header': 'very secret data', + [http2.sensitiveHeaders]: ['cookie', 'other-sensitive-header'] +}; + +stream.respond(headers); +``` + +For some headers, such as `Authorization` and short `Cookie` headers, +this flag is set automatically. + +This property is also set for received headers. It will contain the names of +all headers marked as sensitive, including ones marked that way automatically. + ### Settings object