@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,352 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NO_DESTINATIONS = exports.DestinationRestrictedError = void 0;
4
+ exports.planDestinations = planDestinations;
5
+ exports.checkDestinations = checkDestinations;
6
+ exports.serializeDestinations = serializeDestinations;
7
+ exports.deserializeDestinations = deserializeDestinations;
8
+ const errors_js_1 = require("./errors.js");
9
+ /**
10
+ * Raised when an operation needs the raw value of an instance the current
11
+ * context's destination is not allowed to receive.
12
+ *
13
+ * `restriction` says which tag refused and `currentValue` is what the context
14
+ * stated for it, or `undefined` when the context stated nothing. All of it is
15
+ * configuration and none of it is any part of the protected value, so the
16
+ * message is safe to log.
17
+ */
18
+ class DestinationRestrictedError extends errors_js_1.SensitiveStringError {
19
+ restriction;
20
+ currentValue;
21
+ allowedValues;
22
+ label;
23
+ name = 'DestinationRestrictedError';
24
+ code = 'destination-restricted';
25
+ constructor(restriction, currentValue, allowedValues, label) {
26
+ const named = label !== undefined ? ` '${label}'` : '';
27
+ const allowed = allowedValues.join(', ');
28
+ super(`Sensitive value${named} cannot be revealed toward this destination: ` +
29
+ (restriction === 'proxy'
30
+ ? `the request goes through proxy '${currentValue ?? ''}', and the value may only go ` +
31
+ `to host ${allowed}. A proxy receives the bytes before the host does, so it has to ` +
32
+ 'be a host the value allows.'
33
+ : currentValue === undefined
34
+ ? `the reveal context states no ${restriction} tag, and the value may only go to ` +
35
+ `${restriction} ${allowed}. Reveal it under a context whose tags name the ` +
36
+ `${restriction}, which the HTTP, data and LLM integrations do on every reveal.`
37
+ : `${restriction} is '${currentValue}', and the value may only go to ` +
38
+ `${restriction} ${allowed}`));
39
+ this.restriction = restriction;
40
+ this.currentValue = currentValue;
41
+ this.allowedValues = allowedValues;
42
+ this.label = label;
43
+ }
44
+ }
45
+ exports.DestinationRestrictedError = DestinationRestrictedError;
46
+ /** Describe a rejected option without disclosing it. */
47
+ function describeType(value) {
48
+ return value === null ? 'null' : typeof value;
49
+ }
50
+ /** The shared empty array a value with no binding points at. */
51
+ exports.NO_DESTINATIONS = Object.freeze([]);
52
+ /** The two fields, in the order they are checked and serialized. */
53
+ const LIST_FIELDS = ['sinks', 'hosts', 'principals'];
54
+ /**
55
+ * Characters that cannot appear in a host entry because they belong to some
56
+ * other part of a URL. A scheme, a path, a query, a fragment or a userinfo
57
+ * pasted into a host list would never equal a `host` tag, so the entry would
58
+ * sit in the list matching nothing, which is the shape of the defect this
59
+ * feature exists to catch rather than reproduce.
60
+ */
61
+ const NOT_A_HOST = /[\s/?#@\\]/;
62
+ function requireList(value, name) {
63
+ if (!Array.isArray(value)) {
64
+ throw new TypeError(`SensitiveString: destinations.${name} must be an array of strings, received ${describeType(value)}`);
65
+ }
66
+ if (value.length === 0) {
67
+ throw new RangeError(`SensitiveString: destinations.${name} is empty. An empty list expresses no binding and ` +
68
+ 'would silently allow everything; omit the field instead.');
69
+ }
70
+ return Object.freeze(value.map((entry, index) => {
71
+ if (typeof entry !== 'string') {
72
+ throw new TypeError(`SensitiveString: destinations.${name}[${index}] must be a string, received ${describeType(entry)}`);
73
+ }
74
+ if (entry === '') {
75
+ throw new RangeError(`SensitiveString: destinations.${name}[${index}] must not be empty`);
76
+ }
77
+ return name === 'hosts'
78
+ ? requireHost(entry, index)
79
+ : name === 'sinks'
80
+ ? requireSink(entry, index)
81
+ : requirePrincipal(entry, index);
82
+ }));
83
+ }
84
+ /**
85
+ * A sink name is matched literally and carries no wildcard: the integrations
86
+ * that write the tag write a fixed name, and a pattern over `'http'`,
87
+ * `'prisma'` or `'anthropic'` has nothing to abbreviate.
88
+ */
89
+ /**
90
+ * A principal is whatever identity the application tags a reveal with, a user
91
+ * id, a service account, a tenant, matched literally. No wildcard: an
92
+ * identity is exact or it is not the identity.
93
+ */
94
+ function requirePrincipal(entry, index) {
95
+ if (entry.includes('*')) {
96
+ throw new RangeError(`SensitiveString: destinations.principals[${index}] must be a literal identity with no wildcard.`);
97
+ }
98
+ return entry;
99
+ }
100
+ function requireSink(entry, index) {
101
+ if (entry.includes('*') || /\s/.test(entry)) {
102
+ throw new RangeError(`SensitiveString: destinations.sinks[${index}] must be a literal sink name with no ` +
103
+ "wildcard or whitespace, such as 'http' or 'anthropic'.");
104
+ }
105
+ return entry;
106
+ }
107
+ /**
108
+ * A host entry is what `new URL(...).host` spells: a lowercase hostname, with
109
+ * the port when it is not the scheme's default, or `*.` followed by a domain,
110
+ * which matches every host at least one label below it and not the domain
111
+ * itself.
112
+ *
113
+ * Nothing more is normalized. A trailing dot, a punycode form and a stated
114
+ * default port are all different strings from their equivalents, and an entry
115
+ * that does not equal what the integration writes refuses rather than passes,
116
+ * which is the direction to fail in. Case is the exception: DNS names are
117
+ * case-insensitive and a hand-written tag may not be lowercase.
118
+ */
119
+ function requireHost(entry, index) {
120
+ const host = entry.toLowerCase();
121
+ if (NOT_A_HOST.test(host) || host.includes('://')) {
122
+ throw new RangeError(`SensitiveString: destinations.hosts[${index}] must be a host, not a URL: no scheme, ` +
123
+ 'path, query, fragment, userinfo or whitespace. Write what `new URL(url).host` returns, ' +
124
+ "such as 'api.example.com' or 'api.example.com:8443'.");
125
+ }
126
+ const star = host.indexOf('*');
127
+ if (star !== -1) {
128
+ // A leading `*.` and nothing else: '*.example.com' matches every host
129
+ // below example.com. 'api.*.com', 'api.example.*' and a bare '*' are
130
+ // refused rather than matched as literals, which would leave the list
131
+ // matching nothing, or in the bare case read as "anywhere", which this
132
+ // option exists to stop a value from being.
133
+ if (star !== 0 || host.length < 3 || host[1] !== '.' || host.includes('*', 1)) {
134
+ throw new RangeError(`SensitiveString: destinations.hosts[${index}] may only carry '*' as a leading '*.' ` +
135
+ "prefix, such as '*.example.com'. A bare '*' would bind the value to nowhere in " +
136
+ 'particular, which is what omitting the option already means.');
137
+ }
138
+ }
139
+ // The rest must be a host the URL parser would hand back unchanged under
140
+ // either scheme. That is what refuses the entries the character check
141
+ // cannot see: a Unicode domain the parser would have written in punycode, a
142
+ // full-width stop it would have mapped to a dot, a bare port, and a stated
143
+ // default port, `:443` or `:80`, which `URL.host` elides and a tag would
144
+ // therefore never carry. Each would sit in the list matching nothing.
145
+ const literal = star === 0 ? host.slice(2) : host;
146
+ if (!isCanonicalHost(literal)) {
147
+ throw new RangeError(`SensitiveString: destinations.hosts[${index}] is not spelled as \`new URL(url).host\` ` +
148
+ 'would spell it: write the lowercase hostname in its punycode form, with the port only ' +
149
+ 'when it is not the default for the scheme.');
150
+ }
151
+ return host;
152
+ }
153
+ /** Whether the URL parser hands this host back unchanged under `http:` and `https:`. */
154
+ function isCanonicalHost(host) {
155
+ try {
156
+ return new URL(`http://${host}/`).host === host && new URL(`https://${host}/`).host === host;
157
+ }
158
+ catch {
159
+ return false;
160
+ }
161
+ }
162
+ function resolveOne(binding, index) {
163
+ if (typeof binding !== 'object' || binding === null || Array.isArray(binding)) {
164
+ throw new TypeError(`SensitiveString: destinations[${index}] must be an object, received ` +
165
+ `${Array.isArray(binding) ? 'an array' : describeType(binding)}`);
166
+ }
167
+ const lists = {};
168
+ let declared = false;
169
+ for (const field of LIST_FIELDS) {
170
+ const value = binding[field];
171
+ if (value !== undefined) {
172
+ lists[field] = requireList(value, field);
173
+ declared = true;
174
+ }
175
+ }
176
+ if (!declared) {
177
+ // A binding that binds to nothing is configuration that was meant to do
178
+ // something. Refusing it here is the same choice the empty list makes,
179
+ // for the same reason.
180
+ throw new Error('SensitiveString: destinations declares no destination. Give it sinks, hosts, principals ' +
181
+ 'or any of them together, or omit the option.');
182
+ }
183
+ return { sinks: lists.sinks, hosts: lists.hosts, principals: lists.principals };
184
+ }
185
+ /**
186
+ * Build the destination state for a newly constructed value.
187
+ *
188
+ * Every list is validated here, at construction, so a URL pasted where a host
189
+ * belongs is rejected at the call that wrote it rather than refusing every
190
+ * reveal months later.
191
+ *
192
+ * The option accepts a list as well as a single binding, because a value
193
+ * derived from two bound values carries both, and the wire format has to be
194
+ * able to carry them back.
195
+ *
196
+ * @throws TypeError If an option has the wrong type.
197
+ * @throws RangeError If a list is empty or an entry is not a host or a sink.
198
+ * @throws Error If a binding names no destination.
199
+ */
200
+ function planDestinations(options) {
201
+ const declared = options?.destinations;
202
+ if (declared === undefined) {
203
+ return undefined;
204
+ }
205
+ const bindings = Array.isArray(declared)
206
+ ? declared
207
+ : [declared];
208
+ if (bindings.length === 0) {
209
+ throw new RangeError('SensitiveString: destinations is an empty list, which binds the value to nothing; ' +
210
+ 'omit the option instead.');
211
+ }
212
+ return Object.freeze(bindings.map(resolveOne));
213
+ }
214
+ /**
215
+ * Whether a host matches one entry.
216
+ *
217
+ * `*.example.com` matches `api.example.com` and `a.b.example.com`, and does
218
+ * not match `example.com`: the wildcard stands for at least one label. A port
219
+ * is part of the suffix, so `*.example.com` does not match
220
+ * `api.example.com:8443` and `*.example.com:8443` does. Any other entry is
221
+ * equality. Both sides are already lowercase.
222
+ */
223
+ function matchesHost(host, entry) {
224
+ if (entry.startsWith('*.')) {
225
+ const suffix = entry.slice(1);
226
+ return host.length > suffix.length && host.endsWith(suffix);
227
+ }
228
+ return host === entry;
229
+ }
230
+ function matchesAnyHost(host, entries) {
231
+ for (const entry of entries) {
232
+ if (matchesHost(host, entry)) {
233
+ return true;
234
+ }
235
+ }
236
+ return false;
237
+ }
238
+ /**
239
+ * The tag a context states for a destination field, or `undefined` when it
240
+ * states none or states something that is not a string.
241
+ *
242
+ * A non-string is read as absent rather than coerced: a tag written as a URL
243
+ * object or a number is a context that did not say what this check reads, and
244
+ * `String(url)` would compare a whole URL against a host and refuse anyway,
245
+ * with a less useful message.
246
+ */
247
+ function statedTag(ctx, name) {
248
+ const tag = ctx?.tags?.[name];
249
+ return typeof tag === 'string' ? tag : undefined;
250
+ }
251
+ /**
252
+ * Refuse the read unless the context's destination satisfies every binding.
253
+ *
254
+ * Every binding has to pass, so a value derived from two bound values is at
255
+ * least as bound as each of them, which is rule R2's combination rule with
256
+ * nothing to decide: an intersection is what sharing the state already gives.
257
+ *
258
+ * A context that states no `sink`, no `host` or no `principal` refuses a
259
+ * binding on that field. This is the allowlist rule the environment
260
+ * restrictions follow, and it is the whole point here: a reveal that does not
261
+ * say where the value is going is the reveal this feature exists to refuse.
262
+ * A `proxy` tag is the one read the other way round: absent means the bytes
263
+ * go to the host directly, and present means a second machine receives them
264
+ * first and has to be allowed by the same host list.
265
+ *
266
+ * @throws DestinationRestrictedError If any binding refuses.
267
+ */
268
+ function checkDestinations(destinations, ctx, label) {
269
+ const sink = statedTag(ctx, 'sink');
270
+ const host = statedTag(ctx, 'host')?.toLowerCase();
271
+ const principal = statedTag(ctx, 'principal');
272
+ // A proxy is a second machine the bytes reach, before the host, so when a
273
+ // context states one it has to be a host the value allows too. Absent is
274
+ // read as no proxy: the HTTP row writes the tag when it resolves one, and
275
+ // a context with no proxy tag is a request that goes to its host directly.
276
+ const proxy = statedTag(ctx, 'proxy')?.toLowerCase();
277
+ for (const binding of destinations) {
278
+ if (binding.sinks !== undefined && (sink === undefined || !binding.sinks.includes(sink))) {
279
+ throw new DestinationRestrictedError('sink', sink, binding.sinks, label);
280
+ }
281
+ if (binding.hosts !== undefined &&
282
+ (host === undefined || !matchesAnyHost(host, binding.hosts))) {
283
+ throw new DestinationRestrictedError('host', host, binding.hosts, label);
284
+ }
285
+ if (binding.hosts !== undefined &&
286
+ proxy !== undefined &&
287
+ !matchesAnyHost(proxy, binding.hosts)) {
288
+ throw new DestinationRestrictedError('proxy', proxy, binding.hosts, label);
289
+ }
290
+ if (binding.principals !== undefined &&
291
+ (principal === undefined || !binding.principals.includes(principal))) {
292
+ throw new DestinationRestrictedError('principal', principal, binding.principals, label);
293
+ }
294
+ }
295
+ }
296
+ /**
297
+ * The wire form of these bindings. Lists only, so nothing is dropped.
298
+ */
299
+ function serializeDestinations(destinations) {
300
+ return destinations.map((binding) => {
301
+ const wire = {};
302
+ for (const field of LIST_FIELDS) {
303
+ const list = binding[field];
304
+ if (list !== undefined) {
305
+ wire[field] = [...list];
306
+ }
307
+ }
308
+ return wire;
309
+ });
310
+ }
311
+ /**
312
+ * Read bindings out of an untrusted payload.
313
+ *
314
+ * They can only tighten: a value rebuilt by `deserialize()` starts with none,
315
+ * so anything a payload carries here refuses reads that would otherwise have
316
+ * been allowed, and there is no spelling of "no binding" that lifts one.
317
+ *
318
+ * An unknown key is rejected rather than ignored, for the reason the
319
+ * environment restrictions reject one: a sender describing a limit this
320
+ * receiver does not know would have that limit silently unenforced.
321
+ */
322
+ function deserializeDestinations(serialized) {
323
+ if (!('destinations' in serialized) || serialized.destinations === undefined) {
324
+ return undefined;
325
+ }
326
+ const declared = serialized.destinations;
327
+ if (!Array.isArray(declared)) {
328
+ throw new Error('Invalid SerializedSensitiveString: destinations must be an array');
329
+ }
330
+ if (declared.length === 0) {
331
+ throw new Error('Invalid SerializedSensitiveString: destinations is empty. A payload that binds nothing ' +
332
+ 'omits the field rather than carrying an empty list.');
333
+ }
334
+ return declared.map((entry, index) => {
335
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
336
+ throw new Error(`Invalid SerializedSensitiveString: destinations[${index}] must be an object`);
337
+ }
338
+ const binding = {};
339
+ for (const key of Object.keys(entry)) {
340
+ if (!LIST_FIELDS.includes(key)) {
341
+ throw new Error(`Invalid SerializedSensitiveString: destinations[${index}] carries unknown key '${key}'. ` +
342
+ 'A binding this receiver cannot enforce is refused rather than ignored.');
343
+ }
344
+ binding[key] = entry[key];
345
+ }
346
+ // The lists themselves are validated by `planDestinations`, which is the
347
+ // same check a locally constructed value gets, so a payload cannot smuggle
348
+ // an entry shape the constructor would have refused.
349
+ return binding;
350
+ });
351
+ }
352
+ //# sourceMappingURL=destination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destination.js","sourceRoot":"","sources":["../src/destination.ts"],"names":[],"mappings":";;;AA8SA,4CAqBC;AAkED,8CAyCC;AAKD,sDAgBC;AAaD,0DA6CC;AAvfD,2CAAmD;AAsCnD;;;;;;;;GAQG;AACH,MAAa,0BAA2B,SAAQ,gCAAoB;IAKvD;IACA;IACA;IACA;IAPO,IAAI,GAAG,4BAA4B,CAAC;IACpC,IAAI,GAAG,wBAAwB,CAAC;IAElD,YACW,WAA4B,EAC5B,YAAgC,EAChC,aAAgC,EAChC,KAAc;QAEvB,MAAM,KAAK,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzC,KAAK,CACH,kBAAkB,KAAK,+CAA+C;YACpE,CAAC,WAAW,KAAK,OAAO;gBACtB,CAAC,CAAC,mCAAmC,YAAY,IAAI,EAAE,+BAA+B;oBACpF,WAAW,OAAO,kEAAkE;oBACpF,6BAA6B;gBAC/B,CAAC,CAAC,YAAY,KAAK,SAAS;oBAC1B,CAAC,CAAC,gCAAgC,WAAW,qCAAqC;wBAChF,GAAG,WAAW,IAAI,OAAO,kDAAkD;wBAC3E,GAAG,WAAW,iEAAiE;oBACjF,CAAC,CAAC,GAAG,WAAW,QAAQ,YAAY,kCAAkC;wBACpE,GAAG,WAAW,IAAI,OAAO,EAAE,CAAC,CACrC,CAAC;QApBO,gBAAW,GAAX,WAAW,CAAiB;QAC5B,iBAAY,GAAZ,YAAY,CAAoB;QAChC,kBAAa,GAAb,aAAa,CAAmB;QAChC,UAAK,GAAL,KAAK,CAAS;IAkBzB,CAAC;C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,OAAO,GAAuB,EAAE,CAAC;QAEvC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,IAAI,CAAE,WAAiC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CACb,mDAAmD,KAAK,0BAA0B,GAAG,KAAK;oBACxF,wEAAwE,CAC3E,CAAC;YACJ,CAAC;YAEA,OAAmC,CAAC,GAAG,CAAC,GAAI,KAAiC,CAAC,GAAG,CAAC,CAAC;QACtF,CAAC;QAED,yEAAyE;QACzE,2EAA2E;QAC3E,qDAAqD;QACrD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,145 @@
1
+ import { type KeyedDerivationOptions } from './derive.js';
2
+ import { SensitiveStringError } from './errors.js';
3
+ import type { SensitivityClass, SensitivityPolicy } from './types.js';
4
+ /** How to derive and render a correlation tag. */
5
+ export interface DeterministicRedactorOptions {
6
+ /**
7
+ * HMAC key. Required, and there is no way to configure a redactor without
8
+ * one.
9
+ *
10
+ * At least `MIN_DERIVATION_KEY_BYTES` bytes. Prefer a `Uint8Array` from
11
+ * a secrets manager or `randomBytes`; a string key is read as UTF-8 and sits
12
+ * in the heap as an ordinary string.
13
+ *
14
+ * Rotating it renders every tag minted before the rotation uncorrelatable
15
+ * with every tag minted after, which is a feature when correlation should
16
+ * expire and a surprise when an investigation spans the rotation.
17
+ */
18
+ readonly key: KeyedDerivationOptions['key'];
19
+ /**
20
+ * Domain components mixed in ahead of the value, so the same value under two
21
+ * scopes gets two tags.
22
+ *
23
+ * This is the control for how far correlation reaches. With no scope, a tag
24
+ * is stable for the life of the key, across every process and every restart,
25
+ * and whoever holds two years of logs can count how often a subject appears
26
+ * in them. A per-session or per-tenant scope narrows that to the session or
27
+ * the tenant. A string is one component; an array is several, joined so they
28
+ * cannot be reassociated.
29
+ *
30
+ * It is not a salt in the password sense and does not need to be secret. It
31
+ * separates token spaces, and the key is what makes a tag unguessable.
32
+ */
33
+ readonly scope?: string | readonly string[];
34
+ /**
35
+ * Hex characters retained from the digest. Defaults to
36
+ * `DEFAULT_DERIVED_TOKEN_LENGTH`, which is also the floor.
37
+ *
38
+ * The floor is a correctness guard: two values sharing a tag merge two
39
+ * subjects into one in the log, which reads as a fact rather than as a
40
+ * collision. See `MIN_DERIVED_TOKEN_LENGTH` for the arithmetic, and
41
+ * raise this before a workload grows past it.
42
+ */
43
+ readonly length?: number;
44
+ /** Tag prefix. Defaults to `'REDACTED'`. Must match `[A-Za-z0-9_.:-]{1,64}`. */
45
+ readonly prefix?: string;
46
+ /**
47
+ * Renderer for the prefix and the tag. Defaults to `` `[${prefix}:${tag}]` ``.
48
+ *
49
+ * It receives the prefix and the derived tag and never the raw value, which
50
+ * is what makes a caller-supplied renderer safe to accept here: there is no
51
+ * argument it could leak. It is called once at construction with a probe, so
52
+ * one that throws or answers with a non-string is refused before it can take
53
+ * down a log line.
54
+ */
55
+ readonly format?: (prefix: string, tag: string) => string;
56
+ }
57
+ /**
58
+ * Raised when a sensitivity class may not be given a correlation tag.
59
+ *
60
+ * Only `credential` is refused, and only by {@link deterministicRedaction}.
61
+ * {@link createDeterministicRedactor} knows no class and refuses nothing.
62
+ */
63
+ export declare class DeterministicRedactionNotAllowedError extends SensitiveStringError {
64
+ readonly klass: SensitivityClass;
65
+ readonly name = "DeterministicRedactionNotAllowedError";
66
+ readonly code = "deterministic-redaction-refused";
67
+ constructor(klass: SensitivityClass);
68
+ }
69
+ /**
70
+ * Build a redaction function that derives a stable tag from the value.
71
+ *
72
+ * The primitive, for a caller assembling a {@link SensitivityPolicy} by hand.
73
+ * {@link deterministicRedaction} is the one-liner over it and is what most
74
+ * callers want, because it keeps the rest of the class's policy intact.
75
+ *
76
+ * Everything that can be wrong with the options is settled at construction
77
+ * rather than at the first redaction: a key below the entropy floor, a length
78
+ * below the collision floor, a domain component carrying a NUL, a malformed
79
+ * prefix, a `format` that does not answer with a string. A redaction runs on
80
+ * the path a log line takes, and a configuration error discovered there is
81
+ * discovered by a log line failing.
82
+ *
83
+ * The options are read once and the scope is copied, so mutating either
84
+ * afterwards moves nothing. A redactor that answered differently on Tuesday
85
+ * because a caller pushed onto the array they passed would break the one
86
+ * property the feature exists for.
87
+ *
88
+ * @param options - The key, the scope, the tag length, and the rendering
89
+ * @returns A function suitable as a policy's `redact`
90
+ *
91
+ * @throws TypeError For a missing or mistyped key, a malformed prefix, a
92
+ * domain component that is not a string or contains a NUL, or a
93
+ * `format` that does not return a string.
94
+ * @throws RangeError If the key is shorter than `MIN_DERIVATION_KEY_BYTES`
95
+ * or `length` is outside the documented bounds.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * registerPolicy(
100
+ * { ...getPolicy('sensitive'), redact: createDeterministicRedactor({ key }) },
101
+ * { overwrite: true }
102
+ * );
103
+ * ```
104
+ */
105
+ export declare function createDeterministicRedactor(options: DeterministicRedactorOptions): (value: string) => string;
106
+ /**
107
+ * A policy for `klass` whose redaction carries a correlation tag.
108
+ *
109
+ * The currently registered policy for the class with its `redact` replaced, so
110
+ * `requireConstantTimeEquals`, `allowMask`, `checkRevealAllowed`, the advisory
111
+ * flags and every deadline rule survive. Registering a hand-written policy
112
+ * instead is how a class quietly loses one of those.
113
+ *
114
+ * The class is mixed into the derivation alongside the caller's scope, so the
115
+ * same string classified two ways gets two tags. That matches how
116
+ * `entityHandle` derives, and it means a `serialize()` payload caught by a
117
+ * redaction walk renders the same tag as the instance it came from, since both
118
+ * are redacted through the same class's policy.
119
+ *
120
+ * `credential` is refused. See {@link DeterministicRedactionNotAllowedError};
121
+ * the refusal is hard-coded rather than read from an advisory flag, because
122
+ * every existing flag answers a different question and overloading one would
123
+ * make it mean two things.
124
+ *
125
+ * @param klass - The class whose redaction is being replaced
126
+ * @param options - The key, the scope, the tag length, and the rendering
127
+ * @returns A policy to hand to `registerPolicy(..., { overwrite: true })`
128
+ *
129
+ * @throws DeterministicRedactionNotAllowedError If `klass` is `credential`.
130
+ * @throws Error If no policy is registered for `klass`.
131
+ * @throws TypeError, RangeError As {@link createDeterministicRedactor}.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * registerPolicy(
136
+ * deterministicRedaction('sensitive', { key: process.env.REDACTION_HMAC_KEY! }),
137
+ * { overwrite: true }
138
+ * );
139
+ *
140
+ * String(new SensitiveString('alice@example.com', 'sensitive'));
141
+ * // '[REDACTED:sensitive:5f2a91c0b74e]'
142
+ * ```
143
+ */
144
+ export declare function deterministicRedaction(klass: SensitivityClass, options: DeterministicRedactorOptions): SensitivityPolicy;
145
+ //# sourceMappingURL=deterministic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deterministic.d.ts","sourceRoot":"","sources":["../src/deterministic.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,sBAAsB,EAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAiFtE,kDAAkD;AAClD,MAAM,WAAW,4BAA4B;IAC3C;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,GAAG,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAE5C;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAE5C;;;;;;;;OAQG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,gFAAgF;IAChF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;;;OAQG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3D;AAED;;;;;GAKG;AACH,qBAAa,qCAAsC,SAAQ,oBAAo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