flare-redact 1.5.0 → 1.6.0

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.
@@ -0,0 +1,297 @@
1
+ # FlareFlow 1 — Source-to-sink declassification for tool-using agents
2
+
3
+ Status: experimental specification, August 2026
4
+
5
+ FlareFlow is a deterministic information-flow boundary for reversible redaction
6
+ in tool-using language-model applications. It prevents a model-produced call
7
+ from turning a protected placeholder back into its original value unless a
8
+ runtime-owned capability authorizes the value's source, detector class,
9
+ destination sink, and JSON location. It also limits cumulative restoration
10
+ across turns.
11
+
12
+ The key words **MUST**, **MUST NOT**, **SHOULD**, and **MAY** are normative.
13
+
14
+ ## 1. Scope
15
+
16
+ FlareFlow protects one narrow but important boundary:
17
+
18
+ ```text
19
+ trusted source ──protect──▶ model context ──authorize──▶ trusted sink
20
+ original opaque token original or refusal
21
+ ```
22
+
23
+ It controls exact restoration of values that Flare Redact detected and replaced.
24
+ It is model-independent: enforcement does not depend on a system prompt, model
25
+ classification, tool description, or the model following an instruction.
26
+
27
+ FlareFlow is not:
28
+
29
+ - a general prompt-injection detector or prevention system;
30
+ - semantic taint tracking for information the model has already observed;
31
+ - an authorization system for deciding whether a tool itself may run;
32
+ - protection against a compromised host runtime, policy owner, detector, or
33
+ trusted sink;
34
+ - a guarantee that detection found every sensitive value.
35
+
36
+ ## 2. Trust model
37
+
38
+ The following components are trusted:
39
+
40
+ - the host runtime that calls FlareFlow;
41
+ - source identifiers assigned by that runtime;
42
+ - sink identifiers resolved through the runtime's tool registry;
43
+ - the sink capability policy and resource limits;
44
+ - detectors used before a value enters model context;
45
+ - a final application boundary that deliberately calls `restoreForApp`.
46
+
47
+ The following inputs are untrusted:
48
+
49
+ - model text and structured tool-call arguments;
50
+ - tool names or source labels emitted by a model;
51
+ - placeholders copied from another session or constructed by an attacker;
52
+ - any object location chosen by a model.
53
+
54
+ A conforming integration MUST NOT derive the selected sink, source identity, or
55
+ capability policy from model output without first resolving it to runtime-owned
56
+ metadata. In the gateway profile, clients cannot submit a policy when creating a
57
+ flow; the gateway operator owns it.
58
+
59
+ ## 3. Terms and state
60
+
61
+ - **Source**: a stable runtime identifier for data entering model context, such
62
+ as `postgres.result`, `user.message`, or `config`.
63
+ - **Detector**: the Flare Redact detector identifier that classified a value,
64
+ such as `url_credentials` or `email`.
65
+ - **Sink**: a stable runtime identifier for an operation that may receive a
66
+ restored value, such as `postgres.execute` or `http.fetch`.
67
+ - **Path**: the JSON Pointer location of a placeholder in the complete
68
+ model-produced call.
69
+ - **Capability**: an operator rule that authorizes a set of source and detector
70
+ labels at a set of paths for one sink.
71
+ - **Declassification**: replacement of an opaque token with its original value.
72
+ - **Flow**: one isolated in-memory mapping, budget state, and value-free audit
73
+ history.
74
+
75
+ For each protected value, a flow stores a record:
76
+
77
+ ```text
78
+ token → (original, source, detector, created_at, expires_at, use_count)
79
+ ```
80
+
81
+ For each sink and capability it stores cumulative use counters. Mappings MUST be
82
+ isolated between flows, bounded in count, and removed when expired or revoked.
83
+
84
+ ## 4. Tokens
85
+
86
+ The reference profile uses:
87
+
88
+ ```text
89
+ [FR_FLOW_<32 lowercase hexadecimal characters>]
90
+ ```
91
+
92
+ The hexadecimal component carries 128 bits sampled with Web Crypto. Tokens MUST
93
+ be unpredictable, MUST NOT encode the original, source, detector, or sequence
94
+ number, and MUST be unique among live mappings in the flow.
95
+
96
+ A well-formed token with no live record in the current flow is an unknown token.
97
+ Unknown tokens MUST NOT be restored. This includes forged tokens, expired or
98
+ revoked tokens, and tokens copied from another flow.
99
+
100
+ ## 5. Capability policy
101
+
102
+ Each sink contains an ordered array of capabilities and an optional cumulative
103
+ budget:
104
+
105
+ ```json
106
+ {
107
+ "postgres.execute": {
108
+ "capabilities": [
109
+ {
110
+ "id": "database-connection",
111
+ "sources": ["postgres.result"],
112
+ "detectors": ["url_credentials"],
113
+ "paths": ["/args/connectionString"],
114
+ "maxUses": 1
115
+ }
116
+ ],
117
+ "budget": {
118
+ "maxUses": 4,
119
+ "maxUniqueValues": 2,
120
+ "maxBytes": 512
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
126
+ `sources` and `detectors` are either `"*"` or a non-empty list of identifiers.
127
+ Omitted `detectors` means `"*"`. Paths are RFC 6901 JSON Pointers with two
128
+ extensions:
129
+
130
+ - `*` matches exactly one segment;
131
+ - `**`, only as the final segment, matches zero or more remaining segments.
132
+
133
+ The first capability whose source selector, detector selector, and path all
134
+ match an occurrence is selected. Capability order is therefore observable and
135
+ MUST be preserved. A placeholder in an object or map key is never eligible for
136
+ declassification, regardless of path policy.
137
+
138
+ All budgets are cumulative for the lifetime of a flow:
139
+
140
+ - `maxUses`: number of restored token occurrences;
141
+ - `maxUniqueValues`: number of distinct token records restored to a sink;
142
+ - `maxBytes`: sum of UTF-8 byte lengths of every restored occurrence.
143
+
144
+ Missing budgets are unbounded. Counters do not reset between model turns.
145
+
146
+ ## 6. Operations
147
+
148
+ ### 6.1 Protect
149
+
150
+ `protectForModel(source, input)` MUST:
151
+
152
+ 1. validate the runtime-owned source identifier;
153
+ 2. remove expired mappings;
154
+ 3. detect sensitive spans under the configured Flare Redact policy;
155
+ 4. replace each span with a token bound to `(source, detector)`;
156
+ 5. return a graph-safe copy without mutating the input;
157
+ 6. record only value-free audit metadata.
158
+
159
+ The same `(source, detector, original)` SHOULD reuse one live token. Protection
160
+ is transactional: a resource-limit or audit failure MUST roll back every mapping
161
+ minted by that call.
162
+
163
+ ### 6.2 Inspect
164
+
165
+ `inspectForSink(sink, input)` MUST evaluate the complete call without restoring a
166
+ value or consuming a budget. Its decision reports occurrence counts, projected
167
+ budget use, and value-free violations.
168
+
169
+ ### 6.3 Authorize
170
+
171
+ `authorizeForSink(sink, input)` MUST perform a complete preflight before any
172
+ declassification. For every token occurrence it MUST verify:
173
+
174
+ 1. a live record exists in the same flow;
175
+ 2. the token is in a value position;
176
+ 3. one capability for this sink matches its source, detector, and path;
177
+ 4. the capability's projected use remains within its limit;
178
+ 5. the sink's projected use, unique-value count, and byte count remain within
179
+ their limits.
180
+
181
+ If any occurrence violates any check, the complete operation MUST fail: no token
182
+ is restored and no capability or sink counter is consumed. Passing through a
183
+ partially restored call is forbidden.
184
+
185
+ If all occurrences pass, the implementation MUST first construct the restored
186
+ copy, then emit its value-free audit event, then commit counters, and finally
187
+ return the copy. This ordering ensures cloning or audit failures do not consume
188
+ authorization state or return unaudited plaintext.
189
+
190
+ Audit callbacks MUST NOT re-enter the same flow while an operation is in
191
+ progress. The reference implementation rejects every such call so a callback
192
+ cannot invalidate the preflight snapshot or race a budget commit.
193
+
194
+ A call with no FlareFlow token MAY pass through by identity, including at an
195
+ unconfigured sink. FlareFlow does not authorize the tool call itself; it
196
+ authorizes declassification.
197
+
198
+ ### 6.4 Trusted restoration and revocation
199
+
200
+ `restoreForApp(input)` restores live mappings without sink policy and MUST be
201
+ used only at a trusted final application boundary. `revokeSource(source)` removes
202
+ all mappings minted by that source. `reset()` removes every mapping and counter;
203
+ the reference implementation replaces retained history with one value-free reset
204
+ event. Audit delivery for revocation and reset occurs before mutation; failure
205
+ leaves their mapping, counter, and retained-event state unchanged.
206
+
207
+ ## 7. Security invariant
208
+
209
+ Let `R(t) = (v, s, d, …)` be the live record for token `t`. Let an occurrence of
210
+ `t` appear at path `p` in a call resolved by the runtime to sink `k`.
211
+
212
+ FlareFlow releases `v` at that occurrence only if there exists a configured
213
+ capability `c` for `k` such that:
214
+
215
+ ```text
216
+ source(c, s) ∧ detector(c, d) ∧ path(c, p)
217
+ ∧ within_capability_budget(c)
218
+ ∧ within_sink_budget(k)
219
+ ```
220
+
221
+ and every other token occurrence in the same call also satisfies its checks.
222
+
223
+ Under the trust model in section 2, this gives the reference implementation an
224
+ exact-token noninterference property: changing model-controlled text, sink
225
+ arguments, key positions, or token placement cannot cause an original value to
226
+ appear in the authorized output unless the runtime's policy already grants that
227
+ specific declassification. A denial leaves the flow's authorization counters
228
+ unchanged.
229
+
230
+ This property says nothing about paraphrases, encoded information, or values the
231
+ model saw before protection.
232
+
233
+ ## 8. Violations and audit
234
+
235
+ The reference profile reports these value-free reasons:
236
+
237
+ | Reason | Meaning |
238
+ |---|---|
239
+ | `unknown_token` | No live mapping exists in this flow |
240
+ | `key_position` | A token appears in an object or map key |
241
+ | `capability_denied` | Source, detector, sink, or path is not authorized |
242
+ | `capability_budget_exceeded` | The selected capability lacks remaining uses |
243
+ | `sink_budget_exceeded` | A sink-wide use, unique-value, or byte limit would be exceeded |
244
+
245
+ Audit records MAY contain time, source or sink identifiers, detector ids,
246
+ capability ids, JSON paths, counts, limits, and aggregate budget use. They MUST
247
+ NOT contain originals or token strings. Token-bearing object keys MUST be
248
+ represented by a positional label rather than copied into an audit path. Audit
249
+ retention MUST be bounded.
250
+
251
+ ## 9. Resource and graph behavior
252
+
253
+ Implementations MUST bound live mappings and SHOULD bound retained events and
254
+ flow count. A gateway flow SHOULD have both a mapping TTL and an idle-flow TTL.
255
+ When a hard mapping limit is reached, protection MUST fail closed and roll back
256
+ the incomplete transaction.
257
+
258
+ The JavaScript reference preserves cycles, sparse arrays, shared references,
259
+ maps, sets, errors, URLs, enumerable symbol properties, and property descriptors
260
+ to the same extent as the core graph transformer. Accessor properties are not
261
+ invoked. Atomic host objects are not traversed.
262
+
263
+ ## 10. Reference APIs
264
+
265
+ JavaScript and TypeScript:
266
+
267
+ ```js
268
+ import { createAgentFlow } from 'flare-redact/agent';
269
+
270
+ const flow = createAgentFlow({ policy, sinks, limits });
271
+ const safe = flow.protectForModel('postgres.result', toolResult);
272
+ const decision = flow.inspectForSink('postgres.execute', modelCall);
273
+ const localCall = flow.authorizeForSink('postgres.execute', modelCall);
274
+ ```
275
+
276
+ Gateway control plane:
277
+
278
+ ```text
279
+ POST /v1/flows
280
+ POST /v1/flows/:id/protect
281
+ POST /v1/flows/:id/inspect
282
+ POST /v1/flows/:id/authorize
283
+ POST /v1/flows/:id/restore
284
+ GET /v1/flows/:id/snapshot
285
+ DELETE /v1/flows/:id
286
+ ```
287
+
288
+ The sidecar makes the same operator policy available to any JSON/HTTP client.
289
+ The repository ships standard-library clients for Python and Go.
290
+
291
+ ## 11. Reproducibility profile
292
+
293
+ `bench/agent-flow-cases.json` defines deterministic attack and utility families.
294
+ `npm run benchmark:agent -- --json` evaluates the legacy shared vault, the
295
+ tool-scoped vault, and FlareFlow. The corpus measures exact-token restoration
296
+ only. Results MUST be reported with the corpus scope statement and MUST NOT be
297
+ presented as a general prompt-injection benchmark.