@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,503 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.devMode = void 0;
4
+ exports.setDevMode = setDevMode;
5
+ exports.getDevModeConfig = getDevModeConfig;
6
+ exports.withDevMode = withDevMode;
7
+ exports.recordCreation = recordCreation;
8
+ exports.recordReveal = recordReveal;
9
+ exports.readDevInfo = readDevInfo;
10
+ const global_state_js_1 = require("./global-state.js");
11
+ const mask_js_1 = require("./mask.js");
12
+ /**
13
+ * What a value's own history was, for the engineer debugging it.
14
+ *
15
+ * A reveal that fails, or one that should never have happened, says nothing
16
+ * about where the value came from or how often it has been read: a stack trace
17
+ * names the caller of `reveal()` and nothing else. Development mode records
18
+ * that history next to the value, behind a flag that is off by default. Every
19
+ * path it adds begins with the same guard, so a process that never turns it on
20
+ * pays one property read per construction and one per exposure.
21
+ *
22
+ * Nothing here is meant for production. The partial rendering in particular is
23
+ * a deliberate, opt-in disclosure of the first few characters of a value, which
24
+ * is exactly what the rest of this library exists to prevent; it is bounded by
25
+ * the same floor `mask()` enforces, so it can never show more of a value than a
26
+ * mask of the same class would.
27
+ */
28
+ /**
29
+ * The most characters a partial rendering may ever show.
30
+ *
31
+ * A cap rather than a warning, because the option exists to tell two values
32
+ * apart while debugging and no amount of prefix beyond a handful helps with
33
+ * that. It is a ceiling on the option, not on the disclosure: the class floor
34
+ * below can lower it further and often does.
35
+ */
36
+ const MAX_PARTIAL_LENGTH = 8;
37
+ /** Characters a partial rendering shows when the caller does not choose. */
38
+ const DEFAULT_PARTIAL_LENGTH = 4;
39
+ /**
40
+ * Reveal times retained per value.
41
+ *
42
+ * A ring, so a value revealed in a loop for an hour holds a fixed amount of
43
+ * memory rather than one number per read. `revealCount` stays exact; only the
44
+ * timestamps are forgotten, oldest first.
45
+ */
46
+ const TIMESTAMP_CAPACITY = 64;
47
+ /** What a stack renders as when the runtime supplied none. */
48
+ const NO_STACK = ' (no stack available)';
49
+ const DISABLED = Object.freeze({
50
+ enabled: false,
51
+ captureStackTraces: false,
52
+ captureCreationStack: false,
53
+ warnOnMissingContext: false,
54
+ repeated: undefined,
55
+ log: Object.freeze({
56
+ enabled: false,
57
+ logger: undefined,
58
+ showPartialValue: false,
59
+ partialLength: DEFAULT_PARTIAL_LENGTH,
60
+ }),
61
+ });
62
+ /**
63
+ * Process-global, for the reason the policy registry is: an application that
64
+ * resolves two physical copies of core must not have to configure each one.
65
+ */
66
+ exports.devMode = (0, global_state_js_1.getGlobalSingleton)('dev-mode', () => ({
67
+ config: DISABLED,
68
+ records: new WeakMap(),
69
+ }));
70
+ /**
71
+ * Describe a rejected option without disclosing it.
72
+ */
73
+ function describeType(value) {
74
+ return value === null ? 'null' : typeof value;
75
+ }
76
+ function requireBoolean(value, name, fallback) {
77
+ if (value === undefined) {
78
+ return fallback;
79
+ }
80
+ if (typeof value !== 'boolean') {
81
+ throw new TypeError(`setDevMode: ${name} must be a boolean, received ${describeType(value)}`);
82
+ }
83
+ return value;
84
+ }
85
+ function requireLogger(value) {
86
+ if (value === undefined) {
87
+ return undefined;
88
+ }
89
+ if (typeof value !== 'function') {
90
+ throw new TypeError(`setDevMode: logReveals.logger must be a function, received ${describeType(value)}`);
91
+ }
92
+ return value;
93
+ }
94
+ function requirePartialLength(value) {
95
+ if (value === undefined) {
96
+ return DEFAULT_PARTIAL_LENGTH;
97
+ }
98
+ if (typeof value !== 'number') {
99
+ throw new TypeError(`setDevMode: logReveals.partialLength must be a number, received ${describeType(value)}`);
100
+ }
101
+ if (!Number.isInteger(value) || value < 0) {
102
+ throw new RangeError('setDevMode: logReveals.partialLength must be a non-negative integer');
103
+ }
104
+ if (value > MAX_PARTIAL_LENGTH) {
105
+ throw new RangeError(`setDevMode: logReveals.partialLength ${value} exceeds the cap of ${MAX_PARTIAL_LENGTH}; ` +
106
+ 'a longer prefix does not help tell two values apart and discloses more of both');
107
+ }
108
+ return value;
109
+ }
110
+ function resolveRepeated(value) {
111
+ if (value === undefined || value === false) {
112
+ return undefined;
113
+ }
114
+ if (typeof value !== 'object' || value === null) {
115
+ throw new TypeError(`setDevMode: warnOnRepeatedReveal must be an object or false, received ${describeType(value)}`);
116
+ }
117
+ const { threshold, window } = value;
118
+ if (typeof threshold !== 'number' || typeof window !== 'number') {
119
+ throw new TypeError('setDevMode: warnOnRepeatedReveal requires a numeric threshold and window');
120
+ }
121
+ if (!Number.isInteger(threshold) || threshold < 1) {
122
+ throw new RangeError('setDevMode: warnOnRepeatedReveal.threshold must be an integer of at least 1');
123
+ }
124
+ if (!Number.isFinite(window) || window <= 0) {
125
+ throw new RangeError('setDevMode: warnOnRepeatedReveal.window must be a positive, finite number of milliseconds');
126
+ }
127
+ return Object.freeze({ threshold, window });
128
+ }
129
+ function resolveLog(value) {
130
+ if (value === undefined || value === false) {
131
+ return DISABLED.log;
132
+ }
133
+ if (typeof value !== 'object' || value === null) {
134
+ throw new TypeError(`setDevMode: logReveals must be an object or false, received ${describeType(value)}`);
135
+ }
136
+ const options = value;
137
+ if (typeof options.enabled !== 'boolean') {
138
+ throw new TypeError(`setDevMode: logReveals.enabled must be a boolean, received ${describeType(options.enabled)}`);
139
+ }
140
+ return Object.freeze({
141
+ enabled: options.enabled,
142
+ logger: requireLogger(options.logger),
143
+ showPartialValue: requireBoolean(options.showPartialValue, 'logReveals.showPartialValue', false),
144
+ partialLength: requirePartialLength(options.partialLength),
145
+ });
146
+ }
147
+ function resolve(config) {
148
+ if (typeof config !== 'object' || config === null) {
149
+ throw new TypeError(`setDevMode expects a configuration object; received ${describeType(config)}`);
150
+ }
151
+ if (typeof config.enabled !== 'boolean') {
152
+ throw new TypeError(`setDevMode: enabled must be a boolean, received ${describeType(config.enabled)}`);
153
+ }
154
+ return Object.freeze({
155
+ enabled: config.enabled,
156
+ captureStackTraces: requireBoolean(config.captureStackTraces, 'captureStackTraces', false),
157
+ captureCreationStack: requireBoolean(config.captureCreationStack, 'captureCreationStack', false),
158
+ warnOnMissingContext: requireBoolean(config.warnOnMissingContext, 'warnOnMissingContext', false),
159
+ repeated: resolveRepeated(config.warnOnRepeatedReveal),
160
+ log: resolveLog(config.logReveals),
161
+ });
162
+ }
163
+ /**
164
+ * Configure development mode. Off until this is called with `enabled: true`.
165
+ *
166
+ * A value records nothing about a period during which development mode was off,
167
+ * so turn it on before constructing the values you intend to inspect.
168
+ *
169
+ * @param config - The configuration. Options are resolved and validated here, so a malformed one is rejected at the call rather than inside a later reveal.
170
+ * @throws TypeError If the configuration, or one of its options, has the wrong type.
171
+ * @throws RangeError If a count is out of range.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * if (process.env['NODE_ENV'] === 'development') {
176
+ * setDevMode({
177
+ * enabled: true,
178
+ * captureStackTraces: true,
179
+ * warnOnMissingContext: true,
180
+ * logReveals: { enabled: true, showPartialValue: true },
181
+ * });
182
+ * }
183
+ * ```
184
+ */
185
+ function setDevMode(config) {
186
+ const resolved = resolve(config);
187
+ if (resolved.enabled && process.env['NODE_ENV'] === 'production') {
188
+ // Deliberately `console.warn` and not the configured logger: what is being
189
+ // reported is the configuration itself, so routing it through a sink that
190
+ // same configuration just named would be the one place it could be missed.
191
+ // eslint-disable-next-line no-console -- see above
192
+ console.warn('[SensitiveString] Dev mode enabled in production! This is a security risk: it records ' +
193
+ 'stacks and, with showPartialValue, writes part of every revealed value to a log.');
194
+ }
195
+ exports.devMode.config = resolved;
196
+ }
197
+ /**
198
+ * The current configuration, with every default resolved.
199
+ *
200
+ * The result is frozen and is accepted by {@link setDevMode}, so it can be
201
+ * saved and restored. `false` and an absent option both resolve to the disabled
202
+ * object form, which behaves identically.
203
+ */
204
+ function getDevModeConfig() {
205
+ const config = exports.devMode.config;
206
+ const log = {
207
+ enabled: config.log.enabled,
208
+ showPartialValue: config.log.showPartialValue,
209
+ partialLength: config.log.partialLength,
210
+ ...(config.log.logger !== undefined ? { logger: config.log.logger } : {}),
211
+ };
212
+ return Object.freeze({
213
+ enabled: config.enabled,
214
+ captureStackTraces: config.captureStackTraces,
215
+ captureCreationStack: config.captureCreationStack,
216
+ warnOnMissingContext: config.warnOnMissingContext,
217
+ warnOnRepeatedReveal: config.repeated ?? false,
218
+ logReveals: Object.freeze(log),
219
+ });
220
+ }
221
+ /**
222
+ * Run `fn` with `config` in force, restoring the previous configuration after.
223
+ *
224
+ * Synchronous. The configuration is process-global, so it cannot follow one
225
+ * asynchronous task without following every other task interleaved with it; a
226
+ * function that returns a promise has its configuration restored when it
227
+ * returns, not when it settles.
228
+ */
229
+ function withDevMode(config, fn) {
230
+ const previous = exports.devMode.config;
231
+ setDevMode(config);
232
+ try {
233
+ return fn();
234
+ }
235
+ finally {
236
+ // The resolved object goes back directly: it was validated when it was set,
237
+ // and restoring must not re-emit the production warning.
238
+ exports.devMode.config = previous;
239
+ }
240
+ }
241
+ /**
242
+ * The file this module was loaded from, so its own frames can be dropped from a
243
+ * captured stack.
244
+ *
245
+ * Read from a stack rather than from `import.meta.url`, which does not exist in
246
+ * the CommonJS form this package also emits.
247
+ */
248
+ const OWN_FILE = ownFile();
249
+ function ownFile() {
250
+ // Line 0 is the `Error` header and line 1 is this function's own frame.
251
+ return frameFile(new Error().stack?.split('\n')[1]);
252
+ }
253
+ /**
254
+ * The source file a stack frame names, or undefined when the frame has none.
255
+ */
256
+ function frameFile(frame) {
257
+ if (frame === undefined) {
258
+ return undefined;
259
+ }
260
+ // `at name (/dir/file.js:12:3)`, `at /dir/file.js:12:3`, and the `file://`
261
+ // form ESM produces. The two trailing numbers are the position, so whatever
262
+ // precedes them is the file, drive letter and all.
263
+ return /\(?((?:[A-Za-z]:)?[^()]+?):\d+:\d+\)?\s*$/.exec(frame)?.[1];
264
+ }
265
+ /**
266
+ * Render a captured stack as the caller's frames alone.
267
+ *
268
+ * Two runs of frames sit above the caller: this module's, and those of whichever
269
+ * module called into it, which is the raw-value gate. The gate's file is not
270
+ * known here, so it is taken from the first frame that is not this module's and
271
+ * its contiguous run is dropped with it. Both runs are library code by
272
+ * construction, since nothing outside core calls in.
273
+ *
274
+ * A build that inlines this module and its caller into one file leaves nothing
275
+ * after the filter, and the unfiltered frames are used instead: too much
276
+ * context beats none.
277
+ */
278
+ function formatStack(stack) {
279
+ if (stack === undefined) {
280
+ return NO_STACK;
281
+ }
282
+ const frames = stack.split('\n').slice(1);
283
+ let start = 0;
284
+ if (OWN_FILE !== undefined) {
285
+ while (start < frames.length && frameFile(frames[start]) === OWN_FILE) {
286
+ start += 1;
287
+ }
288
+ const gate = frameFile(frames[start]);
289
+ if (gate !== undefined) {
290
+ while (start < frames.length && frameFile(frames[start]) === gate) {
291
+ start += 1;
292
+ }
293
+ }
294
+ if (start === frames.length) {
295
+ start = 0;
296
+ }
297
+ }
298
+ const kept = frames.slice(start).map((frame) => ` ${frame.trim()}`);
299
+ return kept.length > 0 ? kept.join('\n') : NO_STACK;
300
+ }
301
+ function captureStack() {
302
+ return formatStack(new Error().stack);
303
+ }
304
+ /**
305
+ * Record the construction of a value.
306
+ *
307
+ * Called from the constructor once its arguments have been accepted, so a
308
+ * rejected construction leaves no record behind.
309
+ */
310
+ function recordCreation(instance) {
311
+ const config = exports.devMode.config;
312
+ exports.devMode.records.set(instance, {
313
+ createdAt: Date.now(),
314
+ creationStack: config.captureCreationStack ? captureStack() : undefined,
315
+ revealCount: 0,
316
+ timestamps: [],
317
+ ringNext: 0,
318
+ lastRevealStack: undefined,
319
+ windowStart: 0,
320
+ windowCount: 0,
321
+ });
322
+ }
323
+ function pushTimestamp(record, now) {
324
+ if (record.timestamps.length < TIMESTAMP_CAPACITY) {
325
+ record.timestamps.push(now);
326
+ return;
327
+ }
328
+ record.timestamps[record.ringNext] = now;
329
+ record.ringNext = (record.ringNext + 1) % TIMESTAMP_CAPACITY;
330
+ }
331
+ function readTimestamps(record) {
332
+ if (record.timestamps.length < TIMESTAMP_CAPACITY) {
333
+ return [...record.timestamps];
334
+ }
335
+ return [
336
+ ...record.timestamps.slice(record.ringNext),
337
+ ...record.timestamps.slice(0, record.ringNext),
338
+ ];
339
+ }
340
+ /**
341
+ * The first few characters of a value, or undefined when none may be shown.
342
+ *
343
+ * Bounded twice: by the configured length, and by the same floor on hidden
344
+ * characters that `mask()` enforces for the class. A value short enough that
345
+ * the floor leaves nothing shows nothing, rather than most of itself. Counts
346
+ * are code points, so a prefix never ends inside a surrogate pair.
347
+ */
348
+ function partialValue(value, length, klass) {
349
+ if (length <= 0) {
350
+ return undefined;
351
+ }
352
+ const chars = [...value];
353
+ const shown = Math.min(length, chars.length - (0, mask_js_1.minMaskedFloor)(klass));
354
+ return shown > 0 ? chars.slice(0, shown).join('') : undefined;
355
+ }
356
+ /**
357
+ * Write one line, swallowing whatever the sink does with it.
358
+ *
359
+ * A debugging aid must not change what the program does. Without this, a logger
360
+ * that throws would turn a successful reveal into a failed one, after the audit
361
+ * hook had already recorded it as successful, and only in development: the one
362
+ * environment where the difference would be mistaken for a bug in the caller.
363
+ */
364
+ function emit(config, message) {
365
+ try {
366
+ // eslint-disable-next-line no-console -- the documented default sink for a feature that only runs in development
367
+ const logger = config.log.logger ?? console.warn;
368
+ logger(message);
369
+ }
370
+ catch {
371
+ // See above.
372
+ }
373
+ }
374
+ /**
375
+ * What each exposing operation is called in a development-mode log line.
376
+ *
377
+ * A record rather than a chain of comparisons, so an operation added to
378
+ * `RevealDetails` without a name here falls back to `Reveal` in one place that
379
+ * is easy to find, rather than silently in the middle of a message.
380
+ */
381
+ const EXPOSURE_NAMES = {
382
+ reveal: 'Reveal',
383
+ mask: 'Mask',
384
+ hash: 'Hash',
385
+ hmac: 'HMAC',
386
+ 'worker-handoff': 'Worker handoff',
387
+ };
388
+ function describeValue(klass, label) {
389
+ return `'${label ?? klass}'`;
390
+ }
391
+ /**
392
+ * Log one exposure, when the configuration asks for it.
393
+ *
394
+ * An exposure with no context is reported under `warnOnMissingContext` even
395
+ * when full logging is off, which is the point of that option: the reveals
396
+ * worth seeing first are the ones nothing explains.
397
+ */
398
+ function logExposure(record, klass, label, value, ctx, details, config) {
399
+ const missingContext = ctx === null || ctx === undefined;
400
+ if (!config.log.enabled && !(config.warnOnMissingContext && missingContext)) {
401
+ return;
402
+ }
403
+ // Only the exposing operations reach here, since that is the branch of the
404
+ // gate that records. Naming each of them is the point of the line: a digest
405
+ // logged as a reveal tells a developer their value was handed out when it
406
+ // was not.
407
+ const operation = EXPOSURE_NAMES[details.operation] ?? 'Reveal';
408
+ let message = `[SensitiveString] ${operation} of ${describeValue(klass, label)}`;
409
+ if (config.log.showPartialValue) {
410
+ // The only reader of the value, and the reason it arrives as a thunk: a
411
+ // byte-oriented reveal holds a `Buffer`, and decoding one into a string to
412
+ // decide not to print it would undo the thing sealing exists to do.
413
+ const partial = partialValue(typeof value === 'string' ? value : value(), config.log.partialLength, klass);
414
+ if (partial !== undefined) {
415
+ message += ` (${partial}...)`;
416
+ }
417
+ }
418
+ message += missingContext ? ' without context' : ` with context '${ctx.name}'`;
419
+ if (record.lastRevealStack !== undefined) {
420
+ message += `\n${record.lastRevealStack}`;
421
+ }
422
+ if (record.creationStack !== undefined) {
423
+ message += `\nCreated at:\n${record.creationStack}`;
424
+ }
425
+ emit(config, message);
426
+ }
427
+ /**
428
+ * Warn when one value is exposed repeatedly, at most once per window.
429
+ *
430
+ * Counted in fixed windows rather than a sliding one: a sliding count of an
431
+ * unbounded history is what the ring buffer exists to avoid, and rate limiting
432
+ * the warning is a feature in its own right. A loop that reveals a thousand
433
+ * times a second produces one line per window, not a thousand; a burst that
434
+ * straddles a boundary is reported by the window it finishes in.
435
+ */
436
+ function warnOnRepeats(record, klass, label, now, config) {
437
+ const repeated = config.repeated;
438
+ if (repeated === undefined) {
439
+ return;
440
+ }
441
+ if (now - record.windowStart >= repeated.window) {
442
+ record.windowStart = now;
443
+ record.windowCount = 0;
444
+ }
445
+ record.windowCount += 1;
446
+ // Equality, not `>=`: the warning fires as the threshold is crossed and stays
447
+ // quiet for the rest of the window.
448
+ if (record.windowCount !== repeated.threshold) {
449
+ return;
450
+ }
451
+ let message = `[SensitiveString] Warning: ${describeValue(klass, label)} revealed ` +
452
+ `${repeated.threshold} times in ${repeated.window}ms\n` +
453
+ ' Consider caching the revealed value or reviewing the code path.';
454
+ if (record.lastRevealStack !== undefined) {
455
+ message += `\n Most recent reveal at:\n${record.lastRevealStack}`;
456
+ }
457
+ emit(config, message);
458
+ }
459
+ /**
460
+ * Record one exposure of a value.
461
+ *
462
+ * Called from the raw-value gate for exactly the reads an audit hook sees: the
463
+ * ones where the value reaches the caller. A comparison reads the value without
464
+ * disclosing it and is not counted, and neither is a read that only feeds
465
+ * redaction. A read the gate refused never reaches here, so a denied reveal is
466
+ * not counted as one.
467
+ */
468
+ function recordReveal(instance, klass, label, value, ctx, details) {
469
+ const record = exports.devMode.records.get(instance);
470
+ if (record === undefined) {
471
+ // Constructed before development mode was turned on.
472
+ return;
473
+ }
474
+ const config = exports.devMode.config;
475
+ const now = Date.now();
476
+ record.revealCount += 1;
477
+ pushTimestamp(record, now);
478
+ if (config.captureStackTraces) {
479
+ record.lastRevealStack = captureStack();
480
+ }
481
+ logExposure(record, klass, label, value, ctx, details, config);
482
+ warnOnRepeats(record, klass, label, now, config);
483
+ }
484
+ /**
485
+ * What development mode recorded about one value, or undefined when it is off.
486
+ */
487
+ function readDevInfo(instance) {
488
+ if (!exports.devMode.config.enabled) {
489
+ return undefined;
490
+ }
491
+ const record = exports.devMode.records.get(instance);
492
+ if (record === undefined) {
493
+ return undefined;
494
+ }
495
+ return Object.freeze({
496
+ createdAt: new Date(record.createdAt),
497
+ revealCount: record.revealCount,
498
+ revealTimestamps: Object.freeze(readTimestamps(record)),
499
+ ...(record.creationStack !== undefined ? { creationStack: record.creationStack } : {}),
500
+ ...(record.lastRevealStack !== undefined ? { lastRevealStack: record.lastRevealStack } : {}),
501
+ });
502
+ }
503
+ //# sourceMappingURL=dev-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-mode.js","sourceRoot":"","sources":["../src/dev-mode.ts"],"names":[],"mappings":";;;AA4WA,gCAeC;AASD,4CAiBC;AAUD,kCAWC;AAmFD,wCAaC;AAgMD,oCA2BC;AAKD,kCAkBC;AA5vBD,uDAAuD;AAEvD,uCAA2C;AAE3C;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B,4EAA4E;AAC5E,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B,8DAA8D;AAC9D,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AA2H5C,MAAM,QAAQ,GAAoB,MAAM,CAAC,MAAM,CAAC;IAC9C,OAAO,EAAE,KAAK;IACd,kBAAkB,EAAE,KAAK;IACzB,oBAAoB,EAAE,KAAK;IAC3B,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE,SAAS;IACnB,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC;QACjB,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,SAAS;QACjB,gBAAgB,EAAE,KAAK;QACvB,aAAa,EAAE,sBAAsB;KACtC,CAAC;CACH,CAAC,CAAC;AAEH;;;GAGG;AACU,QAAA,OAAO,GAAG,IAAA,oCAAkB,EAAe,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;IACzE,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,IAAI,OAAO,EAAqB;CAC1C,CAAC,CAAC,CAAC;AAE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