Commit ac2e749
committed
agent-loop: encrypt tool_calls.function.{name,arguments} under E2EE
PR #144 follow-up: Pierre flagged that with E2EE active but without
X-Encrypt-All-Fields, the model-generated search query was still
leaking plaintext via the upstream tool_calls[].function.arguments
chunks. Same privacy class as the user's E2EE-decrypted prompt — must
not be on the wire in the clear.
Fix: in routes/chat.rs's agent-loop branch, force
`encrypt_all_fields = true` on the EncryptionContext used to build the
loop's chunk_transform. This only affects the agent-loop path — the
regular chat path below still honors the client's X-Encrypt-All-Fields
choice, so existing E2EE clients are unaffected.
Why not require X-Encrypt-All-Fields instead: this path is opt-in via
the namespaced tool type; clients that opt into it don't need to
remember a separate header to get the full privacy guarantee.
Test: extended e2ee_without_encrypt_all_fields_encrypts_tool_result to
also assert tool_calls[0].function.arguments (the model-generated query)
and tool_calls[0].function.name are ciphertext on the wire and decrypt
back to {"query":"rust"} and "web_context_search" respectively. The
synthetic nearai_tool_result envelope legitimately keeps `name` as
plaintext metadata identifying which server-side tool ran; only the
envelope's `output` is sensitive and that remains encrypted.1 parent 619cfed commit ac2e749
2 files changed
Lines changed: 77 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
80 | 88 | | |
81 | 89 | | |
82 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
943 | | - | |
| 943 | + | |
| 944 | + | |
944 | 945 | | |
945 | 946 | | |
946 | 947 | | |
| |||
952 | 953 | | |
953 | 954 | | |
954 | 955 | | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | 956 | | |
959 | 957 | | |
960 | 958 | | |
961 | 959 | | |
962 | | - | |
963 | | - | |
| 960 | + | |
964 | 961 | | |
965 | | - | |
966 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
967 | 1024 | | |
0 commit comments