@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.
- package/dist/bson.d.ts +28 -0
- package/dist/bson.d.ts.map +1 -0
- package/dist/bson.js +37 -0
- package/dist/bson.js.map +1 -0
- package/dist/classification.d.ts +69 -0
- package/dist/classification.d.ts.map +1 -0
- package/dist/classification.js +104 -0
- package/dist/classification.js.map +1 -0
- package/dist/compare.d.ts +36 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +123 -0
- package/dist/compare.js.map +1 -0
- package/dist/context.d.ts +78 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +110 -0
- package/dist/context.js.map +1 -0
- package/dist/derive.d.ts +110 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +153 -0
- package/dist/derive.js.map +1 -0
- package/dist/destination.d.ts +120 -0
- package/dist/destination.d.ts.map +1 -0
- package/dist/destination.js +352 -0
- package/dist/destination.js.map +1 -0
- package/dist/deterministic.d.ts +145 -0
- package/dist/deterministic.d.ts.map +1 -0
- package/dist/deterministic.js +352 -0
- package/dist/deterministic.js.map +1 -0
- package/dist/dev-mode.d.ts +177 -0
- package/dist/dev-mode.d.ts.map +1 -0
- package/dist/dev-mode.js +503 -0
- package/dist/dev-mode.js.map +1 -0
- package/dist/environment.d.ts +181 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +558 -0
- package/dist/environment.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/global-state.d.ts +8 -0
- package/dist/global-state.d.ts.map +1 -0
- package/dist/global-state.js +22 -0
- package/dist/global-state.js.map +1 -0
- package/dist/hash.d.ts +74 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +253 -0
- package/dist/hash.js.map +1 -0
- package/dist/hygiene.d.ts +242 -0
- package/dist/hygiene.d.ts.map +1 -0
- package/dist/hygiene.js +257 -0
- package/dist/hygiene.js.map +1 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +233 -0
- package/dist/index.js.map +1 -0
- package/dist/mask.d.ts +51 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +461 -0
- package/dist/mask.js.map +1 -0
- package/dist/own-property.d.ts +20 -0
- package/dist/own-property.d.ts.map +1 -0
- package/dist/own-property.js +34 -0
- package/dist/own-property.js.map +1 -0
- package/dist/patterns.d.ts +12 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +19 -0
- package/dist/patterns.js.map +1 -0
- package/dist/policy.d.ts +51 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +181 -0
- package/dist/policy.js.map +1 -0
- package/dist/probe.d.ts +141 -0
- package/dist/probe.d.ts.map +1 -0
- package/dist/probe.js +213 -0
- package/dist/probe.js.map +1 -0
- package/dist/redact-copy.d.ts +61 -0
- package/dist/redact-copy.d.ts.map +1 -0
- package/dist/redact-copy.js +217 -0
- package/dist/redact-copy.js.map +1 -0
- package/dist/redact.d.ts +141 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +514 -0
- package/dist/redact.js.map +1 -0
- package/dist/redaction-marker.d.ts +48 -0
- package/dist/redaction-marker.d.ts.map +1 -0
- package/dist/redaction-marker.js +138 -0
- package/dist/redaction-marker.js.map +1 -0
- package/dist/redaction-observer.d.ts +108 -0
- package/dist/redaction-observer.d.ts.map +1 -0
- package/dist/redaction-observer.js +103 -0
- package/dist/redaction-observer.js.map +1 -0
- package/dist/redaction-scope.d.ts +21 -0
- package/dist/redaction-scope.d.ts.map +1 -0
- package/dist/redaction-scope.js +44 -0
- package/dist/redaction-scope.js.map +1 -0
- package/dist/reference.d.ts +101 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +123 -0
- package/dist/reference.js.map +1 -0
- package/dist/regexp.d.ts +25 -0
- package/dist/regexp.d.ts.map +1 -0
- package/dist/regexp.js +61 -0
- package/dist/regexp.js.map +1 -0
- package/dist/release.d.ts +88 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +108 -0
- package/dist/release.js.map +1 -0
- package/dist/reveal-budget.d.ts +148 -0
- package/dist/reveal-budget.d.ts.map +1 -0
- package/dist/reveal-budget.js +314 -0
- package/dist/reveal-budget.js.map +1 -0
- package/dist/revocation.d.ts +168 -0
- package/dist/revocation.d.ts.map +1 -0
- package/dist/revocation.js +541 -0
- package/dist/revocation.js.map +1 -0
- package/dist/sealing.d.ts +283 -0
- package/dist/sealing.d.ts.map +1 -0
- package/dist/sealing.js +523 -0
- package/dist/sealing.js.map +1 -0
- package/dist/sensitive-string.d.ts +919 -0
- package/dist/sensitive-string.d.ts.map +1 -0
- package/dist/sensitive-string.js +2260 -0
- package/dist/sensitive-string.js.map +1 -0
- package/dist/serialized.d.ts +33 -0
- package/dist/serialized.d.ts.map +1 -0
- package/dist/serialized.js +65 -0
- package/dist/serialized.js.map +1 -0
- package/dist/template.d.ts +69 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +158 -0
- package/dist/template.js.map +1 -0
- package/dist/ttl.d.ts +104 -0
- package/dist/ttl.d.ts.map +1 -0
- package/dist/ttl.js +330 -0
- package/dist/ttl.js.map +1 -0
- package/dist/types.d.ts +859 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/dist/winston.d.ts +114 -0
- package/dist/winston.d.ts.map +1 -0
- package/dist/winston.js +170 -0
- package/dist/winston.js.map +1 -0
- package/dist/worker.d.ts +398 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +861 -0
- package/dist/worker.js.map +1 -0
- package/dist/wrap.d.ts +287 -0
- package/dist/wrap.d.ts.map +1 -0
- package/dist/wrap.js +553 -0
- package/dist/wrap.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeterministicRedactionNotAllowedError = void 0;
|
|
4
|
+
exports.createDeterministicRedactor = createDeterministicRedactor;
|
|
5
|
+
exports.deterministicRedaction = deterministicRedaction;
|
|
6
|
+
const derive_js_1 = require("./derive.js");
|
|
7
|
+
const errors_js_1 = require("./errors.js");
|
|
8
|
+
const policy_js_1 = require("./policy.js");
|
|
9
|
+
/**
|
|
10
|
+
* Deterministic redaction: a redacted rendering that tells two values apart.
|
|
11
|
+
*
|
|
12
|
+
* Ordinary redaction answers every value with the same string, which is what
|
|
13
|
+
* makes it safe and what makes a log unreadable. Three lines saying
|
|
14
|
+
* `[REDACTED:sensitive]` may be one subject or three, and the difference is
|
|
15
|
+
* usually the whole question being asked. This replaces the constant with
|
|
16
|
+
* `[REDACTED:sensitive:a1b2c3d4e5f6]`, a stable tag derived from the value, so
|
|
17
|
+
* the lines that share a subject look like they do.
|
|
18
|
+
*
|
|
19
|
+
* ⚠️ This changes the contract. Redacted output has until now carried no
|
|
20
|
+
* information about the value at all, and under this policy it carries a keyed
|
|
21
|
+
* fingerprint of it. Anyone who holds the key and a guess can confirm the
|
|
22
|
+
* guess against a log line; anyone who holds neither still learns which lines
|
|
23
|
+
* concern the same subject, which is itself disclosure and is the point.
|
|
24
|
+
* Adopting it is a decision with a threat model behind it rather than a
|
|
25
|
+
* formatting preference.
|
|
26
|
+
*
|
|
27
|
+
* The tag is an HMAC and there is no unkeyed mode, for the reason
|
|
28
|
+
* {@link deriveKeyedToken} spells out: the values that get redacted are
|
|
29
|
+
* low-entropy by definition, an email address under a plain SHA-256 is a
|
|
30
|
+
* wordlist lookup, and a redacted log is exactly where an offline attack
|
|
31
|
+
* happens. The factory therefore refuses without a key rather than defaulting
|
|
32
|
+
* to a bare digest.
|
|
33
|
+
*
|
|
34
|
+
* Two things about the tag are worth settling before adopting it, and neither
|
|
35
|
+
* is in the design sketch's threat model.
|
|
36
|
+
*
|
|
37
|
+
* The policy is process-global, so one registration tags every rendering the
|
|
38
|
+
* process produces, including the ones bound for somewhere else. The error
|
|
39
|
+
* tracking and APM integrations scrub through `redactCopy`, so an instance in a
|
|
40
|
+
* Sentry event, a Bugsnag report, a Rollbar item or a Datadog span carries the
|
|
41
|
+
* tag. What a vendor flattened into a plain object before the scrub ran does
|
|
42
|
+
* not: `sensitive-rollbar`'s flattened path has no value left to derive from
|
|
43
|
+
* and writes the constant. Correlating a subject across a log aggregator and a
|
|
44
|
+
* third-party error tracker is usually the point, and it is worth deciding
|
|
45
|
+
* rather than discovering.
|
|
46
|
+
*
|
|
47
|
+
* And the key is not the only way to confirm a guess. Anyone who can get a
|
|
48
|
+
* value of their own choosing redacted into output they can read has an oracle:
|
|
49
|
+
* they submit a guess, read its tag, and compare it with a tag from the log. A
|
|
50
|
+
* request body echoed into a log line is the ordinary shape of that, and
|
|
51
|
+
* `redactSerialized` is the sharpest one, because it takes both the class and
|
|
52
|
+
* the value off an untrusted payload. HMAC-SHA256 is a PRF, so the oracle does
|
|
53
|
+
* not recover the key, and it does reduce "an attacker who holds the key" to
|
|
54
|
+
* "an attacker who can reach the service".
|
|
55
|
+
*
|
|
56
|
+
* Two things about where this runs are worth knowing before adopting it.
|
|
57
|
+
* Redaction is not a reveal: it happens under `#readRawValue('safe')`, so it
|
|
58
|
+
* produces no audit record, charges no reveal budget, and is not refused by an
|
|
59
|
+
* expired deadline or a revocation, all of which are deliberate, because a log
|
|
60
|
+
* line must keep redacting after a value dies. And it runs on every
|
|
61
|
+
* `toString()`, so a log-heavy path pays one HMAC per rendering; there is no
|
|
62
|
+
* cache, because a value-keyed cache is a table of plaintexts with the
|
|
63
|
+
* lifetime of the process.
|
|
64
|
+
*/
|
|
65
|
+
/** The default tag prefix, which keeps the rendering greppable as `[REDACTED:...]`. */
|
|
66
|
+
const DEFAULT_PREFIX = 'REDACTED';
|
|
67
|
+
/**
|
|
68
|
+
* What a prefix may contain.
|
|
69
|
+
*
|
|
70
|
+
* Wide enough for the `REDACTED:sensitive` form {@link deterministicRedaction}
|
|
71
|
+
* builds, and narrow enough that the rendering stays one parseable token: no
|
|
72
|
+
* whitespace, no brackets, nothing that would make `[prefix:tag]` ambiguous to
|
|
73
|
+
* the log search that has to find it.
|
|
74
|
+
*/
|
|
75
|
+
const PREFIX_PATTERN = /^[A-Za-z0-9_.:-]{1,64}$/;
|
|
76
|
+
/**
|
|
77
|
+
* The string the factory renders once to check the caller's `format`.
|
|
78
|
+
*
|
|
79
|
+
* Not a secret and not a canary: it exists so a `format` that throws or answers
|
|
80
|
+
* with something other than a string fails at configuration time rather than
|
|
81
|
+
* in the middle of the first log line that needed redacting.
|
|
82
|
+
*/
|
|
83
|
+
const FORMAT_PROBE = 'deterministic-redactor-format-probe';
|
|
84
|
+
/**
|
|
85
|
+
* Raised when a sensitivity class may not be given a correlation tag.
|
|
86
|
+
*
|
|
87
|
+
* Only `credential` is refused, and only by {@link deterministicRedaction}.
|
|
88
|
+
* {@link createDeterministicRedactor} knows no class and refuses nothing.
|
|
89
|
+
*/
|
|
90
|
+
class DeterministicRedactionNotAllowedError extends errors_js_1.SensitiveStringError {
|
|
91
|
+
klass;
|
|
92
|
+
name = 'DeterministicRedactionNotAllowedError';
|
|
93
|
+
code = 'deterministic-redaction-refused';
|
|
94
|
+
constructor(klass) {
|
|
95
|
+
super(`deterministicRedaction: a '${klass}' value does not get a correlation tag. A credential is ` +
|
|
96
|
+
'guessable by construction, so a stable tag turns every log line into an oracle for ' +
|
|
97
|
+
'confirming a guess against, for anyone who later obtains the key. Tag the sensitive ' +
|
|
98
|
+
'value the credential belongs to instead. A deployment that has weighed this and still ' +
|
|
99
|
+
'wants it assembles the policy itself around createDeterministicRedactor(), which is one ' +
|
|
100
|
+
'line that shows up in review.');
|
|
101
|
+
this.klass = klass;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.DeterministicRedactionNotAllowedError = DeterministicRedactionNotAllowedError;
|
|
105
|
+
/**
|
|
106
|
+
* Build a redaction function that derives a stable tag from the value.
|
|
107
|
+
*
|
|
108
|
+
* The primitive, for a caller assembling a {@link SensitivityPolicy} by hand.
|
|
109
|
+
* {@link deterministicRedaction} is the one-liner over it and is what most
|
|
110
|
+
* callers want, because it keeps the rest of the class's policy intact.
|
|
111
|
+
*
|
|
112
|
+
* Everything that can be wrong with the options is settled at construction
|
|
113
|
+
* rather than at the first redaction: a key below the entropy floor, a length
|
|
114
|
+
* below the collision floor, a domain component carrying a NUL, a malformed
|
|
115
|
+
* prefix, a `format` that does not answer with a string. A redaction runs on
|
|
116
|
+
* the path a log line takes, and a configuration error discovered there is
|
|
117
|
+
* discovered by a log line failing.
|
|
118
|
+
*
|
|
119
|
+
* The options are read once and the scope is copied, so mutating either
|
|
120
|
+
* afterwards moves nothing. A redactor that answered differently on Tuesday
|
|
121
|
+
* because a caller pushed onto the array they passed would break the one
|
|
122
|
+
* property the feature exists for.
|
|
123
|
+
*
|
|
124
|
+
* @param options - The key, the scope, the tag length, and the rendering
|
|
125
|
+
* @returns A function suitable as a policy's `redact`
|
|
126
|
+
*
|
|
127
|
+
* @throws TypeError For a missing or mistyped key, a malformed prefix, a
|
|
128
|
+
* domain component that is not a string or contains a NUL, or a
|
|
129
|
+
* `format` that does not return a string.
|
|
130
|
+
* @throws RangeError If the key is shorter than `MIN_DERIVATION_KEY_BYTES`
|
|
131
|
+
* or `length` is outside the documented bounds.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* registerPolicy(
|
|
136
|
+
* { ...getPolicy('sensitive'), redact: createDeterministicRedactor({ key }) },
|
|
137
|
+
* { overwrite: true }
|
|
138
|
+
* );
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
function createDeterministicRedactor(options) {
|
|
142
|
+
return buildRedactor('createDeterministicRedactor', options).redact;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The shared body of both factories.
|
|
146
|
+
*
|
|
147
|
+
* `operation` is the name of the function the caller actually called, so a
|
|
148
|
+
* malformed prefix passed to `deterministicRedaction` is not reported against
|
|
149
|
+
* a function that appears nowhere in the caller's code. It is the same reason
|
|
150
|
+
* `planHash` takes one. The refusals that come from `derive.ts` keep naming
|
|
151
|
+
* `deriveKeyedToken`, which is exported and documented, and `entityHandle`
|
|
152
|
+
* reports them the same way.
|
|
153
|
+
*/
|
|
154
|
+
function buildRedactor(operation, options) {
|
|
155
|
+
if (options === null || typeof options !== 'object') {
|
|
156
|
+
throw new TypeError(`${operation}: options must carry at least a key`);
|
|
157
|
+
}
|
|
158
|
+
const prefix = requirePrefix(operation, options.prefix);
|
|
159
|
+
const format = options.format ?? defaultFormat;
|
|
160
|
+
if (typeof format !== 'function') {
|
|
161
|
+
throw new TypeError(`${operation}: format must be a function`);
|
|
162
|
+
}
|
|
163
|
+
const derivation = {
|
|
164
|
+
key: copyKey(options.key),
|
|
165
|
+
domain: requireScope(operation, options.scope),
|
|
166
|
+
...(options.length === undefined ? {} : { length: options.length }),
|
|
167
|
+
};
|
|
168
|
+
(0, derive_js_1.assertKeyedDerivationOptions)(derivation);
|
|
169
|
+
const redact = (value) => format(prefix, (0, derive_js_1.deriveKeyedToken)(value, derivation));
|
|
170
|
+
refuseNonString(operation, redact(FORMAT_PROBE));
|
|
171
|
+
return {
|
|
172
|
+
redact,
|
|
173
|
+
markerPattern: deriveMarkerPattern(format, prefix, derivation.length ?? derive_js_1.DEFAULT_DERIVED_TOKEN_LENGTH),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A policy for `klass` whose redaction carries a correlation tag.
|
|
178
|
+
*
|
|
179
|
+
* The currently registered policy for the class with its `redact` replaced, so
|
|
180
|
+
* `requireConstantTimeEquals`, `allowMask`, `checkRevealAllowed`, the advisory
|
|
181
|
+
* flags and every deadline rule survive. Registering a hand-written policy
|
|
182
|
+
* instead is how a class quietly loses one of those.
|
|
183
|
+
*
|
|
184
|
+
* The class is mixed into the derivation alongside the caller's scope, so the
|
|
185
|
+
* same string classified two ways gets two tags. That matches how
|
|
186
|
+
* `entityHandle` derives, and it means a `serialize()` payload caught by a
|
|
187
|
+
* redaction walk renders the same tag as the instance it came from, since both
|
|
188
|
+
* are redacted through the same class's policy.
|
|
189
|
+
*
|
|
190
|
+
* `credential` is refused. See {@link DeterministicRedactionNotAllowedError};
|
|
191
|
+
* the refusal is hard-coded rather than read from an advisory flag, because
|
|
192
|
+
* every existing flag answers a different question and overloading one would
|
|
193
|
+
* make it mean two things.
|
|
194
|
+
*
|
|
195
|
+
* @param klass - The class whose redaction is being replaced
|
|
196
|
+
* @param options - The key, the scope, the tag length, and the rendering
|
|
197
|
+
* @returns A policy to hand to `registerPolicy(..., { overwrite: true })`
|
|
198
|
+
*
|
|
199
|
+
* @throws DeterministicRedactionNotAllowedError If `klass` is `credential`.
|
|
200
|
+
* @throws Error If no policy is registered for `klass`.
|
|
201
|
+
* @throws TypeError, RangeError As {@link createDeterministicRedactor}.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* registerPolicy(
|
|
206
|
+
* deterministicRedaction('sensitive', { key: process.env.REDACTION_HMAC_KEY! }),
|
|
207
|
+
* { overwrite: true }
|
|
208
|
+
* );
|
|
209
|
+
*
|
|
210
|
+
* String(new SensitiveString('alice@example.com', 'sensitive'));
|
|
211
|
+
* // '[REDACTED:sensitive:5f2a91c0b74e]'
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
function deterministicRedaction(klass, options) {
|
|
215
|
+
if (klass === 'credential') {
|
|
216
|
+
throw new DeterministicRedactionNotAllowedError(klass);
|
|
217
|
+
}
|
|
218
|
+
// Read before anything is validated, so a class with no policy is reported as
|
|
219
|
+
// the missing registration it is rather than as a key problem.
|
|
220
|
+
const base = (0, policy_js_1.getPolicy)(klass);
|
|
221
|
+
if (options === null || typeof options !== 'object') {
|
|
222
|
+
throw new TypeError('deterministicRedaction: options must carry at least a key');
|
|
223
|
+
}
|
|
224
|
+
const { redact, markerPattern } = buildRedactor('deterministicRedaction', {
|
|
225
|
+
...options,
|
|
226
|
+
prefix: options.prefix ?? `${DEFAULT_PREFIX}:${klass}`,
|
|
227
|
+
// Scope first, then the class, so a caller cannot collide the two by naming
|
|
228
|
+
// a scope after a class.
|
|
229
|
+
scope: [...requireScope('deterministicRedaction', options.scope), klass],
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
...base,
|
|
233
|
+
name: klass,
|
|
234
|
+
redact,
|
|
235
|
+
// Declared so the guards that refuse to send a redaction onward can still
|
|
236
|
+
// recognize one. Two probes of different lengths is how they learn a
|
|
237
|
+
// constant policy's marker, and a value-dependent policy defeats that test
|
|
238
|
+
// by construction. Dropped rather than guessed when a caller's `format`
|
|
239
|
+
// does not embed the tag verbatim.
|
|
240
|
+
...(markerPattern === undefined ? {} : { markerPattern }),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function defaultFormat(prefix, tag) {
|
|
244
|
+
return `[${prefix}:${tag}]`;
|
|
245
|
+
}
|
|
246
|
+
function requirePrefix(operation, prefix) {
|
|
247
|
+
if (prefix === undefined) {
|
|
248
|
+
return DEFAULT_PREFIX;
|
|
249
|
+
}
|
|
250
|
+
if (typeof prefix !== 'string' || !PREFIX_PATTERN.test(prefix)) {
|
|
251
|
+
throw new TypeError(`${operation}: prefix must match [A-Za-z0-9_.:-]{1,64}, so the rendering stays one token ` +
|
|
252
|
+
'a log search can find');
|
|
253
|
+
}
|
|
254
|
+
return prefix;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The scope as domain components, copied.
|
|
258
|
+
*
|
|
259
|
+
* A bare string is one component rather than a character sequence, so
|
|
260
|
+
* `scope: 'tenant-7'` and `scope: ['tenant-7']` are the same domain. Component
|
|
261
|
+
* contents are checked by {@link assertKeyedDerivationOptions}, which owns the
|
|
262
|
+
* NUL rule.
|
|
263
|
+
*
|
|
264
|
+
* The copy is the point, and it is the same rule `expiresAt` follows: the
|
|
265
|
+
* redactor reads the components on every rendering, so keeping the caller's
|
|
266
|
+
* array by reference would let a `push()` after construction move every tag
|
|
267
|
+
* that followed it, and would let a component past the validation that ran here
|
|
268
|
+
* once. A non-string pushed in later does not produce a wrong tag, it makes
|
|
269
|
+
* `redact()` throw, which happens on the path a log line takes.
|
|
270
|
+
*/
|
|
271
|
+
function requireScope(operation, scope) {
|
|
272
|
+
if (scope === undefined) {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
if (typeof scope === 'string') {
|
|
276
|
+
return [scope];
|
|
277
|
+
}
|
|
278
|
+
// Checked through an `unknown` binding rather than on `scope` itself:
|
|
279
|
+
// `Array.isArray` narrows to `any[]`, which would launder the element type
|
|
280
|
+
// straight past the checker on the way out.
|
|
281
|
+
const components = scope;
|
|
282
|
+
if (!Array.isArray(components)) {
|
|
283
|
+
throw new TypeError(`${operation}: scope must be a string or an array of strings`);
|
|
284
|
+
}
|
|
285
|
+
return [...scope];
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Refuse a rendering that is not a string.
|
|
289
|
+
*
|
|
290
|
+
* Typed `unknown` on purpose: `format` declares a string return and a JavaScript
|
|
291
|
+
* caller is under no obligation to honour it, and a number reaching `toString()`
|
|
292
|
+
* would be a redaction that fails the type it promised somewhere far from here.
|
|
293
|
+
*/
|
|
294
|
+
/**
|
|
295
|
+
* The key as bytes this redactor owns.
|
|
296
|
+
*
|
|
297
|
+
* The same rule the scope follows, and it matters more here: the key is read on
|
|
298
|
+
* every rendering, so keeping the caller's array by reference would let a
|
|
299
|
+
* zeroize after construction move every tag afterwards, silently and with no
|
|
300
|
+
* error, since a zeroed key is still a valid key. Copying also encodes a string
|
|
301
|
+
* key once instead of once per rendering.
|
|
302
|
+
*
|
|
303
|
+
* Anything that is neither bytes nor a string is passed through untouched, so
|
|
304
|
+
* `assertKeyedDerivationOptions` raises its own message for it rather than this
|
|
305
|
+
* function inventing a second one.
|
|
306
|
+
*/
|
|
307
|
+
function copyKey(key) {
|
|
308
|
+
if (typeof key === 'string') {
|
|
309
|
+
return new TextEncoder().encode(key);
|
|
310
|
+
}
|
|
311
|
+
return key instanceof Uint8Array ? new Uint8Array(key) : key;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* A pattern that recognizes what this redactor renders.
|
|
315
|
+
*
|
|
316
|
+
* Derived by rendering two probe tags and finding where they differ, rather
|
|
317
|
+
* than assembled from the prefix, so it holds for a caller's `format` as well
|
|
318
|
+
* as for the default one. A format that does not embed the tag verbatim, such
|
|
319
|
+
* as one that upper-cases it, reconstructs to something else and yields no
|
|
320
|
+
* pattern at all, which is the honest answer: a wrong pattern is worse than
|
|
321
|
+
* none, because it reads as coverage.
|
|
322
|
+
*/
|
|
323
|
+
function deriveMarkerPattern(format, prefix, length) {
|
|
324
|
+
const first = 'a'.repeat(length);
|
|
325
|
+
const second = 'b'.repeat(length);
|
|
326
|
+
const rendered = format(prefix, first);
|
|
327
|
+
const other = format(prefix, second);
|
|
328
|
+
if (typeof rendered !== 'string' || typeof other !== 'string') {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
// Every occurrence, because a prefix may itself be a run of the probe
|
|
332
|
+
// character and the first match would then be the wrong one.
|
|
333
|
+
for (let at = rendered.indexOf(first); at >= 0; at = rendered.indexOf(first, at + 1)) {
|
|
334
|
+
const head = rendered.slice(0, at);
|
|
335
|
+
const tail = rendered.slice(at + length);
|
|
336
|
+
if (other === head + second + tail) {
|
|
337
|
+
return new RegExp(`${escapeRegExp(head)}[0-9a-f]{${length}}${escapeRegExp(tail)}`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
/** Every character with a meaning inside a pattern, taken literally. */
|
|
343
|
+
function escapeRegExp(literal) {
|
|
344
|
+
return literal.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
345
|
+
}
|
|
346
|
+
function refuseNonString(operation, rendered) {
|
|
347
|
+
if (typeof rendered !== 'string') {
|
|
348
|
+
throw new TypeError(`${operation}: format must return a string, received ` +
|
|
349
|
+
(rendered === null ? 'null' : typeof rendered));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=deterministic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deterministic.js","sourceRoot":"","sources":["../src/deterministic.ts"],"names":[],"mappings":";;;AA6MA,kEAIC;AA8FD,wDAmCC;AAlVD,2CAKqB;AACrB,2CAAmD;AACnD,2CAAwC;AAGxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,uFAAuF;AACvF,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,qCAAqC,CAAC;AA4D3D;;;;;GAKG;AACH,MAAa,qCAAsC,SAAQ,gCAAoB;IAIxD;IAHH,IAAI,GAAG,uCAAuC,CAAC;IAC/C,IAAI,GAAG,iCAAiC,CAAC;IAE3D,YAAqB,KAAuB;QAC1C,KAAK,CACH,8BAA8B,KAAK,0DAA0D;YAC3F,qFAAqF;YACrF,sFAAsF;YACtF,wFAAwF;YACxF,0FAA0F;YAC1F,+BAA+B,CAClC,CAAC;QARiB,UAAK,GAAL,KAAK,CAAkB;IAS5C,CAAC;CACF;AAdD,sFAcC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,2BAA2B,CACzC,OAAqC;IAErC,OAAO,aAAa,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC;AACtE,CAAC;AASD;;;;;;;;;GASG;AACH,SAAS,aAAa,CACpB,SAAmE,EACnE,OAAqC;IAErC,IAAI,OAAO,KAAK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
+
/**
|
|
3
|
+
* The value an exposure is recorded for, or a way to get one.
|
|
4
|
+
*
|
|
5
|
+
* A thunk, because only `showPartialValue` reads it and a sealed value's
|
|
6
|
+
* byte-oriented reveal holds a `Buffer`. Decoding one into a string on every
|
|
7
|
+
* reveal, to decide not to print it, would put back exactly the plaintext
|
|
8
|
+
* string the byte path exists to avoid.
|
|
9
|
+
*/
|
|
10
|
+
type ExposedValue = string | (() => string);
|
|
11
|
+
/** Time window options for the repeated-reveal warning. */
|
|
12
|
+
export interface RepeatedRevealOptions {
|
|
13
|
+
/** Reveals within one window that trigger the warning. */
|
|
14
|
+
threshold: number;
|
|
15
|
+
/** Window length in milliseconds. */
|
|
16
|
+
window: number;
|
|
17
|
+
}
|
|
18
|
+
/** Logging options for exposures. */
|
|
19
|
+
export interface RevealLogOptions {
|
|
20
|
+
/** Whether every exposure is logged, rather than only the unexplained ones. */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Where the lines go. Defaults to `console.warn`. */
|
|
23
|
+
logger?: (message: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the log line shows the first few characters of the value.
|
|
26
|
+
*
|
|
27
|
+
* ⚠️ A real, if small, disclosure. Development only.
|
|
28
|
+
*/
|
|
29
|
+
showPartialValue?: boolean;
|
|
30
|
+
/** Characters the partial rendering shows. Defaults to 4, capped at 8. */
|
|
31
|
+
partialLength?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Development mode configuration, as given to {@link setDevMode}. */
|
|
34
|
+
export interface DevModeConfig {
|
|
35
|
+
/** The one switch. Everything else is inert while this is false. */
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
/** Capture the stack of each exposure. */
|
|
38
|
+
captureStackTraces?: boolean;
|
|
39
|
+
/** Capture the stack of each construction. */
|
|
40
|
+
captureCreationStack?: boolean;
|
|
41
|
+
/** Warn when one value is exposed repeatedly in a short window. */
|
|
42
|
+
warnOnRepeatedReveal?: RepeatedRevealOptions | false;
|
|
43
|
+
/** Warn when an exposure has no reveal context, explicit or ambient. */
|
|
44
|
+
warnOnMissingContext?: boolean;
|
|
45
|
+
/** Log every exposure, not only the unexplained ones. */
|
|
46
|
+
logReveals?: RevealLogOptions | false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What development mode recorded about one value.
|
|
50
|
+
*
|
|
51
|
+
* Read through `SensitiveString.__devInfo`, which is `undefined` unless
|
|
52
|
+
* development mode is on.
|
|
53
|
+
*/
|
|
54
|
+
export interface DevInfo {
|
|
55
|
+
/** When the value was constructed. */
|
|
56
|
+
readonly createdAt: Date;
|
|
57
|
+
/** The construction stack, when `captureCreationStack` was set. */
|
|
58
|
+
readonly creationStack?: string;
|
|
59
|
+
/** Exposures since construction. Exact, and never forgotten. */
|
|
60
|
+
readonly revealCount: number;
|
|
61
|
+
/** The most recent exposure times, oldest first, capped at 64. */
|
|
62
|
+
readonly revealTimestamps: readonly number[];
|
|
63
|
+
/** The stack of the most recent exposure, when `captureStackTraces` was set. */
|
|
64
|
+
readonly lastRevealStack?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Configuration with every default resolved, which is what the hooks read. */
|
|
67
|
+
interface ResolvedDevMode {
|
|
68
|
+
readonly enabled: boolean;
|
|
69
|
+
readonly captureStackTraces: boolean;
|
|
70
|
+
readonly captureCreationStack: boolean;
|
|
71
|
+
readonly warnOnMissingContext: boolean;
|
|
72
|
+
readonly repeated: Readonly<RepeatedRevealOptions> | undefined;
|
|
73
|
+
readonly log: {
|
|
74
|
+
readonly enabled: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Left unresolved on purpose. Binding `console.warn` here would capture
|
|
77
|
+
* whatever it was at configuration time, and a test that installs a spy
|
|
78
|
+
* afterwards would see nothing.
|
|
79
|
+
*/
|
|
80
|
+
readonly logger: ((message: string) => void) | undefined;
|
|
81
|
+
readonly showPartialValue: boolean;
|
|
82
|
+
readonly partialLength: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** What is recorded per value. */
|
|
86
|
+
interface DevRecord {
|
|
87
|
+
readonly createdAt: number;
|
|
88
|
+
readonly creationStack: string | undefined;
|
|
89
|
+
revealCount: number;
|
|
90
|
+
/** Ring of the last {@link TIMESTAMP_CAPACITY} exposure times. */
|
|
91
|
+
readonly timestamps: number[];
|
|
92
|
+
/** Where the next timestamp is written once the ring is full. */
|
|
93
|
+
ringNext: number;
|
|
94
|
+
lastRevealStack: string | undefined;
|
|
95
|
+
/** Start of the window the repeated-reveal warning is counting in. */
|
|
96
|
+
windowStart: number;
|
|
97
|
+
/** Exposures counted in that window. */
|
|
98
|
+
windowCount: number;
|
|
99
|
+
}
|
|
100
|
+
interface DevModeState {
|
|
101
|
+
config: ResolvedDevMode;
|
|
102
|
+
/**
|
|
103
|
+
* Keyed by the instance, so a value's history is collected with the value and
|
|
104
|
+
* a long-lived process cannot accumulate records for values it has dropped.
|
|
105
|
+
* Typed by `object` rather than by the class, because a second physical copy
|
|
106
|
+
* of core reaching this same global state has its own class identity.
|
|
107
|
+
*/
|
|
108
|
+
readonly records: WeakMap<object, DevRecord>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Process-global, for the reason the policy registry is: an application that
|
|
112
|
+
* resolves two physical copies of core must not have to configure each one.
|
|
113
|
+
*/
|
|
114
|
+
export declare const devMode: DevModeState;
|
|
115
|
+
/**
|
|
116
|
+
* Configure development mode. Off until this is called with `enabled: true`.
|
|
117
|
+
*
|
|
118
|
+
* A value records nothing about a period during which development mode was off,
|
|
119
|
+
* so turn it on before constructing the values you intend to inspect.
|
|
120
|
+
*
|
|
121
|
+
* @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.
|
|
122
|
+
* @throws TypeError If the configuration, or one of its options, has the wrong type.
|
|
123
|
+
* @throws RangeError If a count is out of range.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* if (process.env['NODE_ENV'] === 'development') {
|
|
128
|
+
* setDevMode({
|
|
129
|
+
* enabled: true,
|
|
130
|
+
* captureStackTraces: true,
|
|
131
|
+
* warnOnMissingContext: true,
|
|
132
|
+
* logReveals: { enabled: true, showPartialValue: true },
|
|
133
|
+
* });
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function setDevMode(config: DevModeConfig): void;
|
|
138
|
+
/**
|
|
139
|
+
* The current configuration, with every default resolved.
|
|
140
|
+
*
|
|
141
|
+
* The result is frozen and is accepted by {@link setDevMode}, so it can be
|
|
142
|
+
* saved and restored. `false` and an absent option both resolve to the disabled
|
|
143
|
+
* object form, which behaves identically.
|
|
144
|
+
*/
|
|
145
|
+
export declare function getDevModeConfig(): Readonly<DevModeConfig>;
|
|
146
|
+
/**
|
|
147
|
+
* Run `fn` with `config` in force, restoring the previous configuration after.
|
|
148
|
+
*
|
|
149
|
+
* Synchronous. The configuration is process-global, so it cannot follow one
|
|
150
|
+
* asynchronous task without following every other task interleaved with it; a
|
|
151
|
+
* function that returns a promise has its configuration restored when it
|
|
152
|
+
* returns, not when it settles.
|
|
153
|
+
*/
|
|
154
|
+
export declare function withDevMode<T>(config: DevModeConfig, fn: () => T): T;
|
|
155
|
+
/**
|
|
156
|
+
* Record the construction of a value.
|
|
157
|
+
*
|
|
158
|
+
* Called from the constructor once its arguments have been accepted, so a
|
|
159
|
+
* rejected construction leaves no record behind.
|
|
160
|
+
*/
|
|
161
|
+
export declare function recordCreation(instance: object): void;
|
|
162
|
+
/**
|
|
163
|
+
* Record one exposure of a value.
|
|
164
|
+
*
|
|
165
|
+
* Called from the raw-value gate for exactly the reads an audit hook sees: the
|
|
166
|
+
* ones where the value reaches the caller. A comparison reads the value without
|
|
167
|
+
* disclosing it and is not counted, and neither is a read that only feeds
|
|
168
|
+
* redaction. A read the gate refused never reaches here, so a denied reveal is
|
|
169
|
+
* not counted as one.
|
|
170
|
+
*/
|
|
171
|
+
export declare function recordReveal(instance: object, klass: SensitivityClass, label: string | undefined, value: ExposedValue, ctx: RevealContext | null | undefined, details: RevealDetails): void;
|
|
172
|
+
/**
|
|
173
|
+
* What development mode recorded about one value, or undefined when it is off.
|
|
174
|
+
*/
|
|
175
|
+
export declare function readDevInfo(instance: object): DevInfo | undefined;
|
|
176
|
+
export {};
|
|
177
|
+
//# sourceMappingURL=dev-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-mode.d.ts","sourceRoot":"","sources":["../src/dev-mode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA6CjF;;;;;;;GAOG;AACH,KAAK,YAAY,GAAG,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;AAE5C,2DAA2D;AAC3D,MAAM,WAAW,qBAAqB;IACpC,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC/B,+EAA+E;IAC/E,OAAO,EAAE,OAAO,CAAC;IACjB,sDAAsD;IACtD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,OAAO,EAAE,OAAO,CAAC;IAEjB,0CAA0C;IAC1C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,8CAA8C;IAC9C,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,mEAAmE;IACnE,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAAC;IAErD,wEAAwE;IACxE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,yDA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