Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d9cd722
feat(flow): keep only declared fields of captured bodies on disk
abrichr Nov 21, 2026
1217bb5
fix(flow): keep the minimizer stdlib-only and inside the wire-tap imp…
abrichr Nov 21, 2026
b44d8ad
refactor(flow): keep record CLI plumbing in network_capture under the…
abrichr Nov 21, 2026
facb4ec
fix(flow): close the capture-minimization gaps found in cross-vendor …
abrichr Nov 22, 2026
eb95a37
fix(flow): keep minimized HAR descriptions across a reload and return…
abrichr Nov 22, 2026
9020fb1
Merge remote-tracking branch 'origin/main' into claude/nodb-capture-p…
abrichr Nov 22, 2026
a6a8976
fix(flow): close the four capture-privacy findings left open
abrichr Nov 22, 2026
4bfdc86
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 22, 2026
3c34fec
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 22, 2026
3312611
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 22, 2026
6606a89
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
36f697e
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
8baeb03
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
098e671
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 24, 2026
3fbfeb2
test(flow): support default-at-rest v3 sealed sets in capture privacy…
abrichr Nov 24, 2026
af0447c
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 24, 2026
0f65a6c
chore(flow): simplify _utf8 trailing-byte slice to satisfy verdict fo…
abrichr Nov 24, 2026
a78ea31
test(flow): allow synthetic plaintext fixture in test_api_capture_ref…
abrichr Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| Keep captured bodies off disk: `network.jsonl` and saved wire-tap HARs keep only declared field values (a recording's `--param` and `--identifier` fields; a wire policy's id and version fields) and a per-capture keyed hash of everything else, including URL query values; HTML, text and binary bodies keep only size and hash, taken from the bytes as sent (only a body labelled JSON, or with no content type, is parsed as JSON); the recording's `app_url` query and URL-valued HAR headers are minimized too, and a HAR marked minimized that carries a raw body is refused on load. Raw bodies (`--capture-network-bodies raw`, `save_har(raw_bodies=True)`), which API step proposals need, are refused unless sealed at rest or plaintext is explicitly allowed (`OPENADAPT_FLOW_PLAINTEXT_AT_REST`, warned and logged). Not covered: URL path segments and header values beyond credential redaction | On main (this PR) | Synthetic PHI in request and response bodies, absent from every file after decryption in raw, percent, JSON-escaped, base64 and gzip forms; positive controls with raw | `openadapt_flow/capture_privacy.py`, [NETWORK_CAPTURE.md](packages/flow/docs/NETWORK_CAPTURE.md#bodies-minimized-by-default) |
16 changes: 16 additions & 0 deletions packages/flow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@
application vocabulary: month names, yes and no words, currency signs and
tables come from the pack. See docs/EFFECT_LOCATION.md.

### Changes

- Network captures no longer write raw bodies by default. `record
--capture-network` keeps only the `--param` and `--identifier` values of
each request and response body, plus a per-capture keyed hash of every
other value and of each HTML, text or binary body; undeclared URL query
values are hashed too. `dump_har` and `save_har` do the same with the wire
policy's id and version fields. `--capture-network-bodies raw` (and
`raw_bodies=True`) keeps the redacted bodies, which API step and undo
proposals need, and is refused unless the recording is encrypted or
`OPENADAPT_FLOW_PLAINTEXT_AT_REST` explicitly allows plaintext. Binary
bodies, files and non-text responses are sized and hashed from their
bytes as sent; the recording's `app_url` query is minimized too; an
explicit `application/octet-stream` body is never parsed as JSON (a
missing content type still is); and `load_har` refuses a HAR marked
minimized that carries a raw body.
### Fixes

- `verify-run`: an effect list that is empty, or tiers that don't pair one to
Expand Down
6 changes: 4 additions & 2 deletions packages/flow/benchmark/api_generalization/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ def cmd_record(a: argparse.Namespace, app: AppBase) -> None:
from playwright.sync_api import sync_playwright

from openadapt_flow.backends.playwright_backend import PlaywrightBackend
from openadapt_flow.network_capture import NetworkCapture
from openadapt_flow.network_capture import NetworkCapture, require_raw_ready
from openadapt_flow.recorder import Recorder

