@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,558 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NO_RESTRICTIONS = exports.EnvironmentRestrictedError = exports.UnserializableRestrictionError = exports.EnvironmentLockedError = void 0;
4
+ exports.setEnvironmentInfo = setEnvironmentInfo;
5
+ exports.lockEnvironmentInfo = lockEnvironmentInfo;
6
+ exports.isEnvironmentLocked = isEnvironmentLocked;
7
+ exports.getEnvironmentInfo = getEnvironmentInfo;
8
+ exports.resetEnvironmentInfo = resetEnvironmentInfo;
9
+ exports.planRestrictions = planRestrictions;
10
+ exports.checkEnvironmentRestrictions = checkEnvironmentRestrictions;
11
+ exports.carriesCustomRestriction = carriesCustomRestriction;
12
+ exports.serializeRestrictions = serializeRestrictions;
13
+ exports.deserializeRestrictions = deserializeRestrictions;
14
+ const errors_js_1 = require("./errors.js");
15
+ const global_state_js_1 = require("./global-state.js");
16
+ /**
17
+ * Describe a rejected option without disclosing it.
18
+ */
19
+ function describeType(value) {
20
+ return value === null ? 'null' : typeof value;
21
+ }
22
+ /**
23
+ * Raised when `setEnvironmentInfo()` is called after `lockEnvironmentInfo()`.
24
+ *
25
+ * The lock is the whole of what this feature offers against a later
26
+ * reconfiguration, so a refused write is reported rather than ignored: code
27
+ * that believed it had set the region must not carry on believing it.
28
+ */
29
+ class EnvironmentLockedError extends errors_js_1.SensitiveStringError {
30
+ name = 'EnvironmentLockedError';
31
+ code = 'environment-locked';
32
+ constructor() {
33
+ super('Environment info is locked. lockEnvironmentInfo() was already called, so the environment ' +
34
+ 'a restricted value is checked against cannot be changed for the rest of the process.');
35
+ }
36
+ }
37
+ exports.EnvironmentLockedError = EnvironmentLockedError;
38
+ /**
39
+ * Raised when a value carrying a custom restriction is put on the wire.
40
+ *
41
+ * Its own class rather than an `EnvironmentRestrictedError`, because it is a
42
+ * different question with a different answer. That error means "not here, try
43
+ * where the value allows"; this one means "not anywhere, because a function has
44
+ * no wire form", and a caller who retries elsewhere on it retries forever.
45
+ */
46
+ class UnserializableRestrictionError extends errors_js_1.SensitiveStringError {
47
+ label;
48
+ name = 'UnserializableRestrictionError';
49
+ code = 'unserializable-restriction';
50
+ constructor(label) {
51
+ super(`Sensitive value${label !== undefined ? ` '${label}'` : ''} cannot be serialized: it ` +
52
+ 'carries a custom restriction, which is a function and has no wire form. Emitting the ' +
53
+ 'declarative half would hand the receiver a value it believes it has fully checked. ' +
54
+ 'Express the restriction with allowedEnvironments, allowedRegions or allowedDatacenters, ' +
55
+ 'which do cross, or do not transmit the value.');
56
+ this.label = label;
57
+ }
58
+ }
59
+ exports.UnserializableRestrictionError = UnserializableRestrictionError;
60
+ /**
61
+ * Raised when an operation needs the raw value of an instance the current
62
+ * environment is not allowed to read.
63
+ *
64
+ * `restriction` says which field refused and `currentValue` is what the
65
+ * environment reported for it, or `undefined` when the environment does not
66
+ * state that field at all. `allowedValues` and `deniedValues` are the patterns
67
+ * the value was constructed with. All four are configuration, never any part
68
+ * of the protected value, so the message is safe to log.
69
+ */
70
+ class EnvironmentRestrictedError extends errors_js_1.SensitiveStringError {
71
+ restriction;
72
+ currentValue;
73
+ allowedValues;
74
+ deniedValues;
75
+ label;
76
+ detail;
77
+ name = 'EnvironmentRestrictedError';
78
+ code = 'environment-restricted';
79
+ constructor(restriction, currentValue, allowedValues, deniedValues, label,
80
+ /** For a custom refusal: the caller's `customMessage`, or why the function could not answer. */
81
+ detail, cause) {
82
+ const named = label !== undefined ? ` '${label}'` : '';
83
+ super(`Sensitive value${named} cannot be read in this environment: ` +
84
+ describeRefusal(restriction, currentValue, allowedValues, deniedValues, detail), cause === undefined ? undefined : { cause });
85
+ this.restriction = restriction;
86
+ this.currentValue = currentValue;
87
+ this.allowedValues = allowedValues;
88
+ this.deniedValues = deniedValues;
89
+ this.label = label;
90
+ this.detail = detail;
91
+ }
92
+ }
93
+ exports.EnvironmentRestrictedError = EnvironmentRestrictedError;
94
+ function describeRefusal(restriction, currentValue, allowedValues, deniedValues, detail) {
95
+ if (restriction === 'custom') {
96
+ return detail ?? 'a custom restriction refused it';
97
+ }
98
+ if (deniedValues !== undefined) {
99
+ const denied = deniedValues.join(', ');
100
+ return currentValue === undefined
101
+ ? `this environment states no ${restriction}, and the value denies ${denied}`
102
+ : `${restriction} is '${currentValue}', which the value denies as ${denied}`;
103
+ }
104
+ const allowed = allowedValues?.join(', ') ?? '';
105
+ return currentValue === undefined
106
+ ? `this environment states no ${restriction}, and the value allows only ${allowed}`
107
+ : `${restriction} is '${currentValue}', and the value allows only ${allowed}`;
108
+ }
109
+ const UNDECLARED = Object.freeze({ environment: 'unknown' });
110
+ const environment = (0, global_state_js_1.getGlobalSingleton)('environment', () => ({
111
+ info: UNDECLARED,
112
+ declared: false,
113
+ locked: false,
114
+ warned: false,
115
+ }));
116
+ function requireName(value, name) {
117
+ if (typeof value !== 'string') {
118
+ throw new TypeError(`setEnvironmentInfo: ${name} must be a string, received ${describeType(value)}`);
119
+ }
120
+ if (value === '') {
121
+ throw new RangeError(`setEnvironmentInfo: ${name} must not be empty`);
122
+ }
123
+ return value;
124
+ }
125
+ function requireOptionalName(value, name) {
126
+ return value === undefined ? undefined : requireName(value, name);
127
+ }
128
+ /**
129
+ * Copy the caller's tags into our own frozen object.
130
+ *
131
+ * Copied because the environment is read on every restricted access: keeping
132
+ * the caller's object would let a mutation after the lock change what a locked
133
+ * environment reports, which is the one thing the lock exists to prevent.
134
+ */
135
+ function requireTags(value) {
136
+ if (value === undefined) {
137
+ return undefined;
138
+ }
139
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
140
+ throw new TypeError(`setEnvironmentInfo: customTags must be an object, received ${describeType(value)}`);
141
+ }
142
+ const tags = Object.create(null);
143
+ for (const [key, tag] of Object.entries(value)) {
144
+ if (typeof tag !== 'string') {
145
+ throw new TypeError(`setEnvironmentInfo: customTags.${key} must be a string, received ${describeType(tag)}`);
146
+ }
147
+ tags[key] = tag;
148
+ }
149
+ return Object.freeze(tags);
150
+ }
151
+ /**
152
+ * Declare the environment restricted values are checked against.
153
+ *
154
+ * ⚠️ This is process-global mutable state. It protects against a value being
155
+ * deployed somewhere it was not meant to run; it does not protect against code
156
+ * already executing in the process, which can call this function itself until
157
+ * `lockEnvironmentInfo()` has run, and can call `resetEnvironmentInfo()` even
158
+ * after. Call it once, from application startup, with values read from a source
159
+ * you trust, and lock it before serving anything.
160
+ *
161
+ * Every field is copied, so mutating the object afterwards does not move the
162
+ * environment.
163
+ *
164
+ * @throws EnvironmentLockedError If `lockEnvironmentInfo()` has already run.
165
+ * @throws TypeError If `info`, or one of its fields, has the wrong type.
166
+ * @throws RangeError If a field is an empty string.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * setEnvironmentInfo({
171
+ * environment: process.env['NODE_ENV'] ?? 'unknown',
172
+ * region: await instanceRegion(),
173
+ * });
174
+ * lockEnvironmentInfo();
175
+ * ```
176
+ */
177
+ function setEnvironmentInfo(info) {
178
+ if (environment.locked) {
179
+ throw new EnvironmentLockedError();
180
+ }
181
+ if (typeof info !== 'object' || info === null) {
182
+ throw new TypeError(`setEnvironmentInfo: info must be an object, received ${describeType(info)}`);
183
+ }
184
+ const region = requireOptionalName(info.region, 'region');
185
+ const datacenter = requireOptionalName(info.datacenter, 'datacenter');
186
+ const customTags = requireTags(info.customTags);
187
+ environment.info = Object.freeze({
188
+ environment: requireName(info.environment, 'environment'),
189
+ ...(region !== undefined ? { region } : {}),
190
+ ...(datacenter !== undefined ? { datacenter } : {}),
191
+ ...(customTags !== undefined ? { customTags } : {}),
192
+ });
193
+ environment.declared = true;
194
+ }
195
+ /**
196
+ * Freeze the environment for the rest of the process.
197
+ *
198
+ * Call it once startup has finished detecting where it is running and before
199
+ * the first request. There is no unlock: `resetEnvironmentInfo()` clears the
200
+ * lock, and exists for test isolation rather than for production use.
201
+ */
202
+ function lockEnvironmentInfo() {
203
+ environment.locked = true;
204
+ }
205
+ /** Whether `lockEnvironmentInfo()` has run. */
206
+ function isEnvironmentLocked() {
207
+ return environment.locked;
208
+ }
209
+ /**
210
+ * The current environment, frozen.
211
+ *
212
+ * The same object a custom restriction is handed, so neither a caller nor a
213
+ * restriction can write to it.
214
+ */
215
+ function getEnvironmentInfo() {
216
+ return environment.info;
217
+ }
218
+ /**
219
+ * Forget the environment and the lock.
220
+ *
221
+ * For test isolation, which rule R6 requires of every process-global singleton
222
+ * here, and the counterpart of `resetPolicies()`. It undoes `lockEnvironmentInfo()`,
223
+ * which is the honest statement of what the lock is worth: the threat model is
224
+ * a misconfigured deploy, not code already running in the process.
225
+ */
226
+ function resetEnvironmentInfo() {
227
+ environment.info = UNDECLARED;
228
+ environment.declared = false;
229
+ environment.locked = false;
230
+ environment.warned = false;
231
+ }
232
+ /** The shared empty array a value with no restrictions points at. */
233
+ exports.NO_RESTRICTIONS = Object.freeze([]);
234
+ /** The declarative fields, in the order they are checked and serialized. */
235
+ const LIST_FIELDS = [
236
+ 'allowedEnvironments',
237
+ 'deniedEnvironments',
238
+ 'allowedRegions',
239
+ 'deniedRegions',
240
+ 'allowedDatacenters',
241
+ 'deniedDatacenters',
242
+ ];
243
+ /** The fields whose entries are matched as patterns rather than literally. */
244
+ const PATTERN_FIELDS = new Set(['allowedRegions', 'deniedRegions']);
245
+ /**
246
+ * Validate one list of names or patterns.
247
+ *
248
+ * An empty array is refused rather than read either way. `allowedRegions: []`
249
+ * says "no region is allowed" if read literally and "every region is allowed"
250
+ * if read as "no restriction expressed", and a security control must not pick
251
+ * one of those silently: a caller who built the list from configuration that
252
+ * came back empty has a bug, and this is where they find it.
253
+ */
254
+ function requireList(value, name, patterns) {
255
+ if (!Array.isArray(value)) {
256
+ throw new TypeError(`SensitiveString: restrictions.${name} must be an array of strings, received ${describeType(value)}`);
257
+ }
258
+ if (value.length === 0) {
259
+ throw new RangeError(`SensitiveString: restrictions.${name} is empty. An empty list expresses no restriction ` +
260
+ 'and would silently allow everything; omit the field instead.');
261
+ }
262
+ return Object.freeze(value.map((entry, index) => {
263
+ if (typeof entry !== 'string') {
264
+ throw new TypeError(`SensitiveString: restrictions.${name}[${index}] must be a string, received ${describeType(entry)}`);
265
+ }
266
+ if (entry === '') {
267
+ throw new RangeError(`SensitiveString: restrictions.${name}[${index}] must not be empty`);
268
+ }
269
+ const star = entry.indexOf('*');
270
+ if (!patterns && star !== -1) {
271
+ throw new RangeError(`SensitiveString: restrictions.${name}[${index}] contains '*', and ${name} entries are ` +
272
+ 'matched literally. Only region patterns take a wildcard.');
273
+ }
274
+ // A trailing '*' and nothing else, so a pattern that reads like a glob
275
+ // but is matched as a prefix is refused rather than quietly matching
276
+ // nothing. 'eu-*' is a prefix; '*-east-1' and 'eu-*-1' are neither a
277
+ // prefix nor a literal region, and either would leave a denylist
278
+ // matching nothing at all.
279
+ if (star !== -1 && star !== entry.length - 1) {
280
+ throw new RangeError(`SensitiveString: restrictions.${name}[${index}] may only carry '*' as its last ` +
281
+ "character. A region pattern is a literal name or a prefix such as 'eu-*'; " +
282
+ 'anything more expressive belongs in a custom restriction.');
283
+ }
284
+ return entry;
285
+ }));
286
+ }
287
+ function requireCustom(value) {
288
+ if (value === undefined) {
289
+ return undefined;
290
+ }
291
+ if (typeof value !== 'function') {
292
+ throw new TypeError(`SensitiveString: restrictions.custom must be a function, received ${describeType(value)}`);
293
+ }
294
+ return value;
295
+ }
296
+ function requireMessage(value) {
297
+ if (value === undefined) {
298
+ return undefined;
299
+ }
300
+ if (typeof value !== 'string') {
301
+ throw new TypeError(`SensitiveString: restrictions.customMessage must be a string, received ${describeType(value)}`);
302
+ }
303
+ return value;
304
+ }
305
+ function resolveOne(restrictions, index) {
306
+ if (typeof restrictions !== 'object' || restrictions === null || Array.isArray(restrictions)) {
307
+ throw new TypeError(`SensitiveString: restrictions[${index}] must be an object, received ` +
308
+ `${Array.isArray(restrictions) ? 'an array' : describeType(restrictions)}`);
309
+ }
310
+ const lists = {};
311
+ let declared = false;
312
+ for (const field of LIST_FIELDS) {
313
+ const value = restrictions[field];
314
+ if (value !== undefined) {
315
+ lists[field] = requireList(value, field, PATTERN_FIELDS.has(field));
316
+ declared = true;
317
+ }
318
+ }
319
+ const custom = requireCustom(restrictions.custom);
320
+ const customMessage = requireMessage(restrictions.customMessage);
321
+ if (custom === undefined) {
322
+ if (!declared) {
323
+ // A restriction set that restricts nothing is configuration that was
324
+ // meant to do something. Refusing it here is the same choice the empty
325
+ // list makes, for the same reason.
326
+ throw new Error('SensitiveString: restrictions declares no restriction. Give it at least one list or a ' +
327
+ 'custom function, or omit the option.');
328
+ }
329
+ if (customMessage !== undefined) {
330
+ throw new Error('SensitiveString: restrictions.customMessage has no custom function to describe.');
331
+ }
332
+ }
333
+ return {
334
+ allowedEnvironments: lists.allowedEnvironments,
335
+ deniedEnvironments: lists.deniedEnvironments,
336
+ allowedRegions: lists.allowedRegions,
337
+ deniedRegions: lists.deniedRegions,
338
+ allowedDatacenters: lists.allowedDatacenters,
339
+ deniedDatacenters: lists.deniedDatacenters,
340
+ custom,
341
+ customMessage,
342
+ };
343
+ }
344
+ /**
345
+ * Build the restriction state for a newly constructed value.
346
+ *
347
+ * Every list is validated here, at construction, so a malformed pattern is
348
+ * rejected at the call that wrote it rather than inside a reveal months later
349
+ * in a region nobody is watching.
350
+ *
351
+ * The option accepts a list as well as a single set, because a value derived
352
+ * from two restricted values carries both, and the wire format has to be able
353
+ * to carry them back.
354
+ *
355
+ * @throws TypeError If an option has the wrong type.
356
+ * @throws RangeError If a list is empty or a pattern is not a literal or a prefix.
357
+ * @throws Error If a restriction set expresses no restriction.
358
+ */
359
+ function planRestrictions(options) {
360
+ const declared = options?.restrictions;
361
+ if (declared === undefined) {
362
+ return undefined;
363
+ }
364
+ const sets = Array.isArray(declared)
365
+ ? declared
366
+ : [declared];
367
+ if (sets.length === 0) {
368
+ throw new RangeError('SensitiveString: restrictions is an empty list, which expresses no restriction; ' +
369
+ 'omit the option instead.');
370
+ }
371
+ return Object.freeze(sets.map(resolveOne));
372
+ }
373
+ /**
374
+ * Warn once that restrictions are being decided against an environment nobody
375
+ * declared.
376
+ *
377
+ * An undeclared environment reports `unknown` and no region, which refuses
378
+ * every allowlist and satisfies every denylist. The first half fails loudly on
379
+ * its own; the second is the quiet one, and this is what makes it audible.
380
+ *
381
+ * Deliberately `console.warn`: what is being reported is that startup never
382
+ * configured the library, so routing it through anything the library was also
383
+ * never told about would be the one place it could be missed.
384
+ */
385
+ function warnUndeclared() {
386
+ if (environment.declared || environment.warned) {
387
+ return;
388
+ }
389
+ environment.warned = true;
390
+ // eslint-disable-next-line no-console -- see above
391
+ console.warn('[SensitiveString] A value with environment restrictions was read before ' +
392
+ 'setEnvironmentInfo() was called. The environment reports itself as ' +
393
+ "'unknown' with no region, so every allowlist refuses and every denylist passes.");
394
+ }
395
+ /**
396
+ * Whether a name matches one entry of a list.
397
+ *
398
+ * A trailing `*` is a prefix and nothing else is a wildcard, which
399
+ * `requireList` has already enforced, so this is the whole matching rule.
400
+ */
401
+ function matchesEntry(value, entry) {
402
+ return entry.endsWith('*') ? value.startsWith(entry.slice(0, -1)) : value === entry;
403
+ }
404
+ function matchesAny(value, entries) {
405
+ for (const entry of entries) {
406
+ if (matchesEntry(value, entry)) {
407
+ return true;
408
+ }
409
+ }
410
+ return false;
411
+ }
412
+ /**
413
+ * Decide one field against its allowlist and its denylist.
414
+ *
415
+ * The allowlist is checked first so that when both would refuse, the caller is
416
+ * told where the value *may* be read rather than only where it may not.
417
+ *
418
+ * A field the environment does not state is treated differently by the two
419
+ * lists, and the asymmetry is deliberate. An allowlist is the statement "only
420
+ * here", and an environment that cannot say where it is has not shown that it
421
+ * is here, so the read is refused. A denylist is the statement "not there", and
422
+ * it concludes nothing from silence: reading it the other way would refuse
423
+ * every read on every machine that never sets a region, which is every laptop
424
+ * and every CI runner.
425
+ */
426
+ function checkField(kind, current, allowed, denied, label) {
427
+ if (allowed !== undefined && (current === undefined || !matchesAny(current, allowed))) {
428
+ throw new EnvironmentRestrictedError(kind, current, allowed, undefined, label);
429
+ }
430
+ if (denied !== undefined && current !== undefined && matchesAny(current, denied)) {
431
+ throw new EnvironmentRestrictedError(kind, current, undefined, denied, label);
432
+ }
433
+ }
434
+ /**
435
+ * Ask a custom restriction, and treat everything but `true` as a refusal.
436
+ *
437
+ * A function that throws denies the read, for the reason a revocation registry
438
+ * that throws does: something that cannot answer whether this environment
439
+ * qualifies has not said that it does. A function that answers with anything
440
+ * but a boolean denies too, since an `async` one returns a Promise, which is
441
+ * truthy and would otherwise allow every read it was written to refuse.
442
+ */
443
+ function checkCustom(restrictions, info, label) {
444
+ const { custom, customMessage } = restrictions;
445
+ if (custom === undefined) {
446
+ return;
447
+ }
448
+ let answer;
449
+ try {
450
+ answer = custom(info);
451
+ }
452
+ catch (error) {
453
+ throw new EnvironmentRestrictedError('custom', info.environment, undefined, undefined, label, customMessage ?? 'a custom restriction threw instead of answering', error);
454
+ }
455
+ if (answer === true) {
456
+ return;
457
+ }
458
+ throw new EnvironmentRestrictedError('custom', info.environment, undefined, undefined, label, customMessage ??
459
+ (typeof answer === 'boolean'
460
+ ? 'a custom restriction refused it'
461
+ : `a custom restriction answered with ${describeType(answer)} instead of a boolean, ` +
462
+ 'which is read as a refusal'));
463
+ }
464
+ /**
465
+ * Refuse the read unless the current environment satisfies every restriction.
466
+ *
467
+ * Every set has to pass, so a value derived from two restricted values is at
468
+ * least as restricted as each of them, which is rule R2's combination rule with
469
+ * nothing to decide: an intersection is what sharing the state already gives.
470
+ *
471
+ * @throws EnvironmentRestrictedError If any restriction refuses.
472
+ */
473
+ function checkEnvironmentRestrictions(restrictions, label) {
474
+ warnUndeclared();
475
+ const info = environment.info;
476
+ for (const set of restrictions) {
477
+ checkField('environment', info.environment, set.allowedEnvironments, set.deniedEnvironments, label);
478
+ checkField('region', info.region, set.allowedRegions, set.deniedRegions, label);
479
+ checkField('datacenter', info.datacenter, set.allowedDatacenters, set.deniedDatacenters, label);
480
+ checkCustom(set, info, label);
481
+ }
482
+ }
483
+ /**
484
+ * Whether any of these restriction sets carries a function.
485
+ *
486
+ * A function is not data. It cannot be serialized and it cannot cross into
487
+ * another isolate, so a payload built from a value that carries one would
488
+ * arrive enforcing the declarative half and silently not the rest.
489
+ */
490
+ function carriesCustomRestriction(restrictions) {
491
+ for (const set of restrictions) {
492
+ if (set.custom !== undefined) {
493
+ return true;
494
+ }
495
+ }
496
+ return false;
497
+ }
498
+ /**
499
+ * The wire form of these restrictions.
500
+ *
501
+ * Declarative only, and the caller has already been refused if any of them
502
+ * carries a function, so nothing is dropped here.
503
+ */
504
+ function serializeRestrictions(restrictions) {
505
+ return restrictions.map((set) => {
506
+ const wire = {};
507
+ for (const field of LIST_FIELDS) {
508
+ const list = set[field];
509
+ if (list !== undefined) {
510
+ wire[field] = [...list];
511
+ }
512
+ }
513
+ return wire;
514
+ });
515
+ }
516
+ /**
517
+ * Read restrictions out of an untrusted payload.
518
+ *
519
+ * They can only tighten: a value rebuilt by `deserialize()` starts with none,
520
+ * so anything a payload carries here refuses reads that would otherwise have
521
+ * been allowed, and there is no spelling of "no restriction" that lifts one the
522
+ * receiving process would have applied anyway.
523
+ *
524
+ * An unknown key is rejected rather than ignored. A sender that knows a
525
+ * restriction this receiver does not is describing a limit that would be
526
+ * silently unenforced, which is the failure this whole feature exists to avoid.
527
+ */
528
+ function deserializeRestrictions(serialized) {
529
+ if (!('restrictions' in serialized) || serialized.restrictions === undefined) {
530
+ return undefined;
531
+ }
532
+ const declared = serialized.restrictions;
533
+ if (!Array.isArray(declared)) {
534
+ throw new Error('Invalid SerializedSensitiveString: restrictions must be an array');
535
+ }
536
+ if (declared.length === 0) {
537
+ throw new Error('Invalid SerializedSensitiveString: restrictions is empty. A payload that restricts ' +
538
+ 'nothing omits the field rather than carrying an empty list.');
539
+ }
540
+ return declared.map((entry, index) => {
541
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
542
+ throw new Error(`Invalid SerializedSensitiveString: restrictions[${index}] must be an object`);
543
+ }
544
+ const set = {};
545
+ for (const key of Object.keys(entry)) {
546
+ if (!LIST_FIELDS.includes(key)) {
547
+ throw new Error(`Invalid SerializedSensitiveString: restrictions[${index}] carries unknown key '${key}'. ` +
548
+ 'A restriction this receiver cannot enforce is refused rather than ignored.');
549
+ }
550
+ set[key] = entry[key];
551
+ }
552
+ // The lists themselves are validated by `planRestrictions`, which is the
553
+ // same check a locally constructed value gets, so a payload cannot smuggle
554
+ // a pattern shape the constructor would have refused.
555
+ return set;
556
+ });
557
+ }
558
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;AAiOA,gDAsBC;AASD,kDAEC;AAGD,kDAEC;AAQD,gDAEC;AAUD,oDAKC;AAoMD,4CAqBC;AA8ID,oEAoBC;AASD,4DAQC;AAQD,sDAgBC;AAcD,0DA6CC;AAzvBD,2CAAmD;AACnD,uDAAuD;AAEvD;;GAEG;AACH,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAa,sBAAuB,SAAQ,gCAAoB;IAC5C,IAAI,GAAG,wBAAwB,CAAC;IAChC,IAAI,GAAG,oBAAoB,CAAC;IAE9C;QACE,KAAK,CACH,2FAA2F;YACzF,sFAAsF,CACzF,CAAC;IACJ,CAAC;CACF;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K,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACxE,MAAM,IAAI,KAAK,CACb,mDAAmD,KAAK,qBAAqB,CAC9E,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GAA4B,EAAE,CAAC;QAExC,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,4EAA4E,CAC/E,CAAC;YACJ,CAAC;YAEA,GAA+B,CAAC,GAAG,CAAC,GAAI,KAAiC,CAAC,GAAG,CAAC,CAAC;QAClF,CAAC;QAED,yEAAyE;QACzE,2EAA2E;QAC3E,sDAAsD;QACtD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The base every refusal this library raises extends.
3
+ *
4
+ * A caller wants one of two things from an error: to catch one specific
5
+ * failure, or to catch any refusal from this library without enumerating
6
+ * them. A class per failure serves the first, and this base serves the second.
7
+ * `code` is the flat form of the same information, for a log line or a metric
8
+ * that wants a string rather than a prototype chain.
9
+ *
10
+ * A refused operation is what belongs here: an expired value read, a renewal
11
+ * denied, a payload that cannot cross a thread. A failed assertion from
12
+ * `sensitive-testing` does not, and stays outside the hierarchy on purpose: a
13
+ * handler written to swallow refusals must never swallow a leak assertion.
14
+ */
15
+ export declare abstract class SensitiveStringError extends Error {
16
+ /**
17
+ * Stable, greppable discriminator for this kind of refusal.
18
+ *
19
+ * Safe to log: it names the condition and never carries a value.
20
+ */
21
+ abstract readonly code: string;
22
+ }
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,8BAAsB,oBAAqB,SAAQ,KAAK;IACtD;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CAChC"}
package/dist/errors.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SensitiveStringError = void 0;
4
+ /**
5
+ * The base every refusal this library raises extends.
6
+ *
7
+ * A caller wants one of two things from an error: to catch one specific
8
+ * failure, or to catch any refusal from this library without enumerating
9
+ * them. A class per failure serves the first, and this base serves the second.
10
+ * `code` is the flat form of the same information, for a log line or a metric
11
+ * that wants a string rather than a prototype chain.
12
+ *
13
+ * A refused operation is what belongs here: an expired value read, a renewal
14
+ * denied, a payload that cannot cross a thread. A failed assertion from
15
+ * `sensitive-testing` does not, and stays outside the hierarchy on purpose: a
16
+ * handler written to swallow refusals must never swallow a leak assertion.
17
+ */
18
+ class SensitiveStringError extends Error {
19
+ }
20
+ exports.SensitiveStringError = SensitiveStringError;
21
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,MAAsB,oBAAqB,SAAQ,KAAK;CAOvD;AAPD,oDAOC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Return process-global state shared by every loaded copy of core.
3
+ *
4
+ * Symbol.for() is required here: module-local state is duplicated when an
5
+ * application resolves more than one physical installation of this package.
6
+ */
7
+ export declare function getGlobalSingleton<T>(name: string, initialize: () => T): T;
8
+ //# sourceMappingURL=global-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-state.d.ts","sourceRoot":"","sources":["../src/global-state.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,CAY1E"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGlobalSingleton = getGlobalSingleton;
4
+ const GLOBAL_STATE_PREFIX = '@platform-sec/sensitive-string-core';
5
+ /**
6
+ * Return process-global state shared by every loaded copy of core.
7
+ *
8
+ * Symbol.for() is required here: module-local state is duplicated when an
9
+ * application resolves more than one physical installation of this package.
10
+ */
11
+ function getGlobalSingleton(name, initialize) {
12
+ const key = Symbol.for(`${GLOBAL_STATE_PREFIX}/${name}`);
13
+ const globals = globalThis;
14
+ const existing = globals[key];
15
+ if (existing !== undefined) {
16
+ return existing;
17
+ }
18
+ const value = initialize();
19
+ globals[key] = value;
20
+ return value;
21
+ }
22
+ //# sourceMappingURL=global-state.js.map