h2lean 0.19.8 → 0.19.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -22
- package/index.js +7 -7
- package/lib/Http2Stream.js +13 -5
- package/lib/client/Http2ClientSession.js +388 -61
- package/lib/client/Http2ClientStream.js +135 -48
- package/lib/client/client.js +39 -11
- package/lib/headers.js +14 -7
- package/lib/server/Http2ServerSession.js +177 -42
- package/lib/server/Http2ServerStream.js +57 -12
- package/lib/server/compat.js +291 -72
- package/lib/server/server.js +86 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Up to **8× less CPU per request** and **6.8× more requests per second** than `
|
|
|
33
33
|
- [Monkey-patching for frameworks without injection](#monkey-patching-for-frameworks-without-injection)
|
|
34
34
|
- 🛠️ [Advanced Tuning](#️-advanced-tuning)
|
|
35
35
|
- 🔒 [Security](#-security)
|
|
36
|
-
- ⚠️ [
|
|
36
|
+
- ⚠️ [Known Divergences](#️-known-divergences)
|
|
37
37
|
- 📚 [Documentation](#-documentation)
|
|
38
38
|
- 🤝 [Contributing](#-contributing)
|
|
39
39
|
- ⚖️ [License](#️-license)
|
|
@@ -93,7 +93,7 @@ Compatibility target is the **public surface** of `node:http2`: names, argument
|
|
|
93
93
|
|
|
94
94
|
Same class names (`Http2Session`, `Http2Stream`, `Http2ServerRequest`, `Http2ServerResponse`), same event names, same `Http2Session` and settings semantics, all 240 protocol constants re-exported from `node:http2` itself — user code that compares `error.code !== http2.constants.NGHTTP2_ENHANCE_YOUR_CALM` keeps working unchanged. Both transports on both sides: `createServer` (h2c), `createSecureServer` (h2s), `connect()` over cleartext and TLS with node's ALPN rules, and `performServerHandshake()` to run a server session over a socket you already hold.
|
|
95
95
|
|
|
96
|
-
Where behavior deliberately differs from node, it is **documented, measured, and pinned by tests** — never silent. Known divergences: [
|
|
96
|
+
Where behavior deliberately differs from node, it is **documented, measured, and pinned by tests** — never silent. Known divergences: [DIVERGENCES.md](./DIVERGENCES.md).
|
|
97
97
|
|
|
98
98
|
## 📦 Installation
|
|
99
99
|
|
|
@@ -266,40 +266,30 @@ nodeHttp2.connect = h2lean.connect;
|
|
|
266
266
|
h2lean terminates **untrusted bytes from the internet** and turns them into objects your application trusts — the threat model is treated as the primary design constraint ([SECURITY.md](./SECURITY.md)):
|
|
267
267
|
|
|
268
268
|
- 🛡️ **Every denial-of-service limit matches nghttp2** (the engine inside node) or was measured against a live node server — a peer's budget against node is its budget against h2lean: SETTINGS-entry cap (CVE-2020-11080), CONTINUATION cap (CVE-2024-28182), rapid-reset budget (CVE-2023-44487), outbound staging, parked-stream and history bounds.
|
|
269
|
-
- 🚫 **Request-smuggling defense by construction** (RFC 9113 §10.3): field names must be lower-case tokens, values may not carry NUL/CR/LF, connection-specific fields are refused in both directions — all refused at encode time, *before a single octet reaches the wire*.
|
|
269
|
+
- 🚫 **Request-smuggling defense by construction** (RFC 9113 §10.3): field names must be lower-case tokens, values may not carry NUL/CR/LF, connection-specific fields are refused in both directions — all refused at encode time, *before a single octet reaches the wire*. This is a deliberate, measured divergence from node in the strict direction ([DIVERGENCES.md](./DIVERGENCES.md), entry 19).
|
|
270
270
|
- ✅ **Verified, not assumed:**
|
|
271
271
|
- **300+ differential tests** — application scripts run against both `node:http2` and h2lean, transcripts compared;
|
|
272
272
|
- **h2spec 146/146** — full RFC 9113/7541 conformance, same verdict as node's own HTTP/2 (`npm run spec`);
|
|
273
273
|
- **mutation-tested guards** — every defensive limit is rewritten in place and proven to fail the suite ([tools/mutate-guards.js](./tools/mutate-guards.js)).
|
|
274
274
|
|
|
275
|
-
## ⚠️ Known Divergences
|
|
275
|
+
## ⚠️ Known Divergences
|
|
276
276
|
|
|
277
277
|
The core surface is implemented: server (stream + compat), client (`connect`),
|
|
278
|
-
`performServerHandshake`, and server push (`pushStream` / PUSH_PROMISE reception).
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
None silently returns a wrong answer: a missing method is `undefined`, so calling it throws
|
|
282
|
-
`TypeError`, never a fabricated result.
|
|
278
|
+
`performServerHandshake`, and server push (`pushStream` / PUSH_PROMISE reception).
|
|
279
|
+
None of the remaining gaps silently returns a wrong answer: a missing method is
|
|
280
|
+
`undefined`, so calling it throws `TypeError`, never a fabricated result.
|
|
283
281
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
**Events not emitted:**
|
|
290
|
-
|
|
291
|
-
- 🪤 **`'ready'`** on a stream (node emits it when the stream id is assigned).
|
|
292
|
-
|
|
293
|
-
**Behavioural differences** (full reasoning in the header comment of the affected file and [AGENTS.md](./AGENTS.md) §10):
|
|
294
|
-
|
|
295
|
-
- 🎛️ **Options accepted but ignored:** `headerHintTimeout`/`headerHintSize` (no 1xx informational-flood guard). `paddingStrategy` (0/1/2, with node's 8-octet-aligned and 255-octet-pad wire shapes) and `maxSessionMemory` (per-stream and retained-header budget with node's ENHANCE_YOUR_CALM refusal and callback-failure teardown) are now implemented; see [SECURITY.md](./SECURITY.md).
|
|
296
|
-
- 🚪 The **graceful-close predicate**, the **spurious `200` on `end()` with no body**, a **response queued in the same batch as a refusal**, the **`COMPRESSION_ERROR` vs `FRAME_SIZE_ERROR`** verdict, the **teardown event order**, and **`req.pause()/read()` not slowing the peer** (credit is window-bounded, not per-`read()`) differ from node — each pinned as a KNOWN DIVERGENCE in the test suite.
|
|
282
|
+
Every known divergence — its scenario, node's measured behaviour, h2lean's
|
|
283
|
+
behaviour and the reason it is not implemented — is recorded in
|
|
284
|
+
[DIVERGENCES.md](./DIVERGENCES.md). That file is the single home for this
|
|
285
|
+
material; it is a decision record, not a to-do list.
|
|
297
286
|
|
|
298
287
|
## 📚 Documentation
|
|
299
288
|
|
|
300
289
|
| Document | What it holds |
|
|
301
290
|
|---|---|
|
|
302
291
|
| [PERFORMANCE.md](./PERFORMANCE.md) | 🏎️ Benchmarks: methodology, full tables, caveats, re-run commands |
|
|
292
|
+
| [DIVERGENCES.md](./DIVERGENCES.md) | 🔀 Every known divergence from node, measured and explained |
|
|
303
293
|
| [SECURITY.md](./SECURITY.md) | 🔒 Threat model, every hardening limit, known gaps — stated plainly |
|
|
304
294
|
| [OPTIMIZATION.md](./OPTIMIZATION.md) | 🔬 All 35 measured optimization techniques (and rejected ones) |
|
|
305
295
|
| [CHANGELOG.md](./CHANGELOG.md) | 📋 Release history, Keep-a-Changelog format |
|
package/index.js
CHANGED
|
@@ -82,15 +82,15 @@ function getUnpackedSettings(buf, options) {
|
|
|
82
82
|
err.code = 'ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH';
|
|
83
83
|
throw err;
|
|
84
84
|
}
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
: Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
85
|
+
// node passes the view straight to internal/buffer's readUInt16BE/readUInt32BE, which
|
|
86
|
+
// index the view by element. For a Buffer (a Uint8Array) element and octet coincide; for
|
|
87
|
+
// a wider typed array node reads word-sized values. Match that instead of wrapping the
|
|
88
|
+
// view in a Buffer, which would change a Uint16Array's meaning (getpackedsettings.test.js).
|
|
90
89
|
const out = {};
|
|
91
90
|
for (let i = 0; i + 6 <= buf.length; i += 6) {
|
|
92
|
-
const id =
|
|
93
|
-
const value =
|
|
91
|
+
const id = buf[i] * 2 ** 8 + buf[i + 1];
|
|
92
|
+
const value = buf[i + 2] * 2 ** 24 + buf[i + 3] * 2 ** 16 +
|
|
93
|
+
buf[i + 4] * 2 ** 8 + buf[i + 5];
|
|
94
94
|
switch (id) {
|
|
95
95
|
case 1: out.headerTableSize = value; break;
|
|
96
96
|
case 2: out.enablePush = value !== 0; break;
|
package/lib/Http2Stream.js
CHANGED
|
@@ -673,22 +673,30 @@ function specType(v) {
|
|
|
673
673
|
// ("must be of type number"), a non-integer number is ERR_OUT_OF_RANGE ("It must be an
|
|
674
674
|
// integer"), and a code outside [0, 2^32-1] is ERR_OUT_OF_RANGE ("It must be >= 0 &&
|
|
675
675
|
// <= 4294967295"). The callback's own message names "callback" and follows the same
|
|
676
|
-
// determineSpecificType shapes (measured: string, null, number).
|
|
676
|
+
// determineSpecificType shapes (measured: string, null, number). node builds the
|
|
677
|
+
// validators off TypeError (ERR_INVALID_ARG_TYPE) and RangeError (ERR_OUT_OF_RANGE)
|
|
678
|
+
// in internal/errors.js, not off plain Error -- the class is observable on a
|
|
679
|
+
// caught throw (test/upstream/client-rststream-before-connect.js).
|
|
680
|
+
function rstValidatorErr(code, msg) {
|
|
681
|
+
const err = code === 'ERR_INVALID_ARG_TYPE' ? new TypeError(msg) : new RangeError(msg);
|
|
682
|
+
err.code = code;
|
|
683
|
+
return err;
|
|
684
|
+
}
|
|
677
685
|
function validateRstCode(code, callback) {
|
|
678
686
|
if (typeof code !== 'number') {
|
|
679
|
-
throw
|
|
687
|
+
throw rstValidatorErr('ERR_INVALID_ARG_TYPE',
|
|
680
688
|
`The "code" argument must be of type number. Received ${specType(code)}`);
|
|
681
689
|
}
|
|
682
690
|
if (!Number.isInteger(code)) {
|
|
683
|
-
throw
|
|
691
|
+
throw rstValidatorErr('ERR_OUT_OF_RANGE',
|
|
684
692
|
`The value of "code" is out of range. It must be an integer. Received ${code}`);
|
|
685
693
|
}
|
|
686
694
|
if (code < 0 || code > 4294967295) {
|
|
687
|
-
throw
|
|
695
|
+
throw rstValidatorErr('ERR_OUT_OF_RANGE',
|
|
688
696
|
`The value of "code" is out of range. It must be >= 0 && <= 4294967295. Received ${code}`);
|
|
689
697
|
}
|
|
690
698
|
if (callback !== undefined && typeof callback !== 'function') {
|
|
691
|
-
throw
|
|
699
|
+
throw rstValidatorErr('ERR_INVALID_ARG_TYPE',
|
|
692
700
|
`The "callback" argument must be of type function. Received ${specType(callback)}`);
|
|
693
701
|
}
|
|
694
702
|
}
|