@platform-sec/sensitive-string-core 0.6.0 → 0.6.1

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.
Files changed (153) hide show
  1. package/dist/bson.d.ts +28 -0
  2. package/dist/bson.d.ts.map +1 -0
  3. package/dist/bson.js +37 -0
  4. package/dist/bson.js.map +1 -0
  5. package/dist/classification.d.ts +69 -0
  6. package/dist/classification.d.ts.map +1 -0
  7. package/dist/classification.js +104 -0
  8. package/dist/classification.js.map +1 -0
  9. package/dist/compare.d.ts +36 -0
  10. package/dist/compare.d.ts.map +1 -0
  11. package/dist/compare.js +123 -0
  12. package/dist/compare.js.map +1 -0
  13. package/dist/context.d.ts +78 -0
  14. package/dist/context.d.ts.map +1 -0
  15. package/dist/context.js +110 -0
  16. package/dist/context.js.map +1 -0
  17. package/dist/derive.d.ts +110 -0
  18. package/dist/derive.d.ts.map +1 -0
  19. package/dist/derive.js +153 -0
  20. package/dist/derive.js.map +1 -0
  21. package/dist/destination.d.ts +120 -0
  22. package/dist/destination.d.ts.map +1 -0
  23. package/dist/destination.js +352 -0
  24. package/dist/destination.js.map +1 -0
  25. package/dist/deterministic.d.ts +145 -0
  26. package/dist/deterministic.d.ts.map +1 -0
  27. package/dist/deterministic.js +352 -0
  28. package/dist/deterministic.js.map +1 -0
  29. package/dist/dev-mode.d.ts +177 -0
  30. package/dist/dev-mode.d.ts.map +1 -0
  31. package/dist/dev-mode.js +503 -0
  32. package/dist/dev-mode.js.map +1 -0
  33. package/dist/environment.d.ts +181 -0
  34. package/dist/environment.d.ts.map +1 -0
  35. package/dist/environment.js +558 -0
  36. package/dist/environment.js.map +1 -0
  37. package/dist/errors.d.ts +23 -0
  38. package/dist/errors.d.ts.map +1 -0
  39. package/dist/errors.js +21 -0
  40. package/dist/errors.js.map +1 -0
  41. package/dist/global-state.d.ts +8 -0
  42. package/dist/global-state.d.ts.map +1 -0
  43. package/dist/global-state.js +22 -0
  44. package/dist/global-state.js.map +1 -0
  45. package/dist/hash.d.ts +74 -0
  46. package/dist/hash.d.ts.map +1 -0
  47. package/dist/hash.js +253 -0
  48. package/dist/hash.js.map +1 -0
  49. package/dist/hygiene.d.ts +242 -0
  50. package/dist/hygiene.d.ts.map +1 -0
  51. package/dist/hygiene.js +257 -0
  52. package/dist/hygiene.js.map +1 -0
  53. package/dist/index.d.ts +85 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +233 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/mask.d.ts +51 -0
  58. package/dist/mask.d.ts.map +1 -0
  59. package/dist/mask.js +461 -0
  60. package/dist/mask.js.map +1 -0
  61. package/dist/own-property.d.ts +20 -0
  62. package/dist/own-property.d.ts.map +1 -0
  63. package/dist/own-property.js +34 -0
  64. package/dist/own-property.js.map +1 -0
  65. package/dist/patterns.d.ts +12 -0
  66. package/dist/patterns.d.ts.map +1 -0
  67. package/dist/patterns.js +19 -0
  68. package/dist/patterns.js.map +1 -0
  69. package/dist/policy.d.ts +51 -0
  70. package/dist/policy.d.ts.map +1 -0
  71. package/dist/policy.js +181 -0
  72. package/dist/policy.js.map +1 -0
  73. package/dist/probe.d.ts +141 -0
  74. package/dist/probe.d.ts.map +1 -0
  75. package/dist/probe.js +213 -0
  76. package/dist/probe.js.map +1 -0
  77. package/dist/redact-copy.d.ts +61 -0
  78. package/dist/redact-copy.d.ts.map +1 -0
  79. package/dist/redact-copy.js +217 -0
  80. package/dist/redact-copy.js.map +1 -0
  81. package/dist/redact.d.ts +141 -0
  82. package/dist/redact.d.ts.map +1 -0
  83. package/dist/redact.js +514 -0
  84. package/dist/redact.js.map +1 -0
  85. package/dist/redaction-marker.d.ts +48 -0
  86. package/dist/redaction-marker.d.ts.map +1 -0
  87. package/dist/redaction-marker.js +138 -0
  88. package/dist/redaction-marker.js.map +1 -0
  89. package/dist/redaction-observer.d.ts +108 -0
  90. package/dist/redaction-observer.d.ts.map +1 -0
  91. package/dist/redaction-observer.js +103 -0
  92. package/dist/redaction-observer.js.map +1 -0
  93. package/dist/redaction-scope.d.ts +21 -0
  94. package/dist/redaction-scope.d.ts.map +1 -0
  95. package/dist/redaction-scope.js +44 -0
  96. package/dist/redaction-scope.js.map +1 -0
  97. package/dist/reference.d.ts +101 -0
  98. package/dist/reference.d.ts.map +1 -0
  99. package/dist/reference.js +123 -0
  100. package/dist/reference.js.map +1 -0
  101. package/dist/regexp.d.ts +25 -0
  102. package/dist/regexp.d.ts.map +1 -0
  103. package/dist/regexp.js +61 -0
  104. package/dist/regexp.js.map +1 -0
  105. package/dist/release.d.ts +88 -0
  106. package/dist/release.d.ts.map +1 -0
  107. package/dist/release.js +108 -0
  108. package/dist/release.js.map +1 -0
  109. package/dist/reveal-budget.d.ts +148 -0
  110. package/dist/reveal-budget.d.ts.map +1 -0
  111. package/dist/reveal-budget.js +314 -0
  112. package/dist/reveal-budget.js.map +1 -0
  113. package/dist/revocation.d.ts +168 -0
  114. package/dist/revocation.d.ts.map +1 -0
  115. package/dist/revocation.js +541 -0
  116. package/dist/revocation.js.map +1 -0
  117. package/dist/sealing.d.ts +283 -0
  118. package/dist/sealing.d.ts.map +1 -0
  119. package/dist/sealing.js +523 -0
  120. package/dist/sealing.js.map +1 -0
  121. package/dist/sensitive-string.d.ts +919 -0
  122. package/dist/sensitive-string.d.ts.map +1 -0
  123. package/dist/sensitive-string.js +2260 -0
  124. package/dist/sensitive-string.js.map +1 -0
  125. package/dist/serialized.d.ts +33 -0
  126. package/dist/serialized.d.ts.map +1 -0
  127. package/dist/serialized.js +65 -0
  128. package/dist/serialized.js.map +1 -0
  129. package/dist/template.d.ts +69 -0
  130. package/dist/template.d.ts.map +1 -0
  131. package/dist/template.js +158 -0
  132. package/dist/template.js.map +1 -0
  133. package/dist/ttl.d.ts +104 -0
  134. package/dist/ttl.d.ts.map +1 -0
  135. package/dist/ttl.js +330 -0
  136. package/dist/ttl.js.map +1 -0
  137. package/dist/types.d.ts +859 -0
  138. package/dist/types.d.ts.map +1 -0
  139. package/dist/types.js +13 -0
  140. package/dist/types.js.map +1 -0
  141. package/dist/winston.d.ts +114 -0
  142. package/dist/winston.d.ts.map +1 -0
  143. package/dist/winston.js +170 -0
  144. package/dist/winston.js.map +1 -0
  145. package/dist/worker.d.ts +398 -0
  146. package/dist/worker.d.ts.map +1 -0
  147. package/dist/worker.js +861 -0
  148. package/dist/worker.js.map +1 -0
  149. package/dist/wrap.d.ts +287 -0
  150. package/dist/wrap.d.ts.map +1 -0
  151. package/dist/wrap.js +553 -0
  152. package/dist/wrap.js.map +1 -0
  153. package/package.json +10 -10
