interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / docs / social.md

125 lines · 8889 bytes Raw Blame History Rendered
1# Forge social: accounts, stars, favorites, watching, follows
2
3Owner: ForgeSocial. Code: `social/*.om` (names `so*`, globals `gs*`, texts `ts*`). Test: `social/tests/run.sh`.
4
5## Sign-in with a Radicle key
6
7There are no passwords. A user signs in by signing a server challenge with the ed25519 key behind their `did:key`.
8
91. `GET <base>login` shows a challenge `interplane-forge-login:<nonce>:<ts>` (nonce: 128 random bits) and sets
10 `__Host-forge_pre=<32 hex>` (Max-Age 900, HttpOnly, Secure, SameSite=Lax, Path=/, no Domain). The form carries
11 hidden `nonce`, `ts` and `csrf` = hex HMAC-SHA256(server key, `login:<nonce>:<ts>:<pre cookie>`), so the form is
12 bound to this browser and cannot be replayed from another.
132. The user signs the challenge:
14
15 ```
16 printf '%s' 'interplane-forge-login:<nonce>:<ts>' > challenge.txt
17 ssh-keygen -Y sign -f ~/.radicle/keys/radicle -n interplane-forge challenge.txt
18 ```
19
20 With the key in ssh-agent instead (`rad auth` adds it), use the public key file:
21 `ssh-keygen -Y sign -f ~/.radicle/keys/radicle.pub -n interplane-forge challenge.txt`.
22 `rad self --did` prints the DID.
233. The user pastes the DID and `challenge.txt.sig` into the form. `POST <base>login` checks, in order:
24 per-IP limit (10 attempts per minute, 429), form MAC and the pre cookie (403), `ts` within 15 minutes and the
25 nonce not spent (403), DID shape (400), the per-(DID, IP) limit (5 signature checks per minute, 429), the
26 site-wide backstop (600 signature checks per minute, 429), then the signature. The first signature check
27 spends the challenge, pass or fail: a retry needs a fresh `GET <base>login`. Spent nonces sit in an
28 in-memory ring of 16384 (more than 600 × 16 minutes, so none is overwritten while its challenge is live);
29 a successful one is also in the log. The limiter tables are keyed with the server key and never evict a
30 live count (8 probes, then refuse), so a client cannot reset someone else's count. Residual risk: an
31 attacker with about 60 or more source IPs can still reach the 600-per-minute backstop.
324. The DID `did:key:z6Mk…` is base58-decoded to multicodec `0xed01` + 32-byte key and written as an
33 allowed-signers line. The server runs `/usr/bin/ssh-keygen -Y verify -f <a> -I forge-user -n interplane-forge
34 -s <s>` as an argv exec (no shell), challenge on stdin, 5 s timeout, temp files in `<data>/tmp/` removed after.
355. On success: an `account` event (first time), a `session` event, and the cookie
36 `__Host-forge_session=<64 hex>` (256 random bits), Max-Age 2592000 (30 days), HttpOnly, Secure,
37 SameSite=Lax, Path=/, no Domain. The log stores only sha256(token) and the nonce, so the nonce stays spent
38 after a restart. A first sign-in goes to `<base>settings` to choose a display name.
39
40 Both cookies use the `__Host-` prefix, so the browser refuses them from a subdomain, over http, or with a
41 Domain or another Path. Path=/ covers `/forge/` on www.aienos.com. Tradeoff: on that shared origin the
42 cookie also reaches the other apps on www.aienos.com; giving the forge its own host would remove that.
43 Sessions issued under the old name `forge_session` no longer count: those users sign in again.
44
45Display names: `[a-z0-9-]{1,39}`, no leading or trailing `-`, not a reserved route word, not taken (409).
46The forge owner (`drakestapleton`, the node NID) keeps its name and cannot be renamed. Profiles live at
47`<base><name>` or `<base><z6Mk… key>`, and show the DID.
48
49Every form after sign-in carries `csrf` = the first 32 hex of HMAC(server key, `csrf:` + sha256(token)),
50compared in constant time. `POST <base>logout` writes a `logout` event and clears the cookie.
51
52### Email magic link (designed, DISABLED)
53
54Sending stays off until Manager approves a mail path. The design:
55
56- `POST <base>login/email` with an address (at most 254 bytes, one `@`, no spaces) and the CSRF form MAC.
57 Limits: 3 per address per hour, 10 per IP per hour; the reply is the same page whether or not the address
58 is known (no account enumeration).
59- The link is `<base>login/email/<token>` with 256 random bits; the log stores only sha256(token), the
60 sha256 of the lowercased address, and an expiry 15 minutes ahead. Single use: an `email-used` event spends it.
61- Opening the link shows a confirm button (POST), so mail scanners that prefetch GET do not sign the user in.
62- An address only signs in to an account it was linked to while signed in with a Radicle key
63 (`email-link` event after a confirmed link). Email alone never creates an account, and the DID stays the identity.
64- None of this is compiled in today: there is no route, no event code, and no mailer.
65
66## Social actions
67
68All are `POST`, answered with `303` back to the page (`back` must be a local path starting with one `/`;
69`//host` is refused). All are idempotent: a second star is a no-op and writes nothing.
70
71| action | route | visible |
72|---|---|---|
73| star / unstar | `<repo>/star`, `<repo>/unstar` | count on the repo bar, `<repo>/stargazers`, the user's Starred list `<base>stars` |
74| favorite / unfavorite | `<repo>/fav`, `<repo>/unfav` | private: only the user, at `<base>stars?tab=favorites` |
75| watch / unwatch | `<repo>/watch`, `<repo>/unwatch` | `<repo>/watchers` |
76| follow / unfollow | `<base>follow`, `<base>unfollow` (field `user`) | `<user>?tab=followers`, `<user>?tab=following`, also `<user>/followers`, `<user>/following` |
77
78Write gate (`sowpre`), in order: not signed in → 303 to `<base>login`; wrong or missing CSRF → 403; store off
79→ 503; per-IP limit (server `fratelim`, 30 per minute) or per-DID limit (30 per minute) → 429.
80Following yourself is 400. Counts start at 0; nothing is seeded.
81
82## The log
83
84`<data>/social.log` (default `~/forge-data/`, override with `FORGE_SOCIAL_DIR=/abs/dir/`) is the only source of
85truth. One JSON object per line:
86
87```
88{"seq":N,"ts":S,"did":"did:key:z…","action":"star","target":"z…rid","prev":"<64 hex>"}
89```
90
91Actions: star unstar fav unfav watch unwatch follow unfollow account name session logout. `prev` is the hex
92sha256 of the previous line's bytes (without its newline); line 1 has 64 zeros. Events are written only when
93state changes. `social.head` holds `<seq> <sha256 of line seq>` and is replaced by rename after each append.
94`social.key` holds the 32-byte HMAC key (mode 600).
95
96At start and on every reload (SIGHUP, a RIDS.md change, or the `reload` flag file) `soload` resets memory and
97replays the log with a strict parser. A changed, reordered or unparsable line, or a log that no longer matches
98`social.head` (truncation), logs `SOCIAL-LOG TAMPER …` on stderr and switches social off: writes 503, sign-in
99503, pages still render with no social bar. Nothing is appended to a log that failed to verify.
100A head that lags the log by exactly one line (a crash between the append and the rename) is accepted.
101
102Threat model: the chain detects accidental damage and naive edits. It is not keyed, so someone who can write
103the data dir can rewrite the whole chain and head. The data dir is the trust boundary (mode 700, owner only).
104
105## Evidence
106
107`social/tests/run.sh` builds a test copy (data dir under a temp dir, port 18489), creates throwaway ed25519 keys,
108and drives the server with curl (build and helpers: `social/tests/lib.sh`). The test copy's units come from the
109build itself: `./run.sh seams` lists them in the build's order with every slice as its seam, and
110`social/tests/units.sh` puts `social/*.om` in place of `server/nosocial.om`; `social/tests/units-check.sh` runs
111first and fails the build when lib.sh types a unit list or when an order change in run.sh would not reach the
112test copy. `STORE_VARIANT=1` exports `FORGE_STORE` (default `~/interplane-store-owner`, read only), so the same
113two commands list the store-reading source in place of the Radicle one; every other unit is the same.
114Last run, with its counts: `social/tests/last-run.txt`. It covers the full sign-in, the `__Host-`
115cookies (Path=/, no Domain) under both bases
116with a session working under `/forge/`, star 1 / unstar 0 / double star 1, favorites, watchers, follows,
117restart and in-process reload, an independent Python check of the chain, and the negatives: forged
118signature, a challenge spent by one failed attempt, malformed signature, tampered form MAC, missing pre
119cookie, replayed nonce, the old cookie name, missing or wrong CSRF, unsigned writes, reserved and taken
120names, self-follow, open redirect, tampered line, truncated log, write and sign-in floods.
121
122`social/tests/lockout.sh` is the sign-in lockout test: 61 wrong-key sign-ins for one DID from 6 `X-Real-IP`
123values inside one minute, then a legitimate sign-in from a 7th IP must get 303. With `SOCIAL_SRC=<dir>` it runs
124against other `social/*.om`; the old code (60 checks per minute site-wide, challenge kept on failure) fails
125it with 429. Both runs: `social/tests/lockout-last-run.txt`.