@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,110 @@
1
+ /**
2
+ * Keyed derivation of a stable token from a raw value.
3
+ *
4
+ * One implementation, in `core`, because two callers want the same primitive
5
+ * and a truncated keyed HMAC over a low-entropy value has exactly one correct
6
+ * shape. Deterministic redaction (ROADMAP 6.1) correlates a value across log
7
+ * lines; an LLM entity handle stands in for a value inside a prompt. Both
8
+ * derive a short stable token from something an attacker can guess, and both
9
+ * publish the result somewhere the attacker can see it.
10
+ *
11
+ * That is why there is no unkeyed mode. An email address under a plain
12
+ * SHA-256 is recoverable from a wordlist in seconds, and the entire premise of
13
+ * a derived token is that it appears where an offline attack can reach it.
14
+ *
15
+ * This module holds the derivation and nothing else. It does not read a
16
+ * `SensitiveString`, does not authorize, and does not audit: a caller reveals
17
+ * through the ordinary gate and hands the result here, so the audit record is
18
+ * produced by the reveal rather than by a second, quieter path to the same
19
+ * value.
20
+ */
21
+ /**
22
+ * Shortest token this function will produce, in hex characters.
23
+ *
24
+ * 12 hex characters is 48 bits. Under the birthday bound two distinct values
25
+ * collide with probability around one in a million at roughly 24,000 distinct
26
+ * values under one key and domain. 8 characters is 32 bits, where the same
27
+ * bound falls at about 90 values and a one-in-a-thousand collision arrives at
28
+ * about 3,000, which a support-ticket workload reaches in a week. A collision
29
+ * merges two subjects into one, so the floor is a correctness guard as much as
30
+ * a security one.
31
+ */
32
+ export declare const MIN_DERIVED_TOKEN_LENGTH = 12;
33
+ /** The full SHA-256 digest in hex. Longer would be truncation of nothing. */
34
+ export declare const MAX_DERIVED_TOKEN_LENGTH = 64;
35
+ /** The default, which is the floor. Raise it before a workload grows past the bound above. */
36
+ export declare const DEFAULT_DERIVED_TOKEN_LENGTH = 12;
37
+ /**
38
+ * Shortest accepted key, in bytes.
39
+ *
40
+ * A key of a few bytes is an unkeyed hash with extra steps: the search space
41
+ * is small enough to enumerate alongside the wordlist the value came from. 16
42
+ * bytes is the floor rather than a recommendation; 32 bytes of `randomBytes`
43
+ * is the recommendation.
44
+ */
45
+ export declare const MIN_DERIVATION_KEY_BYTES = 16;
46
+ /** How to derive a token. */
47
+ export interface KeyedDerivationOptions {
48
+ /**
49
+ * HMAC key. Required, and there is no way to configure the function without
50
+ * one.
51
+ *
52
+ * A string is read as UTF-8. Prefer a `Uint8Array` from a secrets manager or
53
+ * `randomBytes`, since a string key sits in the heap as an ordinary string.
54
+ */
55
+ readonly key: Uint8Array | string;
56
+ /**
57
+ * Domain components mixed in ahead of the value, so the same value in two
58
+ * contexts derives two different tokens.
59
+ *
60
+ * Joined with a NUL byte, which is why a component may not contain one: with
61
+ * an ordinary separator, `['a', 'b.c']` and `['a.b', 'c']` would hash
62
+ * identically and two domains would silently share a token space.
63
+ */
64
+ readonly domain?: readonly string[];
65
+ /** Hex characters retained. Default {@link DEFAULT_DERIVED_TOKEN_LENGTH}. */
66
+ readonly length?: number;
67
+ }
68
+ /**
69
+ * Derive a stable token from a raw value.
70
+ *
71
+ * `HMAC-SHA256(key, domain[0] || 0x00 || ... || domain[n] || 0x00 || value)`,
72
+ * hex, truncated to `length`. Deterministic across processes for the same key,
73
+ * domain and value, which is the property that makes a token usable as a
74
+ * correlation key or a pseudonym.
75
+ *
76
+ * @param value - The raw value. The caller is responsible for having been
77
+ * authorized to hold it; this function performs no check.
78
+ * @param options - The key, the domain separation, and the token length
79
+ * @returns The truncated hex digest, with no prefix or delimiters
80
+ *
81
+ * @throws TypeError If the key is not bytes or a string, or a domain component
82
+ * is not a string or contains a NUL byte.
83
+ * @throws RangeError If the key is shorter than {@link MIN_DERIVATION_KEY_BYTES},
84
+ * or `length` is not a whole number within the documented bounds.
85
+ */
86
+ export declare function deriveKeyedToken(value: string, options: KeyedDerivationOptions): string;
87
+ /**
88
+ * Check the derivation options without deriving anything.
89
+ *
90
+ * For a caller who has to read a protected value to derive from it. Every
91
+ * refusal `deriveKeyedToken` can raise for a malformed key, length or domain
92
+ * is raised here instead, so the caller can settle them before the read rather
93
+ * than after it.
94
+ *
95
+ * The read is the reason this exists. Core's rule in the raw-value gate is that
96
+ * a denied read is not a reveal and must not be logged as one; a read whose
97
+ * result is about to be thrown away for a caller's typo is the same thing one
98
+ * step later. Without this, an audit sink records a reveal that produced
99
+ * nothing, and an auditor reconciling reveals against derived tokens finds one
100
+ * that does not balance.
101
+ *
102
+ * @param options - The same options {@link deriveKeyedToken} takes
103
+ *
104
+ * @throws TypeError For a key or domain component of the wrong type, or a
105
+ * domain component containing a NUL byte.
106
+ * @throws RangeError For a key below the entropy floor or a length outside the
107
+ * documented bounds.
108
+ */
109
+ export declare function assertKeyedDerivationOptions(options: KeyedDerivationOptions): void;
110
+ //# sourceMappingURL=derive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,6EAA6E;AAC7E,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,8FAA8F;AAC9F,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,6BAA6B;AAC7B,MAAM,WAAW,sBAAsB;IACrC;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAAC;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAoBvF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAOlF"}
package/dist/derive.js ADDED
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIN_DERIVATION_KEY_BYTES = exports.DEFAULT_DERIVED_TOKEN_LENGTH = exports.MAX_DERIVED_TOKEN_LENGTH = exports.MIN_DERIVED_TOKEN_LENGTH = void 0;
4
+ exports.deriveKeyedToken = deriveKeyedToken;
5
+ exports.assertKeyedDerivationOptions = assertKeyedDerivationOptions;
6
+ const node_crypto_1 = require("node:crypto");
7
+ /**
8
+ * Keyed derivation of a stable token from a raw value.
9
+ *
10
+ * One implementation, in `core`, because two callers want the same primitive
11
+ * and a truncated keyed HMAC over a low-entropy value has exactly one correct
12
+ * shape. Deterministic redaction (ROADMAP 6.1) correlates a value across log
13
+ * lines; an LLM entity handle stands in for a value inside a prompt. Both
14
+ * derive a short stable token from something an attacker can guess, and both
15
+ * publish the result somewhere the attacker can see it.
16
+ *
17
+ * That is why there is no unkeyed mode. An email address under a plain
18
+ * SHA-256 is recoverable from a wordlist in seconds, and the entire premise of
19
+ * a derived token is that it appears where an offline attack can reach it.
20
+ *
21
+ * This module holds the derivation and nothing else. It does not read a
22
+ * `SensitiveString`, does not authorize, and does not audit: a caller reveals
23
+ * through the ordinary gate and hands the result here, so the audit record is
24
+ * produced by the reveal rather than by a second, quieter path to the same
25
+ * value.
26
+ */
27
+ /**
28
+ * Shortest token this function will produce, in hex characters.
29
+ *
30
+ * 12 hex characters is 48 bits. Under the birthday bound two distinct values
31
+ * collide with probability around one in a million at roughly 24,000 distinct
32
+ * values under one key and domain. 8 characters is 32 bits, where the same
33
+ * bound falls at about 90 values and a one-in-a-thousand collision arrives at
34
+ * about 3,000, which a support-ticket workload reaches in a week. A collision
35
+ * merges two subjects into one, so the floor is a correctness guard as much as
36
+ * a security one.
37
+ */
38
+ exports.MIN_DERIVED_TOKEN_LENGTH = 12;
39
+ /** The full SHA-256 digest in hex. Longer would be truncation of nothing. */
40
+ exports.MAX_DERIVED_TOKEN_LENGTH = 64;
41
+ /** The default, which is the floor. Raise it before a workload grows past the bound above. */
42
+ exports.DEFAULT_DERIVED_TOKEN_LENGTH = 12;
43
+ /**
44
+ * Shortest accepted key, in bytes.
45
+ *
46
+ * A key of a few bytes is an unkeyed hash with extra steps: the search space
47
+ * is small enough to enumerate alongside the wordlist the value came from. 16
48
+ * bytes is the floor rather than a recommendation; 32 bytes of `randomBytes`
49
+ * is the recommendation.
50
+ */
51
+ exports.MIN_DERIVATION_KEY_BYTES = 16;
52
+ /**
53
+ * Derive a stable token from a raw value.
54
+ *
55
+ * `HMAC-SHA256(key, domain[0] || 0x00 || ... || domain[n] || 0x00 || value)`,
56
+ * hex, truncated to `length`. Deterministic across processes for the same key,
57
+ * domain and value, which is the property that makes a token usable as a
58
+ * correlation key or a pseudonym.
59
+ *
60
+ * @param value - The raw value. The caller is responsible for having been
61
+ * authorized to hold it; this function performs no check.
62
+ * @param options - The key, the domain separation, and the token length
63
+ * @returns The truncated hex digest, with no prefix or delimiters
64
+ *
65
+ * @throws TypeError If the key is not bytes or a string, or a domain component
66
+ * is not a string or contains a NUL byte.
67
+ * @throws RangeError If the key is shorter than {@link MIN_DERIVATION_KEY_BYTES},
68
+ * or `length` is not a whole number within the documented bounds.
69
+ */
70
+ function deriveKeyedToken(value, options) {
71
+ if (typeof value !== 'string') {
72
+ throw new TypeError('deriveKeyedToken: value must be a string');
73
+ }
74
+ const key = normalizeKey(options.key);
75
+ const length = normalizeLength(options.length);
76
+ const hmac = (0, node_crypto_1.createHmac)('sha256', key);
77
+ for (const component of options.domain ?? []) {
78
+ assertDomainComponent(component);
79
+ hmac.update(component, 'utf8');
80
+ hmac.update(SEPARATOR);
81
+ }
82
+ hmac.update(value, 'utf8');
83
+ return hmac.digest('hex').slice(0, length);
84
+ }
85
+ /**
86
+ * Check the derivation options without deriving anything.
87
+ *
88
+ * For a caller who has to read a protected value to derive from it. Every
89
+ * refusal `deriveKeyedToken` can raise for a malformed key, length or domain
90
+ * is raised here instead, so the caller can settle them before the read rather
91
+ * than after it.
92
+ *
93
+ * The read is the reason this exists. Core's rule in the raw-value gate is that
94
+ * a denied read is not a reveal and must not be logged as one; a read whose
95
+ * result is about to be thrown away for a caller's typo is the same thing one
96
+ * step later. Without this, an audit sink records a reveal that produced
97
+ * nothing, and an auditor reconciling reveals against derived tokens finds one
98
+ * that does not balance.
99
+ *
100
+ * @param options - The same options {@link deriveKeyedToken} takes
101
+ *
102
+ * @throws TypeError For a key or domain component of the wrong type, or a
103
+ * domain component containing a NUL byte.
104
+ * @throws RangeError For a key below the entropy floor or a length outside the
105
+ * documented bounds.
106
+ */
107
+ function assertKeyedDerivationOptions(options) {
108
+ normalizeKey(options.key);
109
+ normalizeLength(options.length);
110
+ for (const component of options.domain ?? []) {
111
+ assertDomainComponent(component);
112
+ }
113
+ }
114
+ function assertDomainComponent(component) {
115
+ if (typeof component !== 'string') {
116
+ throw new TypeError('deriveKeyedToken: every domain component must be a string');
117
+ }
118
+ if (component.includes(NUL)) {
119
+ throw new TypeError('deriveKeyedToken: a domain component may not contain a NUL byte, which is the separator');
120
+ }
121
+ }
122
+ const NUL = String.fromCharCode(0);
123
+ const SEPARATOR = new Uint8Array([0]);
124
+ function normalizeKey(key) {
125
+ const bytes = typeof key === 'string'
126
+ ? new TextEncoder().encode(key)
127
+ : key instanceof Uint8Array
128
+ ? key
129
+ : undefined;
130
+ if (bytes === undefined) {
131
+ throw new TypeError('deriveKeyedToken: key must be a Uint8Array or a string');
132
+ }
133
+ if (bytes.length < exports.MIN_DERIVATION_KEY_BYTES) {
134
+ // The length is metadata about the key, not the key, so naming it is safe
135
+ // and it is the one thing that tells the caller what to fix.
136
+ throw new RangeError(`deriveKeyedToken: key must be at least ${exports.MIN_DERIVATION_KEY_BYTES} bytes, received ${bytes.length}`);
137
+ }
138
+ return bytes;
139
+ }
140
+ function normalizeLength(length) {
141
+ if (length === undefined) {
142
+ return exports.DEFAULT_DERIVED_TOKEN_LENGTH;
143
+ }
144
+ if (!Number.isInteger(length)) {
145
+ throw new RangeError('deriveKeyedToken: length must be a whole number of hex characters');
146
+ }
147
+ if (length < exports.MIN_DERIVED_TOKEN_LENGTH || length > exports.MAX_DERIVED_TOKEN_LENGTH) {
148
+ throw new RangeError(`deriveKeyedToken: length must be between ${exports.MIN_DERIVED_TOKEN_LENGTH} and ` +
149
+ `${exports.MAX_DERIVED_TOKEN_LENGTH} hex characters, received ${length}`);
150
+ }
151
+ return length;
152
+ }
153
+ //# sourceMappingURL=derive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive.js","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":";;;AA6FA,4CAoBC;AAwBD,oEAOC;AAhJD,6CAAyC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;GAUG;AACU,QAAA,wBAAwB,GAAG,EAAE,CAAC;AAE3C,6EAA6E;AAChE,QAAA,wBAAwB,GAAG,EAAE,CAAC;AAE3C,8FAA8F;AACjF,QAAA,4BAA4B,GAAG,EAAE,CAAC;AAE/C;;;;;;;GAOG;AACU,QAAA,wBAAwB,GAAG,EAAE,CAAC;AAyB3C;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAAC,KAAa,EAAE,OAA+B;IAC7E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,S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ringOptions, SerializedDestinationBinding } from './types.js';
2
+ import { SensitiveStringError } from './errors.js';
3
+ /**
4
+ * Destination binding: a value says where it may go, and the gate checks the
5
+ * reveal context against it.
6
+ *
7
+ * Every other control in the gate answers a question about the value or about
8
+ * the process: is it expired, is it revoked, is this region allowed to read
9
+ * it, has its budget been spent. None of them asks where the plaintext is
10
+ * about to be sent. So a credential can be wrapped at entry, revealed at
11
+ * exactly the call site the design says to reveal it, audited, and still
12
+ * written to the wrong host, because the reveal authorized a call site and not
13
+ * a recipient. Measured seven times in the adoption corpus, twice as the same
14
+ * substring host comparison written by two unrelated maintainers.
15
+ *
16
+ * This module is the recipient half. A value constructed with `destinations`
17
+ * carries the sinks, the hosts and the principals it may be revealed toward,
18
+ * and every exposing read is checked against the `sink`, `host`, `proxy` and
19
+ * `principal` tags of the context it runs under. Those two tags are the ones the integrations already write:
20
+ * the HTTP clients set `tags.sink: 'http'` and `tags.host` from the request
21
+ * URL on every reveal, the data layer sets `tags.sink` to its driver, and the
22
+ * LLM package sets it to the sink name it was given. A context that states no
23
+ * destination is refused, on the rule the environment restrictions already
24
+ * follow: an allowlist is the statement "only here", and a caller who has not
25
+ * said where the value is going has not shown that it is going there.
26
+ *
27
+ * What it protects against is what every gate check here protects against: a
28
+ * program that computed its request URL from the wrong input, a credential
29
+ * store that answered a lookup for the wrong origin, a comparison that let
30
+ * `registry.example.com.attacker.net` pass for `registry.example.com`. It does
31
+ * not protect against code in the process that writes the tag itself, which
32
+ * is inside the stated threat model and also visible in the audit record it
33
+ * would have to lie in.
34
+ */
35
+ /** Which half of a binding refused. */
36
+ export type DestinationKind = 'sink' | 'host' | 'principal' | 'proxy';
37
+ /**
38
+ * Raised when an operation needs the raw value of an instance the current
39
+ * context's destination is not allowed to receive.
40
+ *
41
+ * `restriction` says which tag refused and `currentValue` is what the context
42
+ * stated for it, or `undefined` when the context stated nothing. All of it is
43
+ * configuration and none of it is any part of the protected value, so the
44
+ * message is safe to log.
45
+ */
46
+ export declare class DestinationRestrictedError extends SensitiveStringError {
47
+ readonly restriction: DestinationKind;
48
+ readonly currentValue: string | undefined;
49
+ readonly allowedValues: readonly string[];
50
+ readonly label?: string | undefined;
51
+ readonly name = "DestinationRestrictedError";
52
+ readonly code = "destination-restricted";
53
+ constructor(restriction: DestinationKind, currentValue: string | undefined, allowedValues: readonly string[], label?: string | undefined);
54
+ }
55
+ /**
56
+ * A validated binding, held by the value that declares it.
57
+ *
58
+ * Lists are copied out of the caller's object, for the reason the environment
59
+ * restrictions copy theirs: they are read on every access, and a caller who
60
+ * mutates the array they passed must not be able to widen a binding after the
61
+ * fact. Hosts are stored lowercased, which is the form they are compared in.
62
+ */
63
+ export interface ResolvedDestination {
64
+ readonly sinks: readonly string[] | undefined;
65
+ readonly hosts: readonly string[] | undefined;
66
+ readonly principals: readonly string[] | undefined;
67
+ }
68
+ /** The shared empty array a value with no binding points at. */
69
+ export declare const NO_DESTINATIONS: readonly ResolvedDestination[];
70
+ /**
71
+ * Build the destination state for a newly constructed value.
72
+ *
73
+ * Every list is validated here, at construction, so a URL pasted where a host
74
+ * belongs is rejected at the call that wrote it rather than refusing every
75
+ * reveal months later.
76
+ *
77
+ * The option accepts a list as well as a single binding, because a value
78
+ * derived from two bound values carries both, and the wire format has to be
79
+ * able to carry them back.
80
+ *
81
+ * @throws TypeError If an option has the wrong type.
82
+ * @throws RangeError If a list is empty or an entry is not a host or a sink.
83
+ * @throws Error If a binding names no destination.
84
+ */
85
+ export declare function planDestinations(options: SensitiveStringOptions | undefined): readonly ResolvedDestination[] | undefined;
86
+ /**
87
+ * Refuse the read unless the context's destination satisfies every binding.
88
+ *
89
+ * Every binding has to pass, so a value derived from two bound values is at
90
+ * least as bound as each of them, which is rule R2's combination rule with
91
+ * nothing to decide: an intersection is what sharing the state already gives.
92
+ *
93
+ * A context that states no `sink`, no `host` or no `principal` refuses a
94
+ * binding on that field. This is the allowlist rule the environment
95
+ * restrictions follow, and it is the whole point here: a reveal that does not
96
+ * say where the value is going is the reveal this feature exists to refuse.
97
+ * A `proxy` tag is the one read the other way round: absent means the bytes
98
+ * go to the host directly, and present means a second machine receives them
99
+ * first and has to be allowed by the same host list.
100
+ *
101
+ * @throws DestinationRestrictedError If any binding refuses.
102
+ */
103
+ export declare function checkDestinations(destinations: readonly ResolvedDestination[], ctx: RevealContext | null | undefined, label: string | undefined): void;
104
+ /**
105
+ * The wire form of these bindings. Lists only, so nothing is dropped.
106
+ */
107
+ export declare function serializeDestinations(destinations: readonly ResolvedDestination[]): SerializedDestinationBinding[];
108
+ /**
109
+ * Read bindings out of an untrusted payload.
110
+ *
111
+ * They can only tighten: a value rebuilt by `deserialize()` starts with none,
112
+ * so anything a payload carries here refuses reads that would otherwise have
113
+ * been allowed, and there is no spelling of "no binding" that lifts one.
114
+ *
115
+ * An unknown key is rejected rather than ignored, for the reason the
116
+ * environment restrictions reject one: a sender describing a limit this
117
+ * receiver does not know would have that limit silently unenforced.
118
+ */
119
+ export declare function deserializeDestinations(serialized: object): readonly DestinationBinding[] | undefined;
120
+ //# sourceMappingURL=destination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../src/destination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,sBAAsB,EACtB,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,uCAAuC;AACvC,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;AAEtE;;;;;;;;GAQG;AACH,qBAAa,0BAA2B,SAAQ,oBAAoB;IAKhE,QAAQ,CAAC,WAAW,EAAE,eAAe;IACrC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS;IACzC,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,E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