@@ -919,6 +919,51 @@ const buf = Buffer.from(new Foo(), 'utf8');
919919A ` TypeError ` will be thrown if ` object ` has not mentioned methods or is not of
920920other type appropriate for ` Buffer.from() ` variants.
921921
922+ ### Class Method: Buffer.harden([ options] )
923+ <!-- YAML
924+ added: TODO
925+ -->
926+
927+ * ` options ` {Object}
928+ * ` zeroFill ` {boolean}
929+ If ` true ` , all future ` Buffer ` instances, even the ones created with
930+ ` Buffer.allocUnsafe ` , will be zero-filled by default.
931+ ** Default:** ` true ` .
932+ * ` disablePool ` {boolean}
933+ If ` true ` , all future ` Buffer ` allocations will not be pooled and their
934+ underlying ` ArrayBuffer ` will have the same size as ` Buffer ` instance.
935+ ** Default:** ` true ` .
936+ * ` throwOnUnsafe ` {boolean}
937+ If ` true ` , unsafe ` Buffer(arg) ` API will throw instead of showing a
938+ deprecation warning.
939+ Otherwise, if ` false ` , first call to unsafe ` Buffer(arg) ` will trigger a
940+ deprecation warning, regardless of whether it was called from inside of
941+ ` node_modules ` directory or not (unlike the default warning).
942+ ** Default:** ` true ` .
943+ * ` freeze ` {boolean}
944+ If ` true ` , ` Buffer ` and ` require('buffer') ` objects are frozen and can
945+ not be monkey-patched.
946+ ` Buffer.prototype ` is not frozen for compatibility reasons.
947+ ** Default:** ` true ` .
948+
949+ Calling ` Buffer.harden() ` enables additional security measures for Buffer API,
950+ disabling some trade-offs between security and performance/compatibility that
951+ are present by default.
952+
953+ This method has effect only of subsequent Buffer API usage, Buffer instances
954+ created before ` Buffer.harden() ` is called are not affected.
955+
956+ Warning: for ecosystem compatibility and security reasons ` Buffer.harden() ` can
957+ be called only once and only from the top-level application code. Attempting to
958+ call it from a library in ` node_modules ` will throw.
959+
960+ By default, it enables mandratory zero fill, disables Buffer pooling, disables
961+ deprecated unsafe Buffer API, freezes ` Buffer ` and ` require('buffer') ` objects.
962+
963+ The exact behaviour could be fine-tuned: for example, to still allow unsafe
964+ Buffer API for compatibility reasons (e.g. if that us required by application
965+ dependencies), ` Buffer.haden({ throwOnUnsafe: false }) ` could be used.
966+
922967### Class Method: Buffer.from(string[ , encoding] )
923968<!-- YAML
924969added: v5.10.0
0 commit comments