Document M4 in AGENTS.md

This commit is contained in:
raucao committed 2026-11-13 16:38:26 +04:00
1 parent 36322259a0
commit 4617838d3c
1 file changed
+37 -6
+37 -6
View File
@@ -29,7 +29,8 @@ src/runtime.rs tokio runtime + the bridge back to the GTK main loop
src/state.rs the key store, once connected, and change notifications
src/signer/mod.rs the NIP-46 responder
src/signer/approval.rs asking the user (timeout ⇒ deny)
src/store/apps.rs the registry of approved applications
src/signer/policy.rs the auto-approval rate limit
src/store/apps.rs the registry of approved applications + their permissions
src/store/keys.rs key storage (Secret Service, one item per key)
src/ui/approval.rs approval dialogs
src/ui/keys_view.rs the keys page
@@ -48,14 +49,28 @@ data/ desktop, metainfo, gschema, icons, resources (ui/*.blp, sty
- Methods: `connect` (verifies the pairing secret), `get_public_key`,
`get_relays`, `switch_relays`, `ping`, `sign_event`,
`nip04/nip44_encrypt|decrypt`.
- **M3 state:** pairing asks first. A client that is not in the registry gets no
answer to anything except `connect`, and approvals are remembered in
`apps.json`. **Requests from an approved client are still answered without
asking** — that is M4; the banner says so.
- **Approved ≠ silent (M4).** A client that is not in the registry gets no answer
to anything except `connect`; an approved client is remembered in `apps.json`
but **every sensitive request is still put to the user**: `sign_event`,
`nip04/nip44_encrypt` and `nip04/nip44_decrypt`. `get_public_key`,
`get_relays`, `switch_relays` and `ping` stay automatic.
- **Policy model.** A dialog answers Deny / Allow once / Allow always. "Always"
stores a `Permission` on the app in `apps.json`: for `sign_event` an allow-list
of **kinds**, for encryption a **method name**. A request covered by a stored
permission is answered without asking — subject to the rate limit below.
- **Decryption always asks.** It is a content oracle, so `Decrypt` never stores a
permission and the dialog offers only Deny / Allow once. Silently decrypting
is the exact flaw this project exists to replace; do not "optimise" it away.
- **Rate limit.** `signer::policy::RateLimiter` caps silent answers per app:
`auto-approve-limit` requests per minute (GSettings, default **30**). Past the
cap the request is asked again, so a runaway or compromised client turns back
into prompts instead of an open tap. Zero means never answer silently.
- Approvals go through `signer::approval::Approver`: the responder asks over a
channel, the dialog answers, and **a timeout or a missing UI denies** — never
allows. Client names/URLs shown in the dialog are client-supplied and must be
treated as display hints only.
- **The policy check and the prompt live on the responder side**, next to the
request, but the registry lock is **never held across an `await`**.
- Relays come from GSettings (`relays`); `REGENT_RELAYS` (comma separated)
overrides them, which is what headless tests use. The default is
`wss://nostr.kosmos.org` because **many public relays reject or rate-limit
@@ -112,6 +127,11 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
- All GTK calls happen on the main context. Anything arriving from a tokio task
(relay, signer) must be marshalled with `glib::MainContext::invoke`.
- Approval prompts must **time out to Deny**, never to allow.
- Event content and client-supplied metadata are attacker-controlled text. Show
them only as **plain, selectable labels** (`use_markup(false)`), never as Pango
markup — a client must not be able to forge formatting that looks like Regent's
own UI. The approval dialog deliberately has **no default response**, so Enter
cannot approve; Escape (and the timeout) deny.
## Verified API traps (do not rediscover these)
@@ -128,6 +148,9 @@ UI lives in `data/resources/ui/*.blp` (Blueprint) and is compiled to `.ui` by
(`is_bunker()`, `relays()`, `secret()`) — use it.
6. Requests arrive NIP‑44 encrypted; fall back to NIP‑04 for legacy clients.
Respond NIP‑44.
7. `AdwAlertDialog`'s `heading` and `body` default to **Pango markup**
(`heading-use-markup`/`body-use-markup` are `true`). Set both to `false`, and
put untrusted text in an `extra-child` of plain, selectable labels.
## Blueprint / Meson traps
@@ -166,8 +189,16 @@ the UI is tested. `build-aux/deploy-dev.sh` runs on the build host,
exposes the two subscription traps above:
```sh
CARGO_TARGET_DIR=_build/cargo-target REGENT_TEST_RELAY=wss://nostr.kosmos.org \
cargo test --release -- --ignored --nocapture nak_can_pair_and_sign
cargo test --release -- --ignored --nocapture nak
```
The `nak_*` tests cover the M4 approval paths end to end: the prompt carries the
kind and content, a denial reaches the client, and "allow always" short-circuits
the next identical request. Each test spins up its own `nak serve` on its own
port — sharing one port makes the parallel run hang.
- The policy logic itself is also covered by fast, relay-free tests that drive
`handle_request` with a client key they control (denial, allow-always per kind,
encryption remembered vs. decryption always asking, the rate limit, and a
dropped question denying). They run on a plain `cargo test`.
- End to end (keyring → responder → app), in a throwaway HOME:
```sh
dbus-run-session -- build-aux/acceptance.sh