out = Path(a.out)
if out.exists():
raise SystemExit(f"exists: {out}")
# Raw bodies (synthetic data) need OPENADAPT_FLOW_PLAINTEXT_AT_REST here.
require_raw_ready(out)
start_proxy(app)
values = app.recording_values()
if a.tag:
Expand All @@ -143,7 +145,7 @@ def cmd_record(a: argparse.Namespace, app: AppBase) -> None:
page.goto(app.base + "/")
if app.login_required:
app.login(page)
capture = NetworkCapture(ctx).start()
capture = NetworkCapture(ctx, bodies="raw").start()
app.open_form(page)
rec = Recorder(
PlaywrightBackend(page),
Expand Down
11 changes: 9 additions & 2 deletions packages/flow/benchmark/openemr_api_tier/feature_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,26 @@

def cmd_record(a: argparse.Namespace) -> None:
from benchmark.harness.openemr_local import SyntheticPatientSpec
from openadapt_flow.network_capture import NetworkCapture
from openadapt_flow.network_capture import NetworkCapture, require_raw_ready
from openadapt_flow.recorder import Recorder

demo = load_demo()
out = Path(a.out)
if out.exists():
raise SystemExit(f"exists: {out}")
if not a.no_capture:
# Raw bodies (synthetic data) need OPENADAPT_FLOW_PLAINTEXT_AT_REST.
require_raw_ready(out)
f = SpikeFixture()
reset_and_seed(f)
print(json.dumps({"record_gate": wait_quiet()}), flush=True)
backend, close = demo._BasePlaywrightBackend.launch(f.ui_base_url, headless=True)
try:
capture = None if a.no_capture else NetworkCapture(backend.page.context).start()
capture = (
None
if a.no_capture
else NetworkCapture(backend.page.context, bodies="raw").start()
)
demo._preauthenticate_browser(backend, f)
page = backend.page
form = demo._form_frame(page)
Expand Down
9 changes: 7 additions & 2 deletions packages/flow/benchmark/undo_proposal/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ def _fixtures() -> dict[str, Fixture]:
def _record_with_capture(fixture: Fixture, url: str, out: Path) -> Path:
"""The demo driver's recording, with the browser's traffic captured."""
from openadapt_flow import demo_driver
from openadapt_flow.network_capture import NetworkCapture
from openadapt_flow.network_capture import NetworkCapture, require_raw_ready

# Raw bodies (synthetic data) need OPENADAPT_FLOW_PLAINTEXT_AT_REST here.
require_raw_ready(out)
original = demo_driver.PlaywrightBackend.launch
captures: list[tuple[NetworkCapture, float]] = []

def launch(*args: Any, **kwargs: Any):
backend, close = original(*args, **kwargs)
captures.append(
(NetworkCapture(backend.page.context).start(), time.monotonic())
(
NetworkCapture(backend.page.context, bodies="raw").start(),
time.monotonic(),
)
)
return backend, close

Expand Down
9 changes: 7 additions & 2 deletions packages/flow/benchmark/zero_config_verify/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ def drive(
"""Run the task's selector solution. With ``recording``, write the
recording the recorder would: events, params and the network capture."""

from openadapt_flow.network_capture import NetworkCapture
from openadapt_flow.network_capture import NetworkCapture, require_raw_ready

if recording is not None:
# Raw bodies (synthetic data) need OPENADAPT_FLOW_PLAINTEXT_AT_REST.
require_raw_ready(recording)
context = browser.new_context(viewport={"width": 1280, "height": 900})
capture = NetworkCapture(context).start() if recording is not None else None
capture = (
NetworkCapture(context, bodies="raw").start() if recording is not None else None
)
t0 = time.monotonic()
events: list[dict[str, Any]] = []
page = context.new_page()
Expand Down
14 changes: 10 additions & 4 deletions packages/flow/docs/API_TIER.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ against 15.95 s and two approvals with API steps off (20 runs each,
## How to use it

```bash
openadapt-flow record --backend web --url https://app.example/ --capture-network --out rec/
# Raw bodies need an encrypted recording: a recording key, or strict mode.
OPENADAPT_FLOW_AT_REST=strict openadapt-flow record --backend web \
--url https://app.example/ --capture-network \
--capture-network-bodies raw --out rec/
openadapt-flow compile rec/ --out bundle/ --name referral
openadapt-flow api show bundle/
openadapt-flow api admit bundle/ --identity subject_name=lname # a person, at a terminal
openadapt-flow run bundle/ ...
```

1. **Record with `--capture-network`.** Flow keeps the page's requests next
to the recorded events in `network.jsonl`. Start the recording before you
open the form, so the page that serves the form is captured.
1. **Record with `--capture-network --capture-network-bodies raw`.** Flow
keeps the page's requests next to the recorded events in `network.jsonl`.
The proposal needs the raw (redacted) bodies; the default keeps only
declared fields ([NETWORK_CAPTURE.md](NETWORK_CAPTURE.md)), and raw needs
an encrypted recording. Start the recording before you open the form, so
the page that serves the form is captured.
2. **Compile.** If the save can be repeated as one request, `compile`
proposes an API step on the save step. `api_proposal.json` in the bundle
says either which step got the proposal, or why there is none.
Expand Down
59 changes: 56 additions & 3 deletions packages/flow/docs/NETWORK_CAPTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ order the browser finished them:
{"seq": 0, "t": -2.102, "method": "GET", "url": "http://127.0.0.1:9811/", "status": 302, ...}
```

The header's `bodies` is `"minimized"` (the default) or `"raw"`; a file
without it was written before minimization existed and is raw.
`network_capture.bodies_mode(recording_dir)` reads it.

`meta.json` also records `network_capture: {"file": "network.jsonl",
"exchanges": N}`.

Expand Down Expand Up @@ -52,6 +56,55 @@ order the browser finished them:
Static assets (images, fonts, style sheets, scripts, media, manifests) are
not captured.

## Bodies: minimized by default

`record --capture-network-bodies minimized` (the default) parses each body in
memory and writes only what the recording declared
(`openadapt_flow/capture_privacy.py`):

- **Kept:** the values of the recording's `--param` and `--identifier`
fields, wherever they appear in a JSON, url-encoded or plain multipart
body, or a URL query.
- **Hashed:** every other value, as `hmac-sha256:<hex>` under a key made
for this capture and never written. Equal values hash equally within one
file; hashes from different files can't be compared, and a short value
(a birth date) can't be recovered by trying candidates.
- **Opaque:** HTML, plain text, binary, a cut body or form, or a
multipart body with a file keeps only its length, content type and hash.
JSON is parsed only from a body labelled JSON or with no content type;
JSON-looking text of any other type, including an explicit
`application/octet-stream`, is opaque. Length and hash are taken from the
body's bytes as sent, before decoding, redaction or cutting.

So `form`, `body` and `response_text` are replaced by `form_minimized`,
`body_minimized` and `response_minimized`, each `{"kept": [[path, value]],
"withheld": [[path, hash]]}` (bodies also carry `format`, `bytes`,
`content_type` and a whole-body `hmac`), and `url`, `frame_url` and
`location` have undeclared query values hashed (also a query in the
fragment, `#/search?q=...`, and a bare search term, `?term`). The
recording's starting URL in `meta.json` (`app_url`) gets the same
treatment, under the same key. Not minimized: URL path segments
(`/patients/1234`) and JSON keys that look like field names.

Every response that is not a static asset is described: a binary or other
non-text response (a PDF, a download) and a url-encoded response get a
`response_minimized` too. A binary body is never written as text, raw mode
included.

A saved wire-tap HAR is minimized the same way, including URL-valued
headers (`Location`, `Referer`, `Content-Location`, `Refresh`). A HAR that
is marked minimized but has a body with other text or form `params` is
refused when loaded (`load_har`, `from_har`).

Readers find no body in a minimized file and propose nothing from it: no
API step, no undo proposal, no record check from the app's reads. Record
with `--capture-network-bodies raw` for those and for debugging. Raw is
refused unless the recording is encrypted (set `OPENADAPT_RECORDING_KEY` or
`OPENADAPT_BUNDLE_KEY`, or use `OPENADAPT_FLOW_AT_REST=strict`; never with
`--no-encrypt`) or `OPENADAPT_FLOW_PLAINTEXT_AT_REST` explicitly allows
plaintext, which is warned about and logged. Code that builds
`NetworkCapture(bodies="raw")` itself calls `require_raw_ready()` first. The redaction below applies to raw bodies.

## Redaction, before anything is written

Nothing below reaches the disk. Values are held in memory during the
Expand Down Expand Up @@ -83,9 +136,9 @@ JSON body, a password-like or token-like field is replaced field by field,
whatever the length of its value.

Replacement is by exact value (and its URL-encoded form), longest value
first. Business values the person typed (names, dates, addresses) are not
redacted, as in `events.jsonl`. Treat a recording with capture as you treat
any recording: it can contain patient or customer data.
first. In a raw capture, business values the person typed (names, dates,
addresses) are not redacted, as in `events.jsonl`. Treat a recording with
capture as you treat any recording: it can contain patient or customer data.

## Lining up requests and events

Expand Down
16 changes: 5 additions & 11 deletions packages/flow/openadapt_flow/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,7 @@ def _cmd_record_capture(args: argparse.Namespace) -> int:
BrowserAttachError,
record_interactive,
)
from openadapt_flow.network_capture import cli_mode

try:
out = record_interactive(
Expand All @@ -1545,7 +1546,7 @@ def _cmd_record_capture(args: argparse.Namespace) -> int:
browser_page_url=getattr(args, "browser_page_url", None),
stop_when=_record_until_stop(args),
surface="web",
capture_network=bool(getattr(args, "capture_network", False)),
capture_network=cli_mode(args, recording_key),
encryption_key=recording_key,
)
except BrowserAttachError as exc:
Expand Down Expand Up @@ -9583,16 +9584,9 @@ def build_parser() -> argparse.ArgumentParser:
"refused under OPENADAPT_FLOW_AT_REST=strict"
),
)
p.add_argument(
"--capture-network",
action="store_true",
help=(
"Web only: also keep the page's requests (network.jsonl; cookies, "
"passwords and session tokens withheld). compile then proposes an "
"API step for a save it can repeat as one request; a person admits "
"it with 'api admit'"
),
)
from openadapt_flow.network_capture import add_cli_arguments as _network_args

_network_args(p)
p.add_argument(
"--with-check",
action="store_true",
Expand Down
Loading
Loading