diff --git a/llms-full.txt b/llms-full.txt index d0e22706e7..b61178f5a0 100644 --- a/llms-full.txt +++ b/llms-full.txt @@ -2426,9 +2426,20 @@ automation into an independently certified transaction system. registered that admitter key (`GET /api/v1/org/{org}/admitter-keys`) and otherwise refuses with `ADMITTER_KEY_UNREGISTERED`, naming the principal id and public key an owner or admin must register. +- `openadapt login` with no token signs in through the browser: a PKCE + loopback grant on `127.0.0.1` that stores the same credential `push` and + `report-run` use. `--token`, `OPENADAPT_INGEST_TOKEN` and a stored token keep + the old path (#2379). ### Fixes +- A headed browser window that draws no frames (on macOS, one covered by a + full-size terminal window) no longer halts a run at its first step. The + page settle waited for two animation frames after the last change, which + such a window never draws, so the readiness gate timed out after 10 s with + "starting state not ready". When every other page signal is quiet and the + page has drawn no frame for a second, or the page is hidden, the settle now + falls back to two identical screenshots. - Choice labels, values, shape metadata and browser-dialog messages are checked against declared secrets before capture. A matching or opaque secret boundary stops recording before that text reaches its artifacts. @@ -2458,3 +2469,41 @@ automation into an independently certified transaction system. derived from its explicit key for its own lifetime. Without that, each checkpoint read ran scrypt again, and the MockMed quickstart run took 28 s instead of 3.5 s (131 derivations, now 1). +- In reverse-proxy mode the wire tap relays a redirect to a path on the + upstream origin, rebuilt on the tap's own origin, instead of answering 502, + so it can front a form app that answers a save with Post/Redirect/Get. The + client's next request comes back through the tap. Browser route mode still + refuses every redirect, and the tap never follows one itself (#2392). +- Guarded native keyboard delivery on a Windows agent that advertises + `native_keyboard_lease_v1` uses a one-shot focus lease over the authorized + control and frame. #2313 describes when it applies and what it checks. +- A repair candidate id that would leave the repair store is refused (#2369). +- `wrap publish` no longer refuses programs whose identity templates carry + `punctuation_body_keys`. These values are salted token hashes, the same + generated shape as the `c` and `r` keys, but the sanitizer sent them to + the PHI recognizer. It sometimes read one as an organization or a group + name and rewrote it, so publish stopped with `SANITIZATION_CHANGED_PROGRAM`. + Only an index key with a hex hash of 16 or more characters is kept. Free + text in that slot is still scrubbed. +- An admitted managed run, and its resume, keep the policy the local Standard + gate chose when neither the CLI nor the deployment names one, instead of + exiting with code 2 (#2401). +- Lens route induction can use a trace's observed effects, not only HTTP + methods, to assign route roles (#2393). +- Generated verify contracts stop fewer correct writes: five generator causes + of false stops are fixed, each by one schema-independent rule (#2418). +- `import openadapt_flow` loads its `ir` re-exports on first use, and the + qualification models and several replayer helpers moved into their own + modules. Names still import explicitly from their old modules; + `from openadapt_flow.qualification import *` no longer includes + `AUTOMATED_GUI_ACTUATIONS` or `build_outcome_envelope` (#2439, #2451, #2454, + #2455, #2456, #2459). + +### Requirements + +- The `privacy` extra needs `openadapt-privacy[presidio]>=1.1.4`, the first + release with `sanitization_config()`, which sanitized reuse and approval bind + to. +- On Python 3.11 and newer, the lock moves Pillow, filelock and other + dependencies to a release that fixes an open security advisory. The + Python 3.10 lock keeps Pillow 12.3.0 and filelock 3.29.7 (#2383). diff --git a/packages/flow/CHANGELOG.md b/packages/flow/CHANGELOG.md index 9dd6142819..d5a15df702 100644 --- a/packages/flow/CHANGELOG.md +++ b/packages/flow/CHANGELOG.md @@ -15,26 +15,7 @@ -## Unreleased - -### Fixes - -- A headed browser window that draws no frames (on macOS, one covered by a - full-size terminal window) no longer halts a run at its first step. The - page settle waited for two animation frames after the last change, which - such a window never draws, so the readiness gate timed out after 10 s with - "starting state not ready". When every other page signal is quiet and the - page has drawn no frame for a second, or the page is hidden, the settle now - falls back to two identical screenshots. -- `wrap publish` no longer refuses programs whose identity templates carry - `punctuation_body_keys`. These values are salted token hashes, the same - generated shape as the `c` and `r` keys, but the sanitizer sent them to - the PHI recognizer. It sometimes read one as an organization or a group - name and rewrote it, so publish stopped with `SANITIZATION_CHANGED_PROGRAM`. - Only an index key with a hex hash of 16 or more characters is kept. Free - text in that slot is still scrubbed. - -## v3.4.0 (held until PyPI serves openadapt-privacy 1.1.4) +## v3.4.0 (2026-11-21) ### Features @@ -83,9 +64,20 @@ registered that admitter key (`GET /api/v1/org/{org}/admitter-keys`) and otherwise refuses with `ADMITTER_KEY_UNREGISTERED`, naming the principal id and public key an owner or admin must register. +- `openadapt login` with no token signs in through the browser: a PKCE + loopback grant on `127.0.0.1` that stores the same credential `push` and + `report-run` use. `--token`, `OPENADAPT_INGEST_TOKEN` and a stored token keep + the old path (#2379). ### Fixes +- A headed browser window that draws no frames (on macOS, one covered by a + full-size terminal window) no longer halts a run at its first step. The + page settle waited for two animation frames after the last change, which + such a window never draws, so the readiness gate timed out after 10 s with + "starting state not ready". When every other page signal is quiet and the + page has drawn no frame for a second, or the page is hidden, the settle now + falls back to two identical screenshots. - Choice labels, values, shape metadata and browser-dialog messages are checked against declared secrets before capture. A matching or opaque secret boundary stops recording before that text reaches its artifacts. @@ -115,6 +107,44 @@ derived from its explicit key for its own lifetime. Without that, each checkpoint read ran scrypt again, and the MockMed quickstart run took 28 s instead of 3.5 s (131 derivations, now 1). +- In reverse-proxy mode the wire tap relays a redirect to a path on the + upstream origin, rebuilt on the tap's own origin, instead of answering 502, + so it can front a form app that answers a save with Post/Redirect/Get. The + client's next request comes back through the tap. Browser route mode still + refuses every redirect, and the tap never follows one itself (#2392). +- Guarded native keyboard delivery on a Windows agent that advertises + `native_keyboard_lease_v1` uses a one-shot focus lease over the authorized + control and frame. #2313 describes when it applies and what it checks. +- A repair candidate id that would leave the repair store is refused (#2369). +- `wrap publish` no longer refuses programs whose identity templates carry + `punctuation_body_keys`. These values are salted token hashes, the same + generated shape as the `c` and `r` keys, but the sanitizer sent them to + the PHI recognizer. It sometimes read one as an organization or a group + name and rewrote it, so publish stopped with `SANITIZATION_CHANGED_PROGRAM`. + Only an index key with a hex hash of 16 or more characters is kept. Free + text in that slot is still scrubbed. +- An admitted managed run, and its resume, keep the policy the local Standard + gate chose when neither the CLI nor the deployment names one, instead of + exiting with code 2 (#2401). +- Lens route induction can use a trace's observed effects, not only HTTP + methods, to assign route roles (#2393). +- Generated verify contracts stop fewer correct writes: five generator causes + of false stops are fixed, each by one schema-independent rule (#2418). +- `import openadapt_flow` loads its `ir` re-exports on first use, and the + qualification models and several replayer helpers moved into their own + modules. Names still import explicitly from their old modules; + `from openadapt_flow.qualification import *` no longer includes + `AUTOMATED_GUI_ACTUATIONS` or `build_outcome_envelope` (#2439, #2451, #2454, + #2455, #2456, #2459). + +### Requirements + +- The `privacy` extra needs `openadapt-privacy[presidio]>=1.1.4`, the first + release with `sanitization_config()`, which sanitized reuse and approval bind + to. +- On Python 3.11 and newer, the lock moves Pillow, filelock and other + dependencies to a release that fixes an open security advisory. The + Python 3.10 lock keeps Pillow 12.3.0 and filelock 3.29.7 (#2383). ## v3.3.0 (2026-11-19) diff --git a/packages/flow/openadapt_flow/tx/wire_tap.py b/packages/flow/openadapt_flow/tx/wire_tap.py index aa2a947828..bdbfb09bf3 100644 --- a/packages/flow/openadapt_flow/tx/wire_tap.py +++ b/packages/flow/openadapt_flow/tx/wire_tap.py @@ -89,12 +89,19 @@ def _utc_now_iso() -> str: def _normalize_origin(url_or_origin: str) -> str: - parts = urlsplit(url_or_origin.strip()) - if not parts.scheme or not parts.netloc: + try: + parts = urlsplit(url_or_origin.strip()) + if not parts.scheme or not parts.netloc: + return "" + scheme = parts.scheme.lower() + host = (parts.hostname or "").lower() + port = parts.port + except ValueError: + # A malformed port or bracketed host is no origin at all. return "" - scheme = parts.scheme.lower() - host = (parts.hostname or "").lower() - port = parts.port + if ":" in host: + # Keep IPv6 brackets so a port can never read as part of the address. + host = f"[{host}]" if ( port is None or (scheme == "http" and port == 80) @@ -114,6 +121,9 @@ def relay_redirect_location( ) -> Optional[str]: """Return the ``Location`` to relay for a same-origin redirect, else ``None``. + Reverse-proxy mode only: the client's next request comes back through the + tap, so every hop is checked again. Browser route mode refuses redirects. + The tap never follows a redirect itself. It hands a redirect back to the client only when the target, resolved against the request URL, stays on an allowed origin, so the next request passes through the tap again. A @@ -121,29 +131,37 @@ def relay_redirect_location( ``rewrite_from_origin``/``rewrite_to_origin`` map an absolute upstream target onto the tap's own origin in reverse-proxy mode. """ - raw = (location or "").strip() - # Browsers read a backslash as a slash, so ``/\\host`` leaves the origin - # even though URL parsers here treat it as a relative path. - if not raw or any(ch in raw for ch in "\r\n\\"): + raw = location or "" + # Validate the header exactly as received. Browsers drop tabs and newlines + # inside a URL and read a backslash as a slash, so refuse any space, + # control character or backslash rather than guess how a client reads it. + if not raw or any(ord(ch) <= 0x20 or ord(ch) == 0x7F or ch == "\\" for ch in raw): + return None + try: + resolved = urljoin(request_url, raw) + origin = _normalize_origin(resolved) + parts = urlsplit(raw) + except ValueError: return None - resolved = urljoin(request_url, raw) - origin = _normalize_origin(resolved) if not origin or origin not in allowed_origins: return None - parts = urlsplit(raw) - if not parts.scheme and not parts.netloc: + # Only a plain path relays as written. Anything with a scheme or an + # authority, including ``///host`` that urlsplit reads as a path but a + # browser reads as a host, is relayed only as the URL checked here, + # rebuilt on the tap's own origin. + if not parts.scheme and not parts.netloc and not raw.startswith("//"): return raw - if rewrite_from_origin is not None and rewrite_to_origin is not None: - if origin != rewrite_from_origin: - return None - target = urlsplit(resolved) - rewritten = rewrite_to_origin.rstrip("/") + (target.path or "/") - if target.query: - rewritten += "?" + target.query - if target.fragment: - rewritten += "#" + target.fragment - return rewritten - return raw + if rewrite_from_origin is None or rewrite_to_origin is None: + return None + if origin != rewrite_from_origin: + return None + target = urlsplit(resolved) + rewritten = rewrite_to_origin.rstrip("/") + (target.path or "/") + if target.query: + rewritten += "?" + target.query + if target.fragment: + rewritten += "#" + target.fragment + return rewritten class _ResolvedTarget(NamedTuple): @@ -1250,7 +1268,9 @@ def _evaluate_policy_locked( ): return "secret_in_url" - if target_origin and target_origin not in self._allowed_origins: + # A target with no parseable origin (for example an invalid port) is + # never forwarded: an empty origin must not skip the allowlist. + if not target_origin or target_origin not in self._allowed_origins: return "disallowed_origin" if not is_mutation: @@ -1826,20 +1846,10 @@ def _handle_route(route: Any) -> None: if callable(fetch_fn) and callable(fulfill_fn): fetched = fetch_fn(max_redirects=0) resp_status, resp_headers, resp_body = _extract_route_response(fetched) - relayed_location = ( - relay_redirect_location( - _get_header(resp_headers, "location"), - request_url=req_url, - allowed_origins=self._allowed_origins, - ) - if resp_status is not None and 300 <= resp_status < 400 - else None - ) - if ( - resp_status is not None - and 300 <= resp_status < 400 - and relayed_location is None - ): + # Playwright runs this handler only for the first URL of a + # redirect chain, so a relayed redirect would leave later hops + # unchecked. Refuse every redirect in this mode. + if resp_status is not None and 300 <= resp_status < 400: self._finalize_request( ticket, request_headers=req_headers, diff --git a/packages/flow/pyproject.toml b/packages/flow/pyproject.toml index 030efd18f6..b4d9a64959 100644 --- a/packages/flow/pyproject.toml +++ b/packages/flow/pyproject.toml @@ -280,7 +280,7 @@ registry = ["sigstore>=4.5,<5; python_version >= '3.11'"] # deployment installs this and sets OPENADAPT_FLOW_SCRUB=on to fail closed. # After install: python -m spacy download en_core_web_sm privacy = [ - "openadapt-privacy[presidio]>=1.0.0", + "openadapt-privacy[presidio]>=1.1.4", # spaCy imports Click directly from its CLI package but does not declare it; # Typer 0.27 stopped supplying Click transitively. Keep regulated-mode # compilation importable under fresh, unconstrained PyPI resolution. diff --git a/packages/flow/tests/test_agent_write_guard.py b/packages/flow/tests/test_agent_write_guard.py index 0086a7685e..ecb0e4a270 100644 --- a/packages/flow/tests/test_agent_write_guard.py +++ b/packages/flow/tests/test_agent_write_guard.py @@ -199,16 +199,36 @@ def _saturate_pool() -> threading.Event: from openadapt_flow.integrations.agents import _POOL release = threading.Event() + started = threading.Barrier(_POOL._max_workers + 1) + + def _hold() -> None: + started.wait(timeout=10) + release.wait(30) + for _ in range(_POOL._max_workers): - _POOL.submit(release.wait, 30) + _POOL.submit(_hold) + started.wait(timeout=10) return release def test_a_read_back_queued_behind_a_full_pool_survives_a_timeout( - portal: Portal, tmp_path: Path + portal: Portal, tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: + from openadapt_flow.integrations.agents import _POOL + guard = _guard(portal, tmp_path) blockers: list[threading.Event] = [] + queued = asyncio.Event() + loop_ref: list[asyncio.AbstractEventLoop] = [] + real_submit = _POOL.submit + + def _tracking_submit(fn, /, *args, **kwargs): + fut = real_submit(fn, *args, **kwargs) + if blockers and fn == guard._finish: + loop_ref[0].call_soon_threadsafe(queued.set) + return fut + + monkeypatch.setattr(_POOL, "submit", _tracking_submit) async def write(): out = await asyncio.to_thread(portal.save_order, **ORDER) @@ -216,9 +236,12 @@ async def write(): return out async def timed_out(): + loop_ref.append(asyncio.get_running_loop()) + task = asyncio.create_task(guard.arun(ORDER, write)) + await asyncio.wait_for(queued.wait(), timeout=10.0) with pytest.raises(TimeoutError): - async with asyncio.timeout(0.5): - await guard.arun(ORDER, write) + async with asyncio.timeout(0.05): + await task try: asyncio.run(timed_out()) diff --git a/packages/flow/tests/test_tx_wire_redirects.py b/packages/flow/tests/test_tx_wire_redirects.py index 7bc61ab2e2..47283be35d 100644 --- a/packages/flow/tests/test_tx_wire_redirects.py +++ b/packages/flow/tests/test_tx_wire_redirects.py @@ -180,7 +180,75 @@ def test_relay_helper_refuses_malformed_or_non_http_targets(location): ) -def test_browser_route_relays_same_origin_redirect_and_aborts_foreign(): +@pytest.mark.parametrize( + "location", + [ + "http:/evil.test/x", + "https:/evil.test/x", + "http:evil.test", + "///evil.test/x", + "////evil.test", + "http://127.0.0.1:8000/ok", + ], +) +def test_without_a_rewrite_only_plain_paths_relay(location): + # Without the reverse-proxy rewrite, nothing with a scheme or authority + # relays: a browser may read it as a different host than urljoin did. + origin = "http://127.0.0.1:8000" + assert ( + relay_redirect_location( + location, + request_url=f"{origin}/form", + allowed_origins=frozenset({origin}), + ) + is None + ) + + +@pytest.mark.parametrize( + "location", ["http:/evil.test/x", "///evil.test/x", "http://up.test/next?a=1"] +) +def test_reverse_proxy_rewrite_never_relays_raw_absolute_text(location): + up, tap = "http://up.test", "http://127.0.0.1:9000" + relayed = relay_redirect_location( + location, + request_url=f"{up}/form", + allowed_origins=frozenset({up}), + rewrite_from_origin=up, + rewrite_to_origin=tap, + ) + # Either refused, or rebuilt on the tap's origin from the checked URL. + assert relayed is None or relayed.startswith(tap + "/") + + +@pytest.mark.parametrize( + "location", + ["/\t/evil.test", "/ok\tx", " /ok", "/ok ", "/ok x", "/ok\x7f", "http://[::1"], +) +def test_relay_helper_refuses_unclean_or_unparseable_headers(location): + origin = "http://127.0.0.1:8000" + assert ( + relay_redirect_location( + location, + request_url=f"{origin}/form", + allowed_origins=frozenset({origin}), + ) + is None + ) + + +def test_ipv6_origins_keep_their_brackets(): + from openadapt_flow.tx.wire_tap import _normalize_origin + + assert _normalize_origin("http://[::1]:8080/x") == "http://[::1]:8080" + assert _normalize_origin("http://[::1:8080]/x") == "http://[::1:8080]" + assert _normalize_origin("http://[::1]:8080") != _normalize_origin( + "http://[::1:8080]" + ) + assert _normalize_origin("http://h:notaport/") == "" + + +def test_browser_route_refuses_every_redirect(): origin = "http://127.0.0.1:8000" class Response: @@ -227,7 +295,9 @@ def route(self, pattern: str, handler: Any) -> None: foreign = Route(f"{origin}/save", "http://127.0.0.1:1/steal") page.handler(same) page.handler(foreign) - assert same.fulfilled is not None and not same.aborted + # Playwright calls the handler only for a chain's first URL, so even a + # same-origin redirect would leave later hops unchecked: both abort. + assert same.aborted and same.fulfilled is None assert foreign.aborted and foreign.fulfilled is None statuses = [m.response_status for m in tap.summary().mutations] assert statuses == [302, 302] diff --git a/packages/flow/tests/test_tx_wire_request_targets.py b/packages/flow/tests/test_tx_wire_request_targets.py index 6ab9bb705c..5268dc4269 100644 --- a/packages/flow/tests/test_tx_wire_request_targets.py +++ b/packages/flow/tests/test_tx_wire_request_targets.py @@ -215,3 +215,13 @@ def test_all_entrypoints_share_stateful_budget_and_write_route_policy( assert route.events == ["abort"] assert tap.summary().mutations[0].block_reason == "undeclared_write_route" assert tap.summary().mutations_allowed == 0 + + +@pytest.mark.parametrize("suffix", [":notaport/rows", ":99999/rows", ":-1/rows"]) +def test_absolute_target_with_an_unparseable_origin_is_refused(upstream, suffix): + origin, seen = upstream + host = urlsplit(origin).hostname + with SessionWireTap(origin, WirePolicy(max_mutations=None)) as tap: + status = send(tap, "GET", f"http://{host}{suffix}") + assert status >= 400 + assert seen == [] diff --git a/packages/flow/uv.lock b/packages/flow/uv.lock index fa3a0567a4..c264d27eaf 100644 --- a/packages/flow/uv.lock +++ b/packages/flow/uv.lock @@ -2913,7 +2913,7 @@ requires-dist = [ { name = "openadapt-flow", extras = ["vision"], marker = "extra == 'rdp'" }, { name = "openadapt-flow", extras = ["vision"], marker = "extra == 'windows'" }, { name = "openadapt-grounding", marker = "extra == 'grounding'", specifier = ">=0.1.0" }, - { name = "openadapt-privacy", extras = ["presidio"], marker = "extra == 'privacy'", specifier = ">=1.0.0" }, + { name = "openadapt-privacy", extras = ["presidio"], marker = "extra == 'privacy'", specifier = ">=1.1.4" }, { name = "openadapt-types", specifier = ">=0.24.0,<0.25.0" }, { name = "openai-agents", marker = "extra == 'openai-agents'", specifier = ">=0.24,<0.25" }, { name = "opencv-python", marker = "extra == 'dev'", specifier = ">=4.9,<5.1" }, @@ -2984,17 +2984,16 @@ wheels = [ [[package]] name = "openadapt-privacy" -version = "1.0.0" +version = "1.1.4" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "pillow", version = "12.3.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, { name = "pillow", version = "13.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, - { name = "pip" }, { name = "pydantic" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/80/65/fb6ea671d07984a99d7f3f147e162d16428454185e5f84c4d7dd3d12d84f/openadapt_privacy-1.0.0.tar.gz", hash = "sha256:6756fd0e4df68df98217f8d8fa0cd67e9b8879610bb0822209656965e19b3d7d", size = 53443, upload-time = "2026-07-15T21:53:51.812Z" } +sdist = { url = "https://files.pythonhosted.org/packages/3d/75/0af8ad76768856faa455f70b322b025e0cfaea113dab5ae4b814eed614f0/openadapt_privacy-1.1.4.tar.gz", hash = "sha256:585573fb4ce1b0e13f48e425b5c0bce4cbc204d378c145df9ec9647d594771d2", size = 320011, upload-time = "2026-11-21T14:38:38.108Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/4c/fd/7bf1e621f372bbd620b272d3c1504b01e6ad60959322115ea35e198a0f80/openadapt_privacy-1.0.0-py3-none-any.whl", hash = "sha256:52fdf09c48466cd02d336e1129ad17d4e528e7cf06a484ba00c1a2aed06ad818", size = 17085, upload-time = "2026-07-15T21:53:50.598Z" }, + { url = "https://files.pythonhosted.org/packages/cb/a9/92f355f1efdd35179e8be90b440002be56cde7904eab4cbbdb98ca50e1b9/openadapt_privacy-1.1.4-py3-none-any.whl", hash = "sha256:16b9e7b7c74d51257e7fbd334d3fa2ef1879df554613a20319676f0c9dc4b874", size = 33172, upload-time = "2026-11-21T14:38:36.913Z" }, ] [package.optional-dependencies] @@ -3404,15 +3403,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/c0/37/66b12dc476041fe523bca29c9d58fbf1ea92a4eaf73acfb9e993948f1191/pillow-13.0.0-pp312-pypy312_pp80-win_amd64.whl", hash = "sha256:567f20f1c75897d7663830da6ea8af719e03d712b1d9ee7f813319f9ece42e5a", size = 7366030, upload-time = "2026-10-16T22:18:06.638Z" }, ] -[[package]] -name = "pip" -version = "26.2" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/db/96/e6f8e9d9d7b9cc4457092712a7e919c3186aa2c2fa9ffed2c5d29cc947e8/pip-26.2.tar.gz", hash = "sha256:2d8542afcc84cdd8e846c2b36b2861fad1da376dd98f8e7113e9108a3c331690", size = 1848845, upload-time = "2026-07-29T21:57:56.407Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/62/36/a3aed958d60531cb442b7ab4596cda7b3621cfb916f8ae1d6769795c7dc1/pip-26.2-py3-none-any.whl", hash = "sha256:931c303696af6fa3417112103b1cad26890e5a07eccb5b99783700e33f2b8aad", size = 1816475, upload-time = "2026-07-29T21:57:54.763Z" }, -] - [[package]] name = "platformdirs" version = "4.14.0"