@@ -0,0 +1,523 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sealing = exports.SealedValueIntegrityError = exports.SealingKeyDestroyedError = exports.SealingUnavailableError = void 0;
4
+ exports.additionalData = additionalData;
5
+ exports.sealBytes = sealBytes;
6
+ exports.openBox = openBox;
7
+ exports.utf8CodeUnits = utf8CodeUnits;
8
+ exports.setSealing = setSealing;
9
+ exports.getSealing = getSealing;
10
+ exports.destroySealingKey = destroySealingKey;
11
+ exports.resetSealing = resetSealing;
12
+ exports.setSealingLimits = setSealingLimits;
13
+ exports.sealingRingState = sealingRingState;
14
+ const node_crypto_1 = require("node:crypto");
15
+ const global_state_js_1 = require("./global-state.js");
16
+ const errors_js_1 = require("./errors.js");
17
+ /**
18
+ * Holding the value as ciphertext instead of as a string, and what that is
19
+ * worth, which is narrower and stranger than the phrase suggests.
20
+ *
21
+ * The key is in the same process as the ciphertext. Nothing here survives the
22
+ * process, nothing here protects a value the process is currently using, and
23
+ * this is not encryption at rest. State that first, because the name invites
24
+ * the opposite reading.
25
+ *
26
+ * Encryption is also not what keeps the plaintext out of a heap snapshot. A
27
+ * `Buffer`'s bytes are external to the V8 heap and a snapshot never records
28
+ * them, so `Buffer.from(value)` achieves that on its own with no key involved.
29
+ * What the key adds is three things a plain buffer cannot do:
30
+ *
31
+ * - Zeroing 32 bytes makes every sealed value in the process permanently
32
+ * unreadable, in constant time, with no registry of instances to walk and no
33
+ * way for an instance to be missed. `clearAllSensitiveValues()` needs an
34
+ * opt-in `WeakRef` registry whose pruning lags collection, and it reaches
35
+ * only what it tracked.
36
+ * - The resident bytes are not the value. A disclosure channel that carries
37
+ * bytes rather than the class's redacted rendering, a buffer written to a
38
+ * log or serialized by a crash reporter, carries ciphertext.
39
+ * - The stored form is bytes, so `clear()` can zero it and `equals()` can
40
+ * compare without materializing a string. Strings can do neither, ever.
41
+ *
42
+ * The cost is real and is stated on the `sealed` option: a read runs a cipher
43
+ * where an unsealed one reads a field, and every string-returning reveal leaves
44
+ * one copy of the plaintext in process memory that garbage collection does not
45
+ * remove. `revealBytes()` and `equals()` are the paths that leave nothing, and
46
+ * a value read repeatedly should use them. `__benchmarks__/sealing.bench.ts`
47
+ * prices each shape against its unsealed twin.
48
+ */
49
+ /** AES-256-GCM: 32-byte key, 96-bit IV, 128-bit tag. */
50
+ const KEY_BYTES = 32;
51
+ const IV_BYTES = 12;
52
+ const TAG_BYTES = 16;
53
+ const GENERATION_BYTES = 4;
54
+ /** The smallest well-formed box: a header, an IV, no ciphertext, and a tag. */
55
+ const MIN_BOX_BYTES = GENERATION_BYTES + IV_BYTES + TAG_BYTES;
56
+ /**
57
+ * Seals allowed under one key before a new generation is started.
58
+ *
59
+ * NIST SP 800-38D section 8.3 puts the limit on random 96-bit IVs under a
60
+ * fixed key at 2^32 invocations. At the measured seal rate a process sealing
61
+ * continuously reaches it in under nine hours, which is not a theoretical
62
+ * bound for a long-lived service, so it is enforced rather than noted.
63
+ */
64
+ const DEFAULT_SEAL_BUDGET = 2 ** 32;
65
+ /**
66
+ * Generations the ring may hold, bounded by what the box header can address.
67
+ *
68
+ * With the budget above this is 2^64 seals before sealing stops being
69
+ * available. It will not be reached; the bound exists so the failure is a
70
+ * named error rather than a silently truncated generation index.
71
+ */
72
+ const DEFAULT_MAX_GENERATIONS = 0xffffffff + 1;
73
+ /**
74
+ * Raised when `sealed: true` was asked for and this process cannot seal.
75
+ *
76
+ * One reason today. It is a class rather than a boolean because the reason is
77
+ * what a caller would act on, and because a second reason would otherwise
78
+ * arrive as a message change.
79
+ */
80
+ class SealingUnavailableError extends errors_js_1.SensitiveStringError {
81
+ reason;
82
+ label;
83
+ name = 'SealingUnavailableError';
84
+ code = 'sealing-unavailable';
85
+ constructor(reason, label) {
86
+ super(`Cannot seal sensitive value${label !== undefined ? ` '${label}'` : ''}: ` +
87
+ `sealing is unavailable (${reason})`);
88
+ this.reason = reason;
89
+ this.label = label;
90
+ }
91
+ }
92
+ exports.SealingUnavailableError = SealingUnavailableError;
93
+ /**
94
+ * Raised when the generation a value was sealed under has been destroyed.
95
+ *
96
+ * Distinguished from {@link SealedValueIntegrityError} so a caller can tell an
97
+ * incident-response key destruction from a tampered box. Generation indices are
98
+ * never reused within a process, so the ring can always tell the two apart.
99
+ */
100
+ class SealingKeyDestroyedError extends errors_js_1.SensitiveStringError {
101
+ destroyedAt;
102
+ attemptedAt;
103
+ label;
104
+ name = 'SealingKeyDestroyedError';
105
+ code = 'sealing-key-destroyed';
106
+ constructor(destroyedAt, attemptedAt, label) {
107
+ super(`Sealing key for sensitive value${label !== undefined ? ` '${label}'` : ''} was ` +
108
+ `destroyed at ${destroyedAt.toISOString()}`);
109
+ this.destroyedAt = destroyedAt;
110
+ this.attemptedAt = attemptedAt;
111
+ this.label = label;
112
+ }
113
+ /** Milliseconds between the destruction and the attempted access. */
114
+ get destroyedFor() {
115
+ return this.attemptedAt.getTime() - this.destroyedAt.getTime();
116
+ }
117
+ }
118
+ exports.SealingKeyDestroyedError = SealingKeyDestroyedError;
119
+ /**
120
+ * Raised when a sealed value's box fails authentication.
121
+ *
122
+ * In practice this means the instance was tampered with. `klass` and `label`
123
+ * are bound into the GCM additional data, so rewriting either makes the value
124
+ * unreadable rather than reclassified: the runtime write that downgrades a
125
+ * credential to a class with weaker redaction and no constant-time comparison
126
+ * succeeds on an unsealed value and fails closed here.
127
+ *
128
+ * It deliberately does not carry OpenSSL's message. Node's is "Unsupported
129
+ * state or unable to authenticate data", which says nothing useful, and a
130
+ * runtime's own diagnostic is not something a security wrapper should re-raise
131
+ * unread.
132
+ */
133
+ class SealedValueIntegrityError extends errors_js_1.SensitiveStringError {
134
+ label;
135
+ name = 'SealedValueIntegrityError';
136
+ code = 'sealed-value-integrity';
137
+ constructor(label) {
138
+ super(`Sealed sensitive value${label !== undefined ? ` '${label}'` : ''} failed ` +
139
+ `authentication: the stored box, its class or its label was modified`);
140
+ this.label = label;
141
+ }
142
+ }
143
+ exports.SealedValueIntegrityError = SealedValueIntegrityError;
144
+ const DEFAULTS = Object.freeze({
145
+ sealByDefault: false,
146
+ strict: true,
147
+ });
148
+ /**
149
+ * The one ring and configuration every physical copy of core shares.
150
+ *
151
+ * Exported for `sensitive-string.ts`, which reads `config` on the construction
152
+ * path: one property chain rather than a call through an accessor, which is
153
+ * what a process that never seals anything pays for the feature.
154
+ *
155
+ * @internal
156
+ */
157
+ exports.sealing = (0, global_state_js_1.getGlobalSingleton)('memory-sealing', () => ({
158
+ config: DEFAULTS,
159
+ generations: [],
160
+ budget: DEFAULT_SEAL_BUDGET,
161
+ maxGenerations: DEFAULT_MAX_GENERATIONS,
162
+ }));
163
+ /**
164
+ * The generation to seal under, starting a new one when the current is spent
165
+ * or destroyed.
166
+ *
167
+ * Charges the seal here rather than after the cipher runs, so a `createCipheriv`
168
+ * that throws cannot leave a nonce budget uncharged for an IV that was drawn.
169
+ */
170
+ function currentGeneration(label) {
171
+ const ring = exports.sealing.generations;
172
+ const last = ring.length === 0 ? undefined : ring[ring.length - 1];
173
+ if (last !== undefined && last.destroyed === undefined && last.seals < exports.sealing.budget) {
174
+ last.seals += 1;
175
+ return last;
176
+ }
177
+ if (ring.length >= exports.sealing.maxGenerations) {
178
+ throw new SealingUnavailableError('generations-exhausted', label);
179
+ }
180
+ const next = {
181
+ index: ring.length,
182
+ key: (0, node_crypto_1.randomBytes)(KEY_BYTES),
183
+ seals: 1,
184
+ destroyed: undefined,
185
+ };
186
+ ring.push(next);
187
+ return next;
188
+ }
189
+ /**
190
+ * The GCM additional data binding a box to the instance's classification.
191
+ *
192
+ * `klass || 0x00 || present || label`. The discriminator byte is there because
193
+ * a missing label and an empty one must not produce the same additional data,
194
+ * which they would if the separator alone divided them.
195
+ *
196
+ * @internal
197
+ */
198
+ function additionalData(klass, label) {
199
+ return Buffer.concat([
200
+ Buffer.from(klass, 'utf8'),
201
+ Buffer.from([0x00, label === undefined ? 0x00 : 0x01]),
202
+ label === undefined ? Buffer.alloc(0) : Buffer.from(label, 'utf8'),
203
+ ]);
204
+ }
205
+ /**
206
+ * Encrypt bytes into a box: `generation || iv || ciphertext || tag`.
207
+ *
208
+ * The caller owns `plain` and decides when to zero it; this function reads it
209
+ * and nothing else. 32 bytes of overhead, one allocation.
210
+ *
211
+ * @internal
212
+ */
213
+ function sealBytes(plain, aad, label) {
214
+ const generation = currentGeneration(label);
215
+ const iv = (0, node_crypto_1.randomBytes)(IV_BYTES);
216
+ const cipher = (0, node_crypto_1.createCipheriv)('aes-256-gcm', generation.key, iv);
217
+ cipher.setAAD(aad);
218
+ const header = Buffer.alloc(GENERATION_BYTES);
219
+ header.writeUInt32BE(generation.index, 0);
220
+ // Evaluated left to right, which is the order GCM requires: the tag is only
221
+ // available once `final()` has run.
222
+ return Buffer.concat([header, iv, cipher.update(plain), cipher.final(), cipher.getAuthTag()]);
223
+ }
224
+ /**
225
+ * Decrypt a box back into bytes the caller owns and may zero.
226
+ *
227
+ * Never returns a string. The two callers decide whether one is wanted, which
228
+ * is the whole point of the split: `equals()` and `revealBytes()` never make
229
+ * one, and section 2.3 of the design measures that as the difference between
230
+ * leaving a thousand plaintext copies in process memory and leaving none.
231
+ *
232
+ * @internal
233
+ */
234
+ function openBox(box, aad, label) {
235
+ if (box.length < MIN_BOX_BYTES) {
236
+ throw new SealedValueIntegrityError(label);
237
+ }
238
+ const generation = exports.sealing.generations[box.readUInt32BE(0)];
239
+ if (generation === undefined) {
240
+ // A box from a ring this process no longer has, which `resetSealing()` is
241
+ // the only way to produce. Reported as tampering rather than as a
242
+ // destruction, because the key that would have opened it is not merely
243
+ // zeroed: there is no record that it ever existed.
244
+ throw new SealedValueIntegrityError(label);
245
+ }
246
+ if (generation.destroyed !== undefined) {
247
+ throw new SealingKeyDestroyedError(generation.destroyed, new Date(), label);
248
+ }
249
+ // GCM produces plaintext before it verifies the tag, so this holds real bytes
250
+ // even on the path that is about to be refused. It is tracked from here so
251
+ // the `finally` can zero it, and released to `undefined` at the one point
252
+ // where it becomes the caller's to own.
253
+ let unauthenticated;
254
+ try {
255
+ const decipher = (0, node_crypto_1.createDecipheriv)('aes-256-gcm', generation.key, box.subarray(GENERATION_BYTES, GENERATION_BYTES + IV_BYTES));
256
+ decipher.setAAD(aad);
257
+ decipher.setAuthTag(box.subarray(box.length - TAG_BYTES));
258
+ unauthenticated = decipher.update(box.subarray(GENERATION_BYTES + IV_BYTES, box.length - TAG_BYTES));
259
+ const tail = decipher.final();
260
+ if (tail.length === 0) {
261
+ // The ordinary path for GCM, which has no block padding: `update`
262
+ // returned everything. Handing that buffer over directly is one fewer
263
+ // copy of the plaintext than concatenating would leave behind.
264
+ const opened = unauthenticated;
265
+ unauthenticated = undefined;
266
+ return opened;
267
+ }
268
+ const opened = Buffer.concat([unauthenticated, tail]);
269
+ tail.fill(0);
270
+ return opened;
271
+ }
272
+ catch {
273
+ // Every failure in this block is reported the same way, and none of them
274
+ // carries the runtime's own text. `final()` failing is the tag check and is
275
+ // the expected one; anything else here is a malformed box that got past the
276
+ // length guard, and OpenSSL's diagnostic for either says nothing a caller
277
+ // can act on.
278
+ throw new SealedValueIntegrityError(label);
279
+ }
280
+ finally {
281
+ unauthenticated?.fill(0);
282
+ }
283
+ }
284
+ /** Whether a byte is a UTF-8 continuation. */
285
+ function isContinuation(byte) {
286
+ return byte !== undefined && (byte & 0xc0) === 0x80;
287
+ }
288
+ function invalidUtf8(offset) {
289
+ return new TypeError(`SensitiveString.fromBuffer expects valid UTF-8; the sequence at byte ${offset} is not`);
290
+ }
291
+ /**
292
+ * Validate UTF-8 and count the UTF-16 code units it decodes to, in one walk.
293
+ *
294
+ * Both halves have to happen without decoding. `length` on a sealed value must
295
+ * agree with `length` on an unsealed one, which is a code unit count, and the
296
+ * obvious validator, `new TextDecoder('utf-8', { fatal: true }).decode(bytes)`,
297
+ * produces exactly the plaintext string `fromBuffer` exists to avoid.
298
+ *
299
+ * Strict: overlong encodings, surrogate code points and anything above
300
+ * U+10FFFF are refused rather than replaced. A lenient decoder would substitute
301
+ * U+FFFD, which changes both the value a later `reveal()` returns and its
302
+ * length, so a caller would get back something other than what it passed.
303
+ *
304
+ * @internal
305
+ */
306
+ function utf8CodeUnits(bytes) {
307
+ let units = 0;
308
+ let at = 0;
309
+ while (at < bytes.length) {
310
+ const lead = bytes[at];
311
+ if (lead < 0x80) {
312
+ at += 1;
313
+ units += 1;
314
+ continue;
315
+ }
316
+ // 0xc0 and 0xc1 can only encode a value below U+0080, which is overlong.
317
+ if (lead >= 0xc2 && lead <= 0xdf) {
318
+ if (!isContinuation(bytes[at + 1])) {
319
+ throw invalidUtf8(at);
320
+ }
321
+ at += 2;
322
+ units += 1;
323
+ continue;
324
+ }
325
+ if (lead >= 0xe0 && lead <= 0xef) {
326
+ // 0xe0 below 0xa0 is overlong; 0xed at 0xa0 or above is a surrogate.
327
+ const low = lead === 0xe0 ? 0xa0 : 0x80;
328
+ const high = lead === 0xed ? 0x9f : 0xbf;
329
+ const second = bytes[at + 1];
330
+ if (second === undefined || second < low || second > high) {
331
+ throw invalidUtf8(at);
332
+ }
333
+ if (!isContinuation(bytes[at + 2])) {
334
+ throw invalidUtf8(at);
335
+ }
336
+ at += 3;
337
+ units += 1;
338
+ continue;
339
+ }
340
+ if (lead >= 0xf0 && lead <= 0xf4) {
341
+ // 0xf0 below 0x90 is overlong; 0xf4 at 0x90 or above is beyond U+10FFFF.
342
+ const low = lead === 0xf0 ? 0x90 : 0x80;
343
+ const high = lead === 0xf4 ? 0x8f : 0xbf;
344
+ const second = bytes[at + 1];
345
+ if (second === undefined || second < low || second > high) {
346
+ throw invalidUtf8(at);
347
+ }
348
+ if (!isContinuation(bytes[at + 2]) || !isContinuation(bytes[at + 3])) {
349
+ throw invalidUtf8(at);
350
+ }
351
+ at += 4;
352
+ // Beyond the basic plane, so it decodes to a surrogate pair.
353
+ units += 2;
354
+ continue;
355
+ }
356
+ throw invalidUtf8(at);
357
+ }
358
+ return units;
359
+ }
360
+ function describeType(value) {
361
+ return value === null ? 'null' : typeof value;
362
+ }
363
+ function requireBoolean(value, name, fallback) {
364
+ if (value === undefined) {
365
+ return fallback;
366
+ }
367
+ if (typeof value !== 'boolean') {
368
+ throw new TypeError(`setSealing: ${name} must be a boolean, received ${describeType(value)}`);
369
+ }
370
+ return value;
371
+ }
372
+ /**
373
+ * Configure sealing for this process. Merges: an unset field is left as it was.
374
+ *
375
+ * `sealByDefault` is read at construction, so this belongs in the entry module
376
+ * beside `registerPolicy`, before anything wraps a value. A value built before
377
+ * this call is not sealed, and there is no way to retrofit sealing onto it.
378
+ *
379
+ * Per-isolate, like every other process-global in this library: a worker thread
380
+ * has its own `globalThis`, so its own configuration and its own keys. A box
381
+ * cannot travel between isolates, and nothing tries to send one.
382
+ *
383
+ * @param config - The switches to change.
384
+ * @throws TypeError If the configuration, or one of its fields, has the wrong type.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * setSealing({ sealByDefault: true });
389
+ * ```
390
+ */
391
+ function setSealing(config) {
392
+ if (typeof config !== 'object' || config === null) {
393
+ throw new TypeError(`setSealing expects a configuration object; received ${describeType(config)}`);
394
+ }
395
+ const current = exports.sealing.config;
396
+ exports.sealing.config = Object.freeze({
397
+ sealByDefault: requireBoolean(config.sealByDefault, 'sealByDefault', current.sealByDefault),
398
+ strict: requireBoolean(config.strict, 'strict', current.strict),
399
+ });
400
+ }
401
+ /**
402
+ * The configuration in force, with every default resolved.
403
+ *
404
+ * A frozen copy of the live object rather than the object itself, so a caller
405
+ * cannot reconfigure the process by writing to what it reads back. The result
406
+ * is accepted by {@link setSealing}, so it can be saved and restored.
407
+ */
408
+ function getSealing() {
409
+ const { sealByDefault, strict } = exports.sealing.config;
410
+ return Object.freeze({ sealByDefault, strict });
411
+ }
412
+ /**
413
+ * Zero every sealing key this process holds.
414
+ *
415
+ * Every value sealed under them becomes permanently unreadable, including
416
+ * values other libraries in this process constructed. Constant time, no
417
+ * instance registry, and no instance can be missed, which is what this has
418
+ * over {@link clearAllSensitiveValues}: that walks an opt-in `WeakRef` set
419
+ * whose pruning lags collection and reaches only what it tracked.
420
+ *
421
+ * Values sealed after this call use a fresh generation and are unaffected, so
422
+ * it is safe in a handler that runs while the process is still serving.
423
+ *
424
+ * What it does not reach: plaintext that earlier string-returning reveals left
425
+ * in process memory, unsealed values, and the expanded key schedules OpenSSL
426
+ * built in freed allocator memory during earlier operations. The last is a real
427
+ * caveat rather than a formality: an AES key schedule is an expansion of the
428
+ * key, not a copy of it, and recovering one from the other is arithmetic. The
429
+ * claim this call supports is that no copy of the 32 key bytes remains, which
430
+ * was measured; it is not that erasure is total.
431
+ *
432
+ * Idempotent. Produces no audit record, because it reads no value and has no
433
+ * value to name in one: a process that wants a record of an incident-response
434
+ * key destruction logs it at the call site, where the reason is known.
435
+ *
436
+ * @example
437
+ * ```ts
438
+ * process.on('SIGTERM', async () => {
439
+ * await server.close(); // stop accepting, drain what is in flight
440
+ * await pool.end(); // nothing still needs a credential
441
+ * destroySealingKey(); // every sealed value in the process is now dead
442
+ * });
443
+ * ```
444
+ */
445
+ function destroySealingKey() {
446
+ const now = new Date();
447
+ for (const generation of exports.sealing.generations) {
448
+ if (generation.destroyed === undefined) {
449
+ generation.key.fill(0);
450
+ generation.destroyed = now;
451
+ }
452
+ }
453
+ }
454
+ /**
455
+ * Restore the defaults, zero every key and empty the ring.
456
+ *
457
+ * Test-only, and gated exactly as `resetPolicies()` is: it undoes process-wide
458
+ * configuration, so a production caller reaching for it is describing a bug.
459
+ *
460
+ * One difference from {@link destroySealingKey} is worth knowing before a test
461
+ * relies on it. Emptying the ring is the one thing in this module that reuses a
462
+ * generation index, so a value sealed before the reset reports
463
+ * {@link SealedValueIntegrityError} rather than {@link SealingKeyDestroyedError}
464
+ * afterwards. Both refuse; only the second names what happened. A test that
465
+ * wants the second must call `destroySealingKey()` instead.
466
+ */
467
+ function resetSealing() {
468
+ exports.sealing.config = DEFAULTS;
469
+ for (const generation of exports.sealing.generations) {
470
+ generation.key.fill(0);
471
+ }
472
+ exports.sealing.generations.length = 0;
473
+ exports.sealing.budget = DEFAULT_SEAL_BUDGET;
474
+ exports.sealing.maxGenerations = DEFAULT_MAX_GENERATIONS;
475
+ }
476
+ /**
477
+ * Lower the nonce budget and the ring size so the generation machinery can be
478
+ * driven in a test.
479
+ *
480
+ * Test-only, `@internal`, and deliberately absent from `index.ts`: crossing
481
+ * 2^32 seals or 2^32 generations honestly takes hours and millennia
482
+ * respectively, and a feature nothing can reach is a feature nothing has
483
+ * checked. Neither limit may be raised above its default, because the budget
484
+ * is a nonce-reuse bound rather than a tuning knob.
485
+ *
486
+ * Undone by {@link resetSealing}.
487
+ *
488
+ * @internal
489
+ */
490
+ function setSealingLimits(limits) {
491
+ if (limits.budget !== undefined) {
492
+ if (!Number.isInteger(limits.budget) || limits.budget < 1) {
493
+ throw new RangeError('setSealingLimits: budget must be a positive integer');
494
+ }
495
+ exports.sealing.budget = Math.min(limits.budget, DEFAULT_SEAL_BUDGET);
496
+ }
497
+ if (limits.generations !== undefined) {
498
+ if (!Number.isInteger(limits.generations) || limits.generations < 1) {
499
+ throw new RangeError('setSealingLimits: generations must be a positive integer');
500
+ }
501
+ exports.sealing.maxGenerations = Math.min(limits.generations, DEFAULT_MAX_GENERATIONS);
502
+ }
503
+ }
504
+ /**
505
+ * How many generations the ring holds, and how many seals the current one has
506
+ * charged.
507
+ *
508
+ * Not part of the public surface: it reports the shape of the key ring, which
509
+ * is an implementation detail everywhere except in the suite that measures the
510
+ * generation rollover.
511
+ *
512
+ * @internal
513
+ */
514
+ function sealingRingState() {
515
+ const ring = exports.sealing.generations;
516
+ const last = ring.length === 0 ? undefined : ring[ring.length - 1];
517
+ return {
518
+ generations: ring.length,
519
+ seals: last?.seals ?? 0,
520
+ destroyed: ring.filter((generation) => generation.destroyed !== undefined).length,
521
+ };
522
+ }
523
+ //# sourceMappingURL=sealing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sealing.js","sourceRoot":"","sources":["../src/sealing.ts"],"names":[],"mappings":";;;AA+QA,wCAMC;AAUD,8BAYC;AAYD,0BA8DC;AA4BD,sCAmEC;AAqCD,gCAaC;AASD,gCAGC;AAmCD,8CASC;AAeD,oCAUC;AAgBD,4CAgBC;AAYD,4CASC;AA5oBD,6CAA4E;AAC5E,uDAAuD;AACvD,2CAAmD;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,wDAAwD;AACxD,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,+EAA+E;AAC/E,MAAM,aAAa,GAAG,gBAAgB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,uBAAuB,GAAG,UAAU,GAAG,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,MAAa,uBAAwB,SAAQ,gCAAoB;IAKpD;IACA;IALO,IAAI,GAAG,yBAAyB,CAAC;IACjC,IAAI,GAAG,qBAAqB,CAAC;IAE/C,YACW,MAA+B,EAC/B,KAAc;QAEvB,KAAK,CACH,8BAA8B,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,IAA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