@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
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,859 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sensitivity classification for data protection.
|
|
3
|
+
*
|
|
4
|
+
* Simplified to two classes based on the only behavioral difference that matters:
|
|
5
|
+
* - `credential`: Requires constant-time comparison (passwords, API keys, tokens)
|
|
6
|
+
* - `sensitive`: Everything else that shouldn't leak (PII, business-sensitive data)
|
|
7
|
+
*
|
|
8
|
+
* For finer-grained categorization (compliance, audit logs), use the optional `label` field.
|
|
9
|
+
*/
|
|
10
|
+
export type SensitivityClass = 'credential' | 'sensitive';
|
|
11
|
+
/**
|
|
12
|
+
* Precedence ordering for combining sensitivity classes.
|
|
13
|
+
* Higher index = more restrictive.
|
|
14
|
+
* credential > sensitive (credentials require constant-time comparison)
|
|
15
|
+
*/
|
|
16
|
+
export declare const SENSITIVITY_PRECEDENCE: readonly SensitivityClass[];
|
|
17
|
+
/**
|
|
18
|
+
* Options shared by every SensitiveString feature.
|
|
19
|
+
*
|
|
20
|
+
* There is one options object rather than a fourth constructor argument per
|
|
21
|
+
* feature, so features compose instead of competing. As an interface, it can
|
|
22
|
+
* also be extended through declaration merging by integration packages.
|
|
23
|
+
*/
|
|
24
|
+
export interface SensitiveStringOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Lifetime in milliseconds, measured from construction.
|
|
27
|
+
*
|
|
28
|
+
* `0` means the value is already expired, which is the most conservative TTL
|
|
29
|
+
* a caller can ask for. Mutually exclusive with `expiresAt`.
|
|
30
|
+
*/
|
|
31
|
+
ttl?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Absolute deadline. Mutually exclusive with `ttl`.
|
|
34
|
+
*
|
|
35
|
+
* Read once, at construction, so mutating the Date afterwards does not move
|
|
36
|
+
* the deadline. A deadline in the past yields a value that is already expired.
|
|
37
|
+
*/
|
|
38
|
+
expiresAt?: Date;
|
|
39
|
+
/**
|
|
40
|
+
* Whether `renew()` may extend the deadline.
|
|
41
|
+
*
|
|
42
|
+
* Defaults to `false` for `credential` and `true` for `sensitive`. A policy
|
|
43
|
+
* that sets `allowRenewal: false` forbids renewal outright, and this option
|
|
44
|
+
* cannot lift that.
|
|
45
|
+
*/
|
|
46
|
+
allowRenewal?: boolean;
|
|
47
|
+
/** Total number of renewals allowed. Unlimited when unset. */
|
|
48
|
+
maxRenewals?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Called once when expiry is first detected, on the value and on everything
|
|
51
|
+
* derived from it. Errors thrown by it are swallowed.
|
|
52
|
+
*/
|
|
53
|
+
onExpire?: () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Total number of times this value may be exposed, over its whole life.
|
|
56
|
+
*
|
|
57
|
+
* `0` means it may never be exposed, which is the most conservative budget a
|
|
58
|
+
* caller can ask for. The count is shared with everything derived from the
|
|
59
|
+
* value, and nothing resets it.
|
|
60
|
+
*/
|
|
61
|
+
maxReveals?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Length of the sliding rate-limit window, in milliseconds.
|
|
64
|
+
*
|
|
65
|
+
* Must be given together with `maxRevealsPerWindow`: either alone is no rate
|
|
66
|
+
* limit at all.
|
|
67
|
+
*/
|
|
68
|
+
revealWindow?: number;
|
|
69
|
+
/** Exposures allowed within `revealWindow`. Must be at least 1. */
|
|
70
|
+
maxRevealsPerWindow?: number;
|
|
71
|
+
/**
|
|
72
|
+
* A revocation list consulted on every read of this value, in addition to the
|
|
73
|
+
* process-global one that `revokeByLabel()` and `revokeByPattern()` write.
|
|
74
|
+
*
|
|
75
|
+
* It is matched against the label this value is constructed with. A value
|
|
76
|
+
* with no label is still consulted for, with `undefined` as the label, so a
|
|
77
|
+
* registry decides for itself whether it can refuse one; the built-in
|
|
78
|
+
* `RevocationList` cannot, and answers false.
|
|
79
|
+
*/
|
|
80
|
+
revocationRegistry?: RevocationRegistry;
|
|
81
|
+
/**
|
|
82
|
+
* Where this value may be read: an environment, a region, a datacenter, or a
|
|
83
|
+
* predicate of the caller's own.
|
|
84
|
+
*
|
|
85
|
+
* Checked against the process-global {@link setEnvironmentInfo} declaration
|
|
86
|
+
* on every read, in the same gate expiry and revocation sit in, so a
|
|
87
|
+
* substring or a template result is restricted exactly as its source is.
|
|
88
|
+
*
|
|
89
|
+
* A list is accepted as well as a single set, and every set has to pass. That
|
|
90
|
+
* is what lets a value derived from two restricted values carry both, and
|
|
91
|
+
* what lets the wire format carry them back.
|
|
92
|
+
*/
|
|
93
|
+
restrictions?: EnvironmentRestrictions | readonly EnvironmentRestrictions[];
|
|
94
|
+
/**
|
|
95
|
+
* Where this value may go: the sinks and the hosts it may be revealed toward.
|
|
96
|
+
*
|
|
97
|
+
* Checked on every exposing read against the `sink` and `host` tags of the
|
|
98
|
+
* reveal context the read runs under, in the same gate expiry, revocation
|
|
99
|
+
* and the environment restrictions sit in. The integrations write those two
|
|
100
|
+
* tags on every reveal they perform, the HTTP clients from the request URL;
|
|
101
|
+
* a context that states neither is refused, because a reveal that does not
|
|
102
|
+
* say where the value is going is the reveal this option exists to stop.
|
|
103
|
+
*
|
|
104
|
+
* A comparison is not checked: `equals()` sends the value nowhere.
|
|
105
|
+
*
|
|
106
|
+
* A list is accepted as well as a single binding, and every binding has to
|
|
107
|
+
* pass. That is what lets a value derived from two bound values carry both,
|
|
108
|
+
* and what lets the wire format carry them back.
|
|
109
|
+
*/
|
|
110
|
+
destinations?: DestinationBinding | readonly DestinationBinding[];
|
|
111
|
+
/**
|
|
112
|
+
* A verification this value waits for before it can be read.
|
|
113
|
+
*
|
|
114
|
+
* Every exposing read refuses with `UnreleasedSensitiveValueError` until the
|
|
115
|
+
* promise resolves `true`. Anything else it resolves to, or a rejection,
|
|
116
|
+
* refuses for good: a verification that did not answer yes has answered no,
|
|
117
|
+
* and a caller who wants to try again constructs a new value. A comparison
|
|
118
|
+
* is not held, because `equals()` sends the value nowhere.
|
|
119
|
+
*
|
|
120
|
+
* The case this exists for is a credential whose destination is trusted
|
|
121
|
+
* only after an asynchronous check has settled, an SSH host key against a
|
|
122
|
+
* known-hosts store, a certificate against a pin: the value is constructed
|
|
123
|
+
* with the check in flight and cannot be sent until the check says so.
|
|
124
|
+
*
|
|
125
|
+
* A promise is not data. It does not cross the wire or a worker handoff,
|
|
126
|
+
* and does not need to: an unreleased value refuses to serialize, and a
|
|
127
|
+
* released one has nothing left to carry.
|
|
128
|
+
*/
|
|
129
|
+
releasedBy?: PromiseLike<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* Hold the value as AES-256-GCM ciphertext in a `Buffer` rather than as a
|
|
132
|
+
* JavaScript string.
|
|
133
|
+
*
|
|
134
|
+
* This is not encryption at rest. The key is in this process, so it defends
|
|
135
|
+
* against a heap snapshot taken while no reveal is in flight and against an
|
|
136
|
+
* accidental disclosure of the stored bytes. It does not defend against a
|
|
137
|
+
* core dump, and it does not defend against code running in this process.
|
|
138
|
+
*
|
|
139
|
+
* Two costs, and the second is the one that decides whether a value should be
|
|
140
|
+
* sealed at all:
|
|
141
|
+
*
|
|
142
|
+
* - Every operation that runs a cipher gets slower, and the ones that do not
|
|
143
|
+
* are unchanged. Reading, constructing and deriving are one to two orders
|
|
144
|
+
* of magnitude slower than the same operation on an unsealed value, and
|
|
145
|
+
* deriving is the worst of the three because it decrypts and then seals the
|
|
146
|
+
* result. Comparing is much the mildest, a small single-digit multiple,
|
|
147
|
+
* because the constant-time path already hashes both operands. Redaction,
|
|
148
|
+
* `length` and `isEmpty()` show no measurable difference at all: they
|
|
149
|
+
* answer from what was captured at construction and never decrypt. No
|
|
150
|
+
* sharper figure is given here on purpose. Repeated runs of
|
|
151
|
+
* `__benchmarks__/sealing.bench.ts` on an idle machine moved these ratios
|
|
152
|
+
* by a factor of three, so run `pnpm bench` on your own hardware and read
|
|
153
|
+
* the gap between a group's members rather than any single number. Each
|
|
154
|
+
* value also costs a couple of hundred extra bytes, most of it the box,
|
|
155
|
+
* which lives outside the V8 heap.
|
|
156
|
+
* - **Every string-returning reveal leaves one copy of the plaintext in
|
|
157
|
+
* process memory that garbage collection does not remove.** Measured across
|
|
158
|
+
* two processes: a thousand `reveal()` calls leave about 940 copies, where
|
|
159
|
+
* a thousand on an unsealed value leave two, because that returns the same
|
|
160
|
+
* string object each time. `revealBytes()` and `equals()` leave none, so a
|
|
161
|
+
* value read repeatedly should use those.
|
|
162
|
+
*
|
|
163
|
+
* Worth sealing: a credential loaded once at startup and held for the life of
|
|
164
|
+
* the process. Not worth sealing: a value wrapped per request, whose
|
|
165
|
+
* plaintext the caller's own parsed body still holds anyway.
|
|
166
|
+
*
|
|
167
|
+
* Two behaviours differ from an unsealed value, both deliberate. A sealed
|
|
168
|
+
* value's redacted rendering is captured at construction, so a policy
|
|
169
|
+
* registered afterwards does not change it. And rewriting `klass` or `label`
|
|
170
|
+
* at runtime makes the value unreadable rather than reclassified, because
|
|
171
|
+
* both are bound into the GCM additional data.
|
|
172
|
+
*
|
|
173
|
+
* Defaults to the process setting from `setSealing()`, which is off.
|
|
174
|
+
*/
|
|
175
|
+
sealed?: boolean;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Where the process believes it is running.
|
|
179
|
+
*
|
|
180
|
+
* Declared once at startup through {@link setEnvironmentInfo}. Every field is
|
|
181
|
+
* copied when it is declared, so mutating the object afterwards does not move
|
|
182
|
+
* the environment.
|
|
183
|
+
*/
|
|
184
|
+
export interface EnvironmentInfo {
|
|
185
|
+
/**
|
|
186
|
+
* Deployment environment: `development`, `staging`, `production`, `test`, or
|
|
187
|
+
* whatever this deployment calls them. Compared literally, so the spelling
|
|
188
|
+
* has to match what a restriction lists.
|
|
189
|
+
*/
|
|
190
|
+
environment: string;
|
|
191
|
+
/** Cloud region, such as `eu-west-1`. The only field a pattern may match. */
|
|
192
|
+
region?: string | undefined;
|
|
193
|
+
/** Datacenter identifier. Compared literally. */
|
|
194
|
+
datacenter?: string | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Anything else this deployment wants a custom restriction to be able to read.
|
|
197
|
+
* Copied and frozen when the environment is declared.
|
|
198
|
+
*/
|
|
199
|
+
customTags?: Record<string, string> | undefined;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Where a value may be read.
|
|
203
|
+
*
|
|
204
|
+
* Every field that is present has to pass. An allowlist and a denylist over the
|
|
205
|
+
* same field are both applied, so a name on both lists is denied.
|
|
206
|
+
*
|
|
207
|
+
* A field the environment does not state is read differently by the two kinds
|
|
208
|
+
* of list: an allowlist refuses, because "only here" is not satisfied by a
|
|
209
|
+
* deployment that cannot say where it is, and a denylist passes, because "not
|
|
210
|
+
* there" concludes nothing from silence.
|
|
211
|
+
*/
|
|
212
|
+
export interface EnvironmentRestrictions {
|
|
213
|
+
/** Environments this value may be read in. Matched literally. */
|
|
214
|
+
allowedEnvironments?: readonly string[] | undefined;
|
|
215
|
+
/** Environments this value may not be read in. Matched literally. */
|
|
216
|
+
deniedEnvironments?: readonly string[] | undefined;
|
|
217
|
+
/**
|
|
218
|
+
* Regions this value may be read in.
|
|
219
|
+
*
|
|
220
|
+
* An entry is a literal region name or a prefix ending in `*`, such as
|
|
221
|
+
* `eu-*`. A `*` anywhere else is refused at construction rather than matched
|
|
222
|
+
* as a literal, which would leave the list matching nothing.
|
|
223
|
+
*/
|
|
224
|
+
allowedRegions?: readonly string[] | undefined;
|
|
225
|
+
/** Regions this value may not be read in. Same pattern rule as the allowlist. */
|
|
226
|
+
deniedRegions?: readonly string[] | undefined;
|
|
227
|
+
/** Datacenters this value may be read in. Matched literally. */
|
|
228
|
+
allowedDatacenters?: readonly string[] | undefined;
|
|
229
|
+
/** Datacenters this value may not be read in. Matched literally. */
|
|
230
|
+
deniedDatacenters?: readonly string[] | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* A predicate of the caller's own, asked last and handed the frozen
|
|
233
|
+
* environment.
|
|
234
|
+
*
|
|
235
|
+
* It must return `true` to allow the read. Anything else, including a
|
|
236
|
+
* Promise from an `async` function, is a refusal, and so is a throw.
|
|
237
|
+
*
|
|
238
|
+
* A function is not data: a value carrying one cannot be serialized or
|
|
239
|
+
* handed to a worker, because the far side would enforce the declarative
|
|
240
|
+
* half and silently not this.
|
|
241
|
+
*/
|
|
242
|
+
custom?: ((env: Readonly<EnvironmentInfo>) => boolean) | undefined;
|
|
243
|
+
/** What to say when `custom` refuses. Requires `custom`. */
|
|
244
|
+
customMessage?: string | undefined;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The wire form of {@link EnvironmentRestrictions}.
|
|
248
|
+
*
|
|
249
|
+
* The declarative fields and nothing else. `custom` has no wire form, and a
|
|
250
|
+
* value that carries one refuses to serialize rather than crossing without it.
|
|
251
|
+
*/
|
|
252
|
+
export interface SerializedEnvironmentRestrictions {
|
|
253
|
+
allowedEnvironments?: string[];
|
|
254
|
+
deniedEnvironments?: string[];
|
|
255
|
+
allowedRegions?: string[];
|
|
256
|
+
deniedRegions?: string[];
|
|
257
|
+
allowedDatacenters?: string[];
|
|
258
|
+
deniedDatacenters?: string[];
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Where a value may go.
|
|
262
|
+
*
|
|
263
|
+
* Each list that is present is an allowlist over one tag of the reveal context,
|
|
264
|
+
* and a context that does not state that tag is refused. There is no denylist:
|
|
265
|
+
* "may go to these and nowhere else" is the statement a recipient binding
|
|
266
|
+
* makes, and a list of places a credential must not go is the artefact that
|
|
267
|
+
* is always one entry short.
|
|
268
|
+
*/
|
|
269
|
+
export interface DestinationBinding {
|
|
270
|
+
/**
|
|
271
|
+
* Sinks this value may be revealed toward, matched literally against the
|
|
272
|
+
* context's `tags.sink`: `'http'` for the HTTP clients, the driver name for
|
|
273
|
+
* the data layer, the sink name given to `sendToExternal`.
|
|
274
|
+
*/
|
|
275
|
+
sinks?: readonly string[] | undefined;
|
|
276
|
+
/**
|
|
277
|
+
* Hosts this value may be revealed toward, matched against the context's
|
|
278
|
+
* `tags.host`, which the HTTP clients set to `new URL(url).host`: the
|
|
279
|
+
* lowercase hostname, with the port when it is not the scheme's default.
|
|
280
|
+
*
|
|
281
|
+
* An entry is that literal form or `*.` followed by a domain, which matches
|
|
282
|
+
* every host at least one label below it and not the domain itself. A URL,
|
|
283
|
+
* a path or a userinfo is refused at construction rather than sitting in the
|
|
284
|
+
* list matching nothing.
|
|
285
|
+
*/
|
|
286
|
+
hosts?: readonly string[] | undefined;
|
|
287
|
+
/**
|
|
288
|
+
* Principals this value may be revealed for, matched literally against the
|
|
289
|
+
* context's `tags.principal`: whatever identity the application tags its
|
|
290
|
+
* reveals with, a user id, a service account, a tenant. A value fetched for
|
|
291
|
+
* one caller and handed out of a shared cache to another refuses, which is
|
|
292
|
+
* a disclosure a redaction model cannot see because nothing is written.
|
|
293
|
+
*/
|
|
294
|
+
principals?: readonly string[] | undefined;
|
|
295
|
+
}
|
|
296
|
+
/** The wire form of a {@link DestinationBinding}: the same three lists. */
|
|
297
|
+
export interface SerializedDestinationBinding {
|
|
298
|
+
sinks?: string[];
|
|
299
|
+
hosts?: string[];
|
|
300
|
+
principals?: string[];
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Where a revocation came from.
|
|
304
|
+
*
|
|
305
|
+
* - `instance`: somebody called `revoke()` on the value or on something derived
|
|
306
|
+
* from it.
|
|
307
|
+
* - `label`, `pattern`: the process-global lists.
|
|
308
|
+
* - `registry`: the `revocationRegistry` the value was constructed with.
|
|
309
|
+
* - `wire`: the value arrived from `deserialize()` already marked revoked.
|
|
310
|
+
* - `unavailable`: the registry could not be reached, or did not answer the
|
|
311
|
+
* contract, so the read is refused because nothing could confirm it.
|
|
312
|
+
*/
|
|
313
|
+
export type RevocationScope = 'instance' | 'label' | 'pattern' | 'registry' | 'wire' | 'unavailable';
|
|
314
|
+
/**
|
|
315
|
+
* A revocation list a value consults, which may be backed by an external store.
|
|
316
|
+
*
|
|
317
|
+
* `isRevoked` must answer synchronously and must return a boolean. A read
|
|
318
|
+
* happens in one call, so an implementation that returns a Promise has already
|
|
319
|
+
* handed the value back by the time it resolves; the library refuses a
|
|
320
|
+
* non-boolean answer rather than guessing which way to read it. An
|
|
321
|
+
* implementation backed by a store therefore keeps a local cache and refreshes
|
|
322
|
+
* it out of band, which is what `sync()` is for.
|
|
323
|
+
*
|
|
324
|
+
* Anything thrown from `isRevoked` denies the read. A store that cannot be
|
|
325
|
+
* reached cannot confirm a value is usable.
|
|
326
|
+
*/
|
|
327
|
+
export interface RevocationRegistry {
|
|
328
|
+
/** Whether this label is revoked. Must be synchronous and must return a boolean. */
|
|
329
|
+
isRevoked(label: string | undefined): boolean;
|
|
330
|
+
/** Why, for a revoked label. Anything it throws is swallowed. */
|
|
331
|
+
getReason?(label: string): string | undefined;
|
|
332
|
+
/** Record a revocation, for a registry that is writable from this process. */
|
|
333
|
+
revoke?(label: string, reason: string): void;
|
|
334
|
+
/** Refresh from the backing store. Never called by the library. */
|
|
335
|
+
sync?(): Promise<void>;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Options for `SensitiveString.renew()`.
|
|
339
|
+
*/
|
|
340
|
+
export interface RenewalOptions {
|
|
341
|
+
/** Latest deadline this renewal may produce. The result is clamped to it. */
|
|
342
|
+
maxExtension?: Date;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Built-in masking strategies for well-known value formats, plus `custom` for a
|
|
346
|
+
* caller-supplied one.
|
|
347
|
+
*/
|
|
348
|
+
export type MaskStrategy = 'email' | 'phone' | 'card' | 'ssn' | 'uuid' | 'url' | 'custom';
|
|
349
|
+
/**
|
|
350
|
+
* Options for `SensitiveString.mask()`.
|
|
351
|
+
*
|
|
352
|
+
* Positional options (`showFirst`, `showLast`) and `strategy` are mutually
|
|
353
|
+
* exclusive: a strategy decides what it shows, so combining the two would
|
|
354
|
+
* silently ignore a caller's attempt to narrow the result.
|
|
355
|
+
*/
|
|
356
|
+
export interface MaskOptions {
|
|
357
|
+
/** Leading characters to leave visible. Positional masking only. */
|
|
358
|
+
showFirst?: number;
|
|
359
|
+
/** Trailing characters to leave visible. Positional masking only. */
|
|
360
|
+
showLast?: number;
|
|
361
|
+
/** Replacement character for hidden characters. Exactly one code point. Defaults to `'*'`. */
|
|
362
|
+
maskChar?: string;
|
|
363
|
+
/**
|
|
364
|
+
* Minimum characters the result must hide.
|
|
365
|
+
*
|
|
366
|
+
* Defaults to 4 for `sensitive` and 8 for `credential`. A caller may raise
|
|
367
|
+
* the floor but not lower it, and a rendering that cannot reach it falls back
|
|
368
|
+
* to full redaction.
|
|
369
|
+
*/
|
|
370
|
+
minMasked?: number;
|
|
371
|
+
/** Format-aware strategy to apply instead of positional masking. */
|
|
372
|
+
strategy?: MaskStrategy;
|
|
373
|
+
/**
|
|
374
|
+
* Formatter for `strategy: 'custom'`.
|
|
375
|
+
*
|
|
376
|
+
* ⚠️ Receives the RAW value. This is a reveal in all but name: the floor
|
|
377
|
+
* cannot be measured against output the library did not produce.
|
|
378
|
+
*/
|
|
379
|
+
customStrategy?: (value: string) => string;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Digest algorithms `hash()` and `hmac()` accept.
|
|
383
|
+
*
|
|
384
|
+
* An allowlist, rather than whatever the Node build happens to support. MD5
|
|
385
|
+
* and SHA-1 are absent because both are broken: a digest under either is a
|
|
386
|
+
* recoverable copy of the value rather than a one-way derivative of it.
|
|
387
|
+
*/
|
|
388
|
+
export type HashAlgorithm = 'sha256' | 'sha384' | 'sha512' | 'sha3-256' | 'sha3-512';
|
|
389
|
+
/** How a digest is rendered. */
|
|
390
|
+
export type HashEncoding = 'hex' | 'base64' | 'base64url';
|
|
391
|
+
/**
|
|
392
|
+
* Options for `SensitiveString.hash()`.
|
|
393
|
+
*/
|
|
394
|
+
export interface HashOptions {
|
|
395
|
+
/**
|
|
396
|
+
* Salt mixed in ahead of the value, so the same value under two salts gives
|
|
397
|
+
* two digests and a precomputed table built for one does not answer for the
|
|
398
|
+
* other.
|
|
399
|
+
*
|
|
400
|
+
* A string is read as UTF-8. It is prepended with no separator, which is what
|
|
401
|
+
* makes the digest reproducible by anything else computing
|
|
402
|
+
* `sha256(salt || value)`; the cost is that a variable-length salt is
|
|
403
|
+
* ambiguous, since `('ab', 'c')` and `('a', 'bc')` hash alike. Use a
|
|
404
|
+
* fixed-length salt, which is what a per-user salt from `randomBytes` is.
|
|
405
|
+
*
|
|
406
|
+
* A salt is not a key. It stops precomputation, and it does nothing at all
|
|
407
|
+
* against an attacker who has the salt and guesses the value, which is every
|
|
408
|
+
* attacker holding a digest and the record it came from. For a value an
|
|
409
|
+
* attacker can enumerate, use `hmac()`.
|
|
410
|
+
*/
|
|
411
|
+
salt?: string | Uint8Array;
|
|
412
|
+
/** Digest rendering. Defaults to `'hex'`. */
|
|
413
|
+
encoding?: HashEncoding;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Options for `SensitiveString.hmac()`.
|
|
417
|
+
*/
|
|
418
|
+
export interface HmacOptions {
|
|
419
|
+
/** Digest rendering. Defaults to `'hex'`. */
|
|
420
|
+
encoding?: HashEncoding;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Audit record for a full reveal.
|
|
424
|
+
*/
|
|
425
|
+
export interface RevealAuditDetails {
|
|
426
|
+
readonly operation: 'reveal';
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Audit record for a partial reveal through `mask()`.
|
|
430
|
+
*
|
|
431
|
+
* `customStrategy` is deliberately absent: an audit sink should not receive a
|
|
432
|
+
* function whose source it might serialize into a log.
|
|
433
|
+
*/
|
|
434
|
+
export interface MaskAuditDetails {
|
|
435
|
+
readonly operation: 'mask';
|
|
436
|
+
/** The strategy applied, or `'positional'` for `showFirst` / `showLast` masking. */
|
|
437
|
+
readonly strategy: MaskStrategy | 'positional';
|
|
438
|
+
readonly showFirst: number;
|
|
439
|
+
readonly showLast: number;
|
|
440
|
+
readonly minMasked: number;
|
|
441
|
+
readonly maskChar: string;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Audit record for a digest taken through `hash()`.
|
|
445
|
+
*
|
|
446
|
+
* The salt is deliberately absent. It is not the value and it is not secret,
|
|
447
|
+
* but an audit sink is the one place a digest, the record it belongs to, and
|
|
448
|
+
* the salt that produced it would all sit together, and a salt is only useful
|
|
449
|
+
* to an attacker who has the other two.
|
|
450
|
+
*/
|
|
451
|
+
export interface HashAuditDetails {
|
|
452
|
+
readonly operation: 'hash';
|
|
453
|
+
readonly algorithm: HashAlgorithm;
|
|
454
|
+
readonly encoding: HashEncoding;
|
|
455
|
+
/** Whether a salt was mixed in. */
|
|
456
|
+
readonly salted: boolean;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Audit record for a digest taken through `hmac()`.
|
|
460
|
+
*
|
|
461
|
+
* A protected key produces a second record of its own, under this same
|
|
462
|
+
* operation, because using a value as an HMAC key reads it.
|
|
463
|
+
*/
|
|
464
|
+
export interface HmacAuditDetails {
|
|
465
|
+
readonly operation: 'hmac';
|
|
466
|
+
readonly algorithm: HashAlgorithm;
|
|
467
|
+
readonly encoding: HashEncoding;
|
|
468
|
+
/** Whether the key was itself a protected value. */
|
|
469
|
+
readonly protectedKey: boolean;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Audit record for a deadline extension through `renew()`.
|
|
473
|
+
*
|
|
474
|
+
* Deadlines are ISO 8601 strings rather than Dates, so a sink receives a record
|
|
475
|
+
* it can serialize directly and cannot use to move a deadline.
|
|
476
|
+
*/
|
|
477
|
+
export interface RenewAuditDetails {
|
|
478
|
+
readonly operation: 'renew';
|
|
479
|
+
/** The deadline before this renewal. */
|
|
480
|
+
readonly previousExpiresAt: string;
|
|
481
|
+
/** The deadline this renewal set. */
|
|
482
|
+
readonly expiresAt: string;
|
|
483
|
+
/** How many renewals this value has had, including this one. */
|
|
484
|
+
readonly renewalCount: number;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Audit record for a revocation through `revoke()`.
|
|
488
|
+
*
|
|
489
|
+
* Reported after the revocation has taken effect, not before it: nothing may
|
|
490
|
+
* refuse a revocation, so a sink that throws is swallowed rather than allowed
|
|
491
|
+
* to keep a value alive. That is the opposite of `renew()`, which is audited
|
|
492
|
+
* first precisely so a sink can stop it.
|
|
493
|
+
*/
|
|
494
|
+
export interface RevokeAuditDetails {
|
|
495
|
+
readonly operation: 'revoke';
|
|
496
|
+
/** The caller-supplied reason. Developer text; it must not carry the value. */
|
|
497
|
+
readonly reason: string;
|
|
498
|
+
readonly revokedAt: string;
|
|
499
|
+
readonly scope: RevocationScope;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Audit record for a value leaving for another thread or process through
|
|
503
|
+
* `toWorkerPayload()`.
|
|
504
|
+
*
|
|
505
|
+
* A handoff is authorized as an ordinary `expose`, since the raw value does
|
|
506
|
+
* reach the caller, and is distinguished here rather than by a new access
|
|
507
|
+
* kind: a policy that refuses `expose` today must keep refusing a handoff, and
|
|
508
|
+
* a separate kind would route around every such policy. The caller's context
|
|
509
|
+
* name is left alone, because that is the field an audit reader searches on;
|
|
510
|
+
* where the value went is a field of this record instead.
|
|
511
|
+
*/
|
|
512
|
+
export interface WorkerHandoffAuditDetails {
|
|
513
|
+
readonly operation: 'worker-handoff';
|
|
514
|
+
/** The destination named to `toWorkerPayload()`. Recorded, never verified. */
|
|
515
|
+
readonly worker: string | undefined;
|
|
516
|
+
/** The key this value has in the payload. */
|
|
517
|
+
readonly key: string;
|
|
518
|
+
/**
|
|
519
|
+
* Whether the authorizing context carried an `auditReveal` that cannot cross
|
|
520
|
+
* the boundary. The receiving side is required to install its own.
|
|
521
|
+
*
|
|
522
|
+
* Always `true` in a record a sink actually receives, and deliberately still
|
|
523
|
+
* a field rather than an assumption: a record is only delivered *through*
|
|
524
|
+
* the hook this reports the loss of, so the sink reading it is the one being
|
|
525
|
+
* dropped. Do not filter an audit log on `false` expecting to find handoffs
|
|
526
|
+
* that kept their hook; there are none, because a context without a hook
|
|
527
|
+
* records nothing at all.
|
|
528
|
+
*/
|
|
529
|
+
readonly auditHookDropped: boolean;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Audit record for a value destroyed through `clear()`.
|
|
533
|
+
*
|
|
534
|
+
* Reported after the value has been dropped, not before it, and with anything
|
|
535
|
+
* the sink throws swallowed: nothing may refuse a clear, so a broken sink must
|
|
536
|
+
* not make it look as though the destruction did not happen. That is the same
|
|
537
|
+
* rule `revoke()` follows and the opposite of `renew()`, which audits first
|
|
538
|
+
* precisely so a sink can stop it.
|
|
539
|
+
*/
|
|
540
|
+
export interface ClearAuditDetails {
|
|
541
|
+
readonly operation: 'clear';
|
|
542
|
+
/**
|
|
543
|
+
* Whether the clear also refused every value derived from this one.
|
|
544
|
+
*
|
|
545
|
+
* True from an owner, which writes the shared state its derivatives read;
|
|
546
|
+
* false from a derivative, which has no shared state of its own to write and
|
|
547
|
+
* so destroys only its own copy.
|
|
548
|
+
*/
|
|
549
|
+
readonly propagated: boolean;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* What the audited operation was, so an audit sink can tell a full reveal from
|
|
553
|
+
* a partial one, and either from a lifetime extension, a revocation, a
|
|
554
|
+
* destruction, or a handoff to another thread.
|
|
555
|
+
*/
|
|
556
|
+
export type RevealDetails = RevealAuditDetails | MaskAuditDetails | HashAuditDetails | HmacAuditDetails | RenewAuditDetails | RevokeAuditDetails | ClearAuditDetails | WorkerHandoffAuditDetails;
|
|
557
|
+
/**
|
|
558
|
+
* What a policy is being asked to authorize.
|
|
559
|
+
*
|
|
560
|
+
* - `compare`: `equals()`, which reads the value but never hands it to the
|
|
561
|
+
* caller and produces no audit record.
|
|
562
|
+
* - `expose`: the value is read for the caller's benefit, whether in full
|
|
563
|
+
* through `reveal()` and `serialize()`, in part through `mask()` and the
|
|
564
|
+
* string and regex operations, or as a durable one-way derivative through
|
|
565
|
+
* `hash()` and `hmac()`. The last of those hands the caller nothing raw and
|
|
566
|
+
* is still an exposure: a digest of a value an attacker can enumerate is
|
|
567
|
+
* that value behind a lookup table.
|
|
568
|
+
* - `renew`: not a read at all. The value's deadline is being extended.
|
|
569
|
+
*
|
|
570
|
+
* A read that only feeds redaction or documented metadata (`toString()`,
|
|
571
|
+
* `length`) never reaches a policy and so has no kind here.
|
|
572
|
+
*/
|
|
573
|
+
export type RevealAccess = 'compare' | 'expose' | 'renew';
|
|
574
|
+
/**
|
|
575
|
+
* Advisory metadata for sensitivity policies.
|
|
576
|
+
*
|
|
577
|
+
* Mostly not enforced: use it for documentation and for an external policy
|
|
578
|
+
* engine. Two fields are read by code in this monorepo and each says so on
|
|
579
|
+
* itself, with opposite defaults, because they answer opposite questions.
|
|
580
|
+
*/
|
|
581
|
+
export interface SensitivityAdvisory {
|
|
582
|
+
/**
|
|
583
|
+
* Whether a one-way digest of this class may be taken.
|
|
584
|
+
*
|
|
585
|
+
* Enforced by `hash()` and `hmac()`. `undefined` allows, unlike
|
|
586
|
+
* `allowSendToExternal` below: hashing is the operation this library wants
|
|
587
|
+
* used in place of holding a value, so the flag exists to forbid it for a
|
|
588
|
+
* class where even a digest is too much, not to require permission for the
|
|
589
|
+
* safe path.
|
|
590
|
+
*/
|
|
591
|
+
allowHash?: boolean;
|
|
592
|
+
/** Whether plaintext persistence is allowed */
|
|
593
|
+
allowPersistPlain?: boolean;
|
|
594
|
+
/** Whether encrypted persistence is allowed */
|
|
595
|
+
allowPersistEncrypted?: boolean;
|
|
596
|
+
/** Whether sending to logs (redacted form only) is allowed */
|
|
597
|
+
allowSendToLog?: boolean;
|
|
598
|
+
/** Generic external sink flag */
|
|
599
|
+
allowSendToExternal?: boolean;
|
|
600
|
+
/** Risk level indicator */
|
|
601
|
+
criticality?: 'low' | 'medium' | 'high';
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Forward declaration for SensitiveString to avoid circular deps.
|
|
605
|
+
* The actual class is defined in sensitive-string.ts
|
|
606
|
+
*/
|
|
607
|
+
export interface ISensitiveString {
|
|
608
|
+
readonly klass: SensitivityClass;
|
|
609
|
+
/** Optional label for audit/compliance categorization (e.g., 'api_key', 'email', 'ssn') */
|
|
610
|
+
readonly label: string | undefined;
|
|
611
|
+
toString(): string;
|
|
612
|
+
reveal(ctx?: RevealContext): string;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* The context an audited operation ran under, as its audit sink sees it.
|
|
616
|
+
*
|
|
617
|
+
* The three descriptive fields, and no `auditReveal`: the sink reading this is
|
|
618
|
+
* that hook, so the only use it has for its own hook is to call it, and the
|
|
619
|
+
* gate the hook runs inside is not reentrant. It is the same trio that crosses
|
|
620
|
+
* a thread boundary as a `PortableRevealContext`, for a different reason:
|
|
621
|
+
* there because a function does not clone, here because a function is not
|
|
622
|
+
* evidence.
|
|
623
|
+
*
|
|
624
|
+
* The narrowing is in the type and not in a copy. What arrives is the live
|
|
625
|
+
* `RevealContext`, which is deliberate on both counts: a sink may compare it by
|
|
626
|
+
* identity with the context it installed, and an audited reveal allocates
|
|
627
|
+
* nothing to be recorded. A caller who casts can still reach the hook on it,
|
|
628
|
+
* which is a contract being defeated rather than anything disclosed, since the
|
|
629
|
+
* object is the one that caller built.
|
|
630
|
+
*
|
|
631
|
+
* Live also means read-only by convention. `tags` is the caller's own object,
|
|
632
|
+
* shared by every reveal made under the context, so writing to it from a sink
|
|
633
|
+
* changes what later reveals report. Copy out what a record needs to keep.
|
|
634
|
+
*/
|
|
635
|
+
export interface AuditContext {
|
|
636
|
+
/** Descriptive name of the unit of work the operation ran under. */
|
|
637
|
+
readonly name: string;
|
|
638
|
+
/** Human-readable justification, when the context carried one. */
|
|
639
|
+
readonly reason?: string;
|
|
640
|
+
/** Freeform metadata: request ID, user ID, and whatever an integration tagged. */
|
|
641
|
+
readonly tags?: Readonly<Record<string, unknown>>;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Context for tracking and auditing reveal operations.
|
|
645
|
+
* Can be passed explicitly or set via AsyncLocalStorage.
|
|
646
|
+
*/
|
|
647
|
+
export interface RevealContext {
|
|
648
|
+
/** Descriptive name for the context (e.g., "http-request", "migration-job") */
|
|
649
|
+
name: string;
|
|
650
|
+
/** Human-readable justification for the reveal */
|
|
651
|
+
reason?: string;
|
|
652
|
+
/** Freeform metadata (request ID, user ID, etc.) */
|
|
653
|
+
tags?: Record<string, unknown>;
|
|
654
|
+
/**
|
|
655
|
+
* Callback invoked when a sensitive value is revealed.
|
|
656
|
+
*
|
|
657
|
+
* `details` distinguishes a full reveal from a partial one and carries the
|
|
658
|
+
* mask options that produced it.
|
|
659
|
+
*
|
|
660
|
+
* `context` is the context the operation actually ran under: the one passed
|
|
661
|
+
* to the call, or the ambient one when the call passed none, which is the
|
|
662
|
+
* same context the policy's `checkRevealAllowed` was asked to authorize
|
|
663
|
+
* against. It is not always the context this hook was installed on. A hook
|
|
664
|
+
* inherited through `createChildContext()` is called with the child, so an
|
|
665
|
+
* integration that tags a reveal with the table, the column or the argument
|
|
666
|
+
* path reaches a sink here rather than through `getCurrentRevealContext()`,
|
|
667
|
+
* which reports where the caller stood and not what the reveal was for.
|
|
668
|
+
*
|
|
669
|
+
* The return value is ignored. A sink that must stop the reveal throws
|
|
670
|
+
* synchronously; a Promise it returns is not awaited, so a rejection after an
|
|
671
|
+
* `await` cannot stop anything and surfaces as an unhandled rejection.
|
|
672
|
+
*
|
|
673
|
+
* ⚠️ The hook runs inside the raw-value gate, which is not reentrant. Reading
|
|
674
|
+
* `value` from here, through `reveal()`, `mask()` or any operation that
|
|
675
|
+
* derives from it, re-enters the gate and recurses until the stack is
|
|
676
|
+
* exhausted; against a reveal budget it also charges the inner read before
|
|
677
|
+
* the outer one has been charged. Read `klass` and `label`, and nothing else.
|
|
678
|
+
*/
|
|
679
|
+
auditReveal?(value: ISensitiveString, details: RevealDetails, context: AuditContext): void;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Policy definition for a sensitivity class.
|
|
683
|
+
* Controls redaction, security behavior, and reveal authorization.
|
|
684
|
+
*/
|
|
685
|
+
export interface SensitivityPolicy {
|
|
686
|
+
/** The sensitivity class this policy applies to */
|
|
687
|
+
name: SensitivityClass;
|
|
688
|
+
/**
|
|
689
|
+
* Transform a raw value into its redacted form.
|
|
690
|
+
* Called by toString(), toJSON(), and inspect.
|
|
691
|
+
*/
|
|
692
|
+
redact(value: string): string;
|
|
693
|
+
/**
|
|
694
|
+
* How to recognize this policy's redacted output, for a policy whose
|
|
695
|
+
* `redact` depends on the value.
|
|
696
|
+
*
|
|
697
|
+
* The guards that refuse to send a redaction onward, chiefly
|
|
698
|
+
* `assertNoMarker` in `@platform-sec/sensitive-string-http`, learn a
|
|
699
|
+
* policy's marker by redacting two probes of different lengths and keeping
|
|
700
|
+
* the answer when both agree. A constant redaction gives itself away that
|
|
701
|
+
* way; a value-dependent one cannot, so it declares its shape here instead.
|
|
702
|
+
* Without it such a policy is recognized only by the default `[REDACTED:`
|
|
703
|
+
* prefix, and a policy that does not use that prefix is not recognized at
|
|
704
|
+
* all, which means a redaction leaves in a request body rather than being
|
|
705
|
+
* refused.
|
|
706
|
+
*
|
|
707
|
+
* `deterministicRedaction()` sets it. A hand-written value-dependent policy
|
|
708
|
+
* should set it too. Leave it unset for a constant redaction, which needs no
|
|
709
|
+
* help.
|
|
710
|
+
*
|
|
711
|
+
* ⚠️ Must not carry the `g` flag. A global `RegExp` keeps `lastIndex`
|
|
712
|
+
* between calls, so a shared one answers differently on every second scan.
|
|
713
|
+
*/
|
|
714
|
+
readonly markerPattern?: RegExp;
|
|
715
|
+
/** Use constant-time comparison for equals() operations */
|
|
716
|
+
requireConstantTimeEquals?: boolean;
|
|
717
|
+
/**
|
|
718
|
+
* Allow queries that disclose partial information about the raw value.
|
|
719
|
+
* Defaults to true for sensitive values and false for credentials.
|
|
720
|
+
*/
|
|
721
|
+
allowPartialQueries?: boolean;
|
|
722
|
+
/**
|
|
723
|
+
* Allow partially masked output from `mask()`.
|
|
724
|
+
* Defaults to true for sensitive values and false for credentials.
|
|
725
|
+
*/
|
|
726
|
+
allowMask?: boolean;
|
|
727
|
+
/**
|
|
728
|
+
* Whether values of this class may be renewed.
|
|
729
|
+
*
|
|
730
|
+
* `false` is a prohibition that the `allowRenewal` construction option cannot
|
|
731
|
+
* lift. `true` makes the class renewable by default. Unset leaves the class
|
|
732
|
+
* default: credentials are not renewable, everything else is.
|
|
733
|
+
*/
|
|
734
|
+
allowRenewal?: boolean;
|
|
735
|
+
/**
|
|
736
|
+
* Lifetime in milliseconds applied to values of this class that are
|
|
737
|
+
* constructed without `ttl` or `expiresAt`.
|
|
738
|
+
*/
|
|
739
|
+
defaultTtl?: number;
|
|
740
|
+
/**
|
|
741
|
+
* Longest lifetime, in milliseconds from construction, any value of this
|
|
742
|
+
* class may have.
|
|
743
|
+
*
|
|
744
|
+
* It caps the deadline at construction, caps every renewal, and gives a
|
|
745
|
+
* deadline to a value that would otherwise have none, so no value of the
|
|
746
|
+
* class outlives it.
|
|
747
|
+
*/
|
|
748
|
+
maxTtl?: number;
|
|
749
|
+
/**
|
|
750
|
+
* Reject construction of a value of this class that has no deadline.
|
|
751
|
+
*
|
|
752
|
+
* `defaultTtl` or `maxTtl` satisfy the requirement, so it only rejects a
|
|
753
|
+
* class that sets neither and a caller who passes neither.
|
|
754
|
+
*/
|
|
755
|
+
requireExpiration?: boolean;
|
|
756
|
+
/**
|
|
757
|
+
* Hook to validate whether reveal is allowed in the given context.
|
|
758
|
+
* Throw an error to deny the reveal, and return nothing to allow it.
|
|
759
|
+
*
|
|
760
|
+
* ⚠️ The hook must be synchronous. The gate reads the value in the same call,
|
|
761
|
+
* so an `async` hook cannot deny anything: it throws into a Promise after the
|
|
762
|
+
* raw value has already been returned, which is the hook failing open on
|
|
763
|
+
* exactly the reads it was written to refuse. The return type is `undefined`
|
|
764
|
+
* rather than `void` so that an `async` function is rejected at compile time,
|
|
765
|
+
* and the gate refuses at runtime any hook that returns a value at all, a
|
|
766
|
+
* Promise included, since a hook that returns `false` meant to deny.
|
|
767
|
+
*
|
|
768
|
+
* `value` is the instance being read, so a policy can decide on the label or
|
|
769
|
+
* the deadline rather than on the class alone, and `access` says what is
|
|
770
|
+
* being authorized. Both were added after the context-only form, so a hook
|
|
771
|
+
* that declares fewer parameters keeps working unchanged.
|
|
772
|
+
*
|
|
773
|
+
* ⚠️ The hook runs inside the raw-value gate, which is not reentrant. Reading
|
|
774
|
+
* `value` from here, through `reveal()`, `equals()` or `mask()`, re-enters the
|
|
775
|
+
* gate and recurses until the stack is exhausted. Read `klass` and `label`,
|
|
776
|
+
* and nothing else.
|
|
777
|
+
*
|
|
778
|
+
* The policy for a class is process-global, so this hook sees every value of
|
|
779
|
+
* that class. A rule that applies to one value belongs to the caller that
|
|
780
|
+
* constructed it, not here.
|
|
781
|
+
*/
|
|
782
|
+
checkRevealAllowed?(ctx: RevealContext | null, value: ISensitiveString, access: RevealAccess): undefined;
|
|
783
|
+
/**
|
|
784
|
+
* Determine the resulting class when combining two sensitive values.
|
|
785
|
+
* If not provided, defaultCombineClasses is used.
|
|
786
|
+
*/
|
|
787
|
+
combineClasses?(a: SensitivityClass, b: SensitivityClass): SensitivityClass;
|
|
788
|
+
/** Advisory metadata. Mostly not enforced; see `SensitivityAdvisory` for the two that are */
|
|
789
|
+
advisory?: SensitivityAdvisory;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Serialized format for secure service-to-service transmission.
|
|
793
|
+
*
|
|
794
|
+
* ⚠️ Contains RAW (UNREDACTED) value.
|
|
795
|
+
* Created via `serialize()`.
|
|
796
|
+
*/
|
|
797
|
+
export interface SerializedSensitiveString {
|
|
798
|
+
/** Marker to identify this as a serialized sensitive string */
|
|
799
|
+
__sensitive: true;
|
|
800
|
+
/** The sensitivity classification */
|
|
801
|
+
klass: SensitivityClass;
|
|
802
|
+
/** The raw (unredacted) value */
|
|
803
|
+
value: string;
|
|
804
|
+
/** Optional label for audit/compliance categorization */
|
|
805
|
+
label?: string;
|
|
806
|
+
/**
|
|
807
|
+
* ISO 8601 deadline, when the value expires.
|
|
808
|
+
*
|
|
809
|
+
* A token with five minutes left still has five minutes left after crossing a
|
|
810
|
+
* service boundary, so the deadline travels with the value and the receiver
|
|
811
|
+
* enforces it against its own clock. Renewal permission and renewal counts
|
|
812
|
+
* deliberately do not travel: a receiver must not take "you may extend this
|
|
813
|
+
* credential's lifetime" from a payload.
|
|
814
|
+
*/
|
|
815
|
+
expiresAt?: string;
|
|
816
|
+
/**
|
|
817
|
+
* Set when the sender is marking the value revoked.
|
|
818
|
+
*
|
|
819
|
+
* `serialize()` never emits it, because a revoked value cannot be read to be
|
|
820
|
+
* serialized at all: the gate refuses. It exists for the other direction, so
|
|
821
|
+
* a payload assembled by hand, or by a gateway that checked its own list, can
|
|
822
|
+
* tell the receiver not to use what it is sending. Like every other field
|
|
823
|
+
* here it may only tighten: there is no way to spell "not revoked" that
|
|
824
|
+
* lifts a revocation the receiving process already holds.
|
|
825
|
+
*
|
|
826
|
+
* Only `true` is accepted. `false` is rejected rather than read as "not
|
|
827
|
+
* revoked", so a payload that means to say nothing says nothing.
|
|
828
|
+
*/
|
|
829
|
+
revoked?: true;
|
|
830
|
+
/** Why, for a payload carrying `revoked`. Ignored without it. */
|
|
831
|
+
revocationReason?: string;
|
|
832
|
+
/**
|
|
833
|
+
* Where the receiver may read this value.
|
|
834
|
+
*
|
|
835
|
+
* Restrictions travel, because a value that may only be read in the EU is
|
|
836
|
+
* still a value that may only be read in the EU after it crosses a service
|
|
837
|
+
* boundary, and the receiving process is exactly the one that might be
|
|
838
|
+
* somewhere else. Like every other field here they may only tighten: a
|
|
839
|
+
* deserialized value starts with none, so a payload can add restrictions and
|
|
840
|
+
* has no way to spell the removal of one.
|
|
841
|
+
*
|
|
842
|
+
* A list, because a value derived from two restricted values carries both.
|
|
843
|
+
* An entry with a key this receiver does not know is rejected rather than
|
|
844
|
+
* ignored, since ignoring it would enforce part of a restriction and report
|
|
845
|
+
* nothing about the rest.
|
|
846
|
+
*/
|
|
847
|
+
restrictions?: SerializedEnvironmentRestrictions[];
|
|
848
|
+
/**
|
|
849
|
+
* Where the receiver may reveal this value toward.
|
|
850
|
+
*
|
|
851
|
+
* Bindings travel for the reason restrictions do: a credential that may only
|
|
852
|
+
* go to one host is still that credential after it crosses a service
|
|
853
|
+
* boundary, and the receiving process is the one about to make the request.
|
|
854
|
+
* They may only tighten, and an entry with an unknown key is rejected rather
|
|
855
|
+
* than ignored.
|
|
856
|
+
*/
|
|
857
|
+
destinations?: SerializedDestinationBinding[];
|
|
858
|
+
}
|
|
859
|
+
//# sourceMappingURL=types.d.ts.map
|