fix(gateway): redact session prompt params inside the owner scope
The registered password-manager values that redaction scrubs are kept per profile and looked up for the profile the current context is bound to. The session prompt hook dispatch redacted params before entering the owning authority's scope, so a prompt asked from a thread bound to another profile (or to none) handed the owning profile's plugins its own registered vault values unscrubbed. Enter the owner scope first, then redact, then invoke the hook. Without an owning authority the asker's copied context is used, as before.
This commit is contained in:
committed by
Mark S.
parent
5f95cdb2c1
commit
bbdcb79f7e
@@ -11,7 +11,8 @@ Observers only: return values are ignored and a failing plugin never affects the
|
||||
order on one worker thread, so plugin code never runs under ``event_stream.lock`` or
|
||||
``session_server_requests._lock``, on the agent thread or on the event loop; each runs in the owning
|
||||
profile's scope (``session_authorities.owner_scope``). ``params`` is a deep copy with every string
|
||||
force-redacted (as ``tools/human_input_hooks.py`` redacts its ``prompt``) and never holds an answer.
|
||||
force-redacted (as ``tools/human_input_hooks.py`` redacts its ``prompt``) inside that owner scope, so
|
||||
the owning profile's registered vault values are scrubbed too, and never holds an answer.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -137,13 +138,13 @@ def _drain() -> None:
|
||||
def _dispatch(hook_name, authority, payload) -> None:
|
||||
from hermes_cli.config_backend import ConfigBackendUnavailable
|
||||
try:
|
||||
if "params" in payload:
|
||||
payload = {**payload, "params": _redacted(payload["params"])}
|
||||
scope = contextlib.nullcontext()
|
||||
if authority is not None:
|
||||
from gateway.session_authorities import owner_scope
|
||||
scope = owner_scope(authority)
|
||||
with scope:
|
||||
if "params" in payload: # in the owner's scope: its registered vault values are scrubbed too
|
||||
payload = {**payload, "params": _redacted(payload["params"])}
|
||||
from hermes_cli.lifecycle import invoke_hook
|
||||
invoke_hook(hook_name, **payload)
|
||||
except (Exception, ConfigBackendUnavailable): # health: allow BLE001 -- observers never break a prompt
|
||||
|
||||
@@ -136,3 +136,32 @@ def test_without_a_gateway_api_a_request_frame_runs_in_the_askers_scope(profiles
|
||||
asker.join(10)
|
||||
beta.plugin.wait(SETTLED)
|
||||
assert profiles.alpha.plugin.calls == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("asked_from", ["unbound", "other profile"])
|
||||
def test_params_are_scrubbed_of_the_owning_profiles_vault_values(profiles, monkeypatch, asked_from):
|
||||
"""A password-manager value registered for the owning profile only never reaches its plugins, even
|
||||
when the prompt is asked from a thread bound to another profile or to none."""
|
||||
from agent.redact import clear_vault_redaction_values, redact_approval_display, register_vault_redaction_value
|
||||
from gateway import run_api
|
||||
from gateway.session_server_requests import ask_viewer, resolve
|
||||
monkeypatch.setattr(run_api, "_ACTIVE_RUNNER", profiles.runner) # the gateway API is up
|
||||
beta, secret = profiles.beta, "orchard violet river lantern"
|
||||
home = None if asked_from == "unbound" else profiles.alpha.home
|
||||
_in_scope(beta.home, lambda: register_vault_redaction_value(secret))
|
||||
try:
|
||||
assert secret in _in_scope(home, lambda: redact_approval_display(secret, force=True)) # not the asker's value
|
||||
beta.live.event_stream.fanout.attach(_Peer())
|
||||
params = {"site": "example", "note": f"save {secret}?", "fields": [{"value": secret}]}
|
||||
out = {}
|
||||
asker = threading.Thread(target=lambda: out.setdefault("value", _in_scope(
|
||||
home, lambda: ask_viewer(beta.live.event_stream, "s", "vault.save_login", params))))
|
||||
asker.start()
|
||||
[opened] = beta.plugin.wait(OPENED)
|
||||
assert opened["home"] == beta.home and opened["params"]["site"] == "example"
|
||||
assert secret not in repr(opened["params"])
|
||||
assert resolve({"jsonrpc": "2.0", "id": opened["prompt_id"], "result": {"value": "yes"}})
|
||||
asker.join(10)
|
||||
assert out["value"] == "yes"
|
||||
finally:
|
||||
_in_scope(beta.home, clear_vault_redaction_values)
|
||||
|
||||
Reference in New Issue
Block a user