@stream-io/node-sdk 0.9.2 → 0.9.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.3](https://github.com/GetStream/stream-node/compare/v0.9.2...v0.9.3) (2026-11-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * limit decompressed webhook payloads to 10 MiB, configurable with webhookConfig.maxPayloadBytes ([#394](https://github.com/GetStream/stream-node/issues/394)) ([3de82bd](https://github.com/GetStream/stream-node/commit/3de82bda9eff5a2531c3d90086bb221e01a2f3e7))
9
+
3
10
  ## [0.9.2](https://github.com/GetStream/stream-node/compare/v0.9.1...v0.9.2) (2026-11-13)
4
11
 
5
12
 
package/dist/index.cjs.js CHANGED
@@ -75,6 +75,15 @@ var InvalidWebhookError = class extends Error {
75
75
  };
76
76
  var GZIP_MAGIC = Buffer.from([31, 139]);
77
77
  /**
78
+ * Webhook helper settings.
79
+ *
80
+ * `maxPayloadBytes` caps the decompressed size of a gzip webhook body
81
+ * (default 10 MiB). {@link gunzipPayload} runs before the signature
82
+ * check, so without a cap an unsigned gzip bomb could exhaust memory.
83
+ * Raise it if your events are larger.
84
+ */
85
+ var webhookConfig = { maxPayloadBytes: 10485760 };
86
+ /**
78
87
  * Returns `body` as a `Buffer`, gzip-decompressed when its first two
79
88
  * bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
80
89
  * plain JSON (no compression, or middleware already decompressed), the
@@ -83,13 +92,21 @@ var GZIP_MAGIC = Buffer.from([31, 139]);
83
92
  * Magic-byte detection (rather than relying on a header) keeps the same
84
93
  * handler correct when middleware - Express, Next.js, AWS Lambda -
85
94
  * auto-decompresses the request before your code sees it.
95
+ *
96
+ * @throws {InvalidWebhookError} When the body has the gzip magic but is
97
+ * not valid gzip, or inflates to more than
98
+ * `webhookConfig.maxPayloadBytes`.
86
99
  */
87
100
  function gunzipPayload(rawBody) {
88
101
  const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody);
89
- if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) try {
90
- return zlib.default.gunzipSync(body);
91
- } catch {
92
- throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
102
+ if (body.length >= 2 && body.subarray(0, 2).equals(GZIP_MAGIC)) {
103
+ const limit = webhookConfig.maxPayloadBytes;
104
+ try {
105
+ return zlib.default.gunzipSync(body, { maxOutputLength: limit });
106
+ } catch (err) {
107
+ if (err.code === "ERR_BUFFER_TOO_LARGE") throw new InvalidWebhookError(`${InvalidWebhookErrorMessages.gzipFailed}: payload exceeds ${limit} bytes`);
108
+ throw new InvalidWebhookError(InvalidWebhookErrorMessages.gzipFailed);
109
+ }
93
110
  }
94
111
  return body;
95
112
  }
@@ -4832,7 +4849,7 @@ var ApiClient = class {
4832
4849
  const headers = {
4833
4850
  Authorization: this.apiConfig.token,
4834
4851
  "stream-auth-type": "jwt",
4835
- "X-Stream-Client": "stream-node-0.9.2",
4852
+ "X-Stream-Client": "stream-node-0.9.3",
4836
4853
  "Accept-Encoding": "gzip",
4837
4854
  "x-client-request-id": clientRequestId
4838
4855
  };
@@ -6953,5 +6970,6 @@ exports.nsToDate = nsToDate;
6953
6970
  exports.nsToMs = nsToMs;
6954
6971
  exports.nsToRfc3339 = nsToRfc3339;
6955
6972
  exports.verifyAndParseWebhook = verifyAndParseWebhook;
6973
+ exports.webhookConfig = webhookConfig;
6956
6974
 
6957
6975
  //# sourceMappingURL=index.cjs.js.map