Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/docs/social.md # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 3 Owner: ForgeSocial. Code: `social/*.om` (names `so*`, globals `gs*`, texts `ts*`). Test: `social/tests/run.sh`. 4 5 ## Sign-in with a Radicle key 6 7 There are no passwords. A user signs in by signing a server challenge with the `ed25519` key behind their `did:key`. 8 9 1. `GET login` shows a challenge `interplane-forge-login::` (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:::
`), so the form is

12 bound to this browser and cannot be replayed from another.

13 2. The user signs the challenge:

14

15 ```

16 printf '%s' 'interplane-forge-login::' > 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.

23 3. The user pastes the DID and `challenge.txt.sig` into the form. `POST 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 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.

32 4. 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  -I forge-user -n interplane-forge

34 -s ` as an argv exec (no shell), challenge on stdin, 5 s timeout, temp files in `/tmp/` removed after.

35 5. 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 `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

45 Display names: `[a-z0-9-]{1,39}`, no leading or trailing `-`, not a reserved route word, not taken (409).

46 The forge owner (`drakestapleton`, the node NID) keeps its name and cannot be renamed. Profiles live at

47 `` or ``, and show the DID.

48

49 Every form after sign-in carries `csrf` = the first 32 hex of HMAC(server key, `csrf:` + sha256(token)),

50 compared in constant time. `POST logout` writes a `logout` event and clears the cookie.

51

52 ### Email magic link (designed, DISABLED)

53

54 Sending stays off until Manager approves a mail path. The design:

55

56 - `POST 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 `login/email/` 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

68 All 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 | `/star`, `/unstar` | count on the repo bar, `/stargazers`, the user's Starred list `stars` |

74 | favorite / unfavorite | `/fav`, `/unfav` | private: only the user, at `stars?tab=favorites` |

75 | watch / unwatch | `/watch`, `/unwatch` | `/watchers` |

76 | follow / unfollow | `follow`, `unfollow` (field `user`) | `?tab=followers`, `?tab=following`, also `/followers`, `/following` |

77

78 Write gate (`sowpre`), in order: not signed in → 303 to `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.

80 Following yourself is 400. Counts start at 0; nothing is seeded.

81

82 ## The log

83

84 `/social.log` (default `~/forge-data/`, override with `FORGE_SOCIAL_DIR=/abs/dir/`) is the only source of

85 truth. 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

91 Actions: star unstar fav unfav watch unwatch follow unfollow account name session logout. `prev` is the hex

92 sha256 of the previous line's bytes (without its newline); line 1 has 64 zeros. Events are written only when

93 state changes. `social.head` holds ` ` and is replaced by rename after each append.

94 `social.key` holds the 32-byte HMAC key (mode 600).

95

96 At start and on every reload (SIGHUP, a RIDS.md change, or the `reload` flag file) `soload` resets memory and

97 replays 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

99 503, pages still render with no social bar. Nothing is appended to a log that failed to verify.

100 A head that lags the log by exactly one line (a crash between the append and the rename) is accepted.

101

102 Threat model: the chain detects accidental damage and naive edits. It is not keyed, so someone who can write

103 the 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,

108 and drives the server with curl (build and helpers: `social/tests/lib.sh`). The test copy's units come from the

109 build 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

111 first and fails the build when lib.sh types a unit list or when an order change in run.sh would not reach the

112 test copy. `STORE_VARIANT=1` exports `FORGE_STORE` (default `~/interplane-store-owner`, read only), so the same

113 two commands list the store-reading source in place of the Radicle one; every other unit is the same.

114 Last run, with its counts: `social/tests/last-run.txt`. It covers the full sign-in, the `__Host-`

115 cookies (Path=/, no Domain) under both bases

116 with a session working under `/forge/`, star 1 / unstar 0 / double star 1, favorites, watchers, follows,

117 restart and in-process reload, an independent Python check of the chain, and the negatives: forged

118 signature, a challenge spent by one failed attempt, malformed signature, tampered form MAC, missing pre

119 cookie, replayed nonce, the old cookie name, missing or wrong CSRF, unsigned writes, reserved and taken

120 names, 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`

123 values inside one minute, then a legitimate sign-in from a 7th IP must get 303. With `SOCIAL_SRC=` it runs

124 against other `social/*.om`; the old code (60 checks per minute site-wide, challenge kept on failure) fails

125 it with 429. Both runs: `social/tests/lockout-last-run.txt`.