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 Source

Forge social: accounts, stars, favorites, watching, follows

Owner: ForgeSocial. Code: social/*.om (names so*, globals gs*, texts ts*). Test: social/tests/run.sh.

Sign-in with a Radicle key

There are no passwords. A user signs in by signing a server challenge with the ed25519 key behind their did:key.

  1. GET <base>login shows a challenge interplane-forge-login:<nonce>:<ts> (nonce: 128 random bits) and sets __Host-forge_pre=<32 hex> (Max-Age 900, HttpOnly, Secure, SameSite=Lax, Path=/, no Domain). The form carries hidden nonce, ts and csrf = hex HMAC-SHA256(server key, login:<nonce>:<ts>:<pre cookie>), so the form is bound to this browser and cannot be replayed from another.
  2. The user signs the challenge:
    printf '%s' 'interplane-forge-login:<nonce>:<ts>' > challenge.txt
    ssh-keygen -Y sign -f ~/.radicle/keys/radicle -n interplane-forge challenge.txt
    

    With the key in ssh-agent instead (rad auth adds it), use the public key file: ssh-keygen -Y sign -f ~/.radicle/keys/radicle.pub -n interplane-forge challenge.txt. rad self --did prints the DID.

  3. The user pastes the DID and challenge.txt.sig into the form. POST <base>login checks, in order: per-IP limit (10 attempts per minute, 429), form MAC and the pre cookie (403), ts within 15 minutes and the nonce not spent (403), DID shape (400), the per-(DID, IP) limit (5 signature checks per minute, 429), the site-wide backstop (600 signature checks per minute, 429), then the signature. The first signature check spends the challenge, pass or fail: a retry needs a fresh GET <base>login. Spent nonces sit in an in-memory ring of 16384 (more than 600 × 16 minutes, so none is overwritten while its challenge is live); a successful one is also in the log. The limiter tables are keyed with the server key and never evict a live count (8 probes, then refuse), so a client cannot reset someone else's count. Residual risk: an attacker with about 60 or more source IPs can still reach the 600-per-minute backstop.
  4. The DID did:key:z6Mk… is base58-decoded to multicodec 0xed01 + 32-byte key and written as an allowed-signers line. The server runs `/usr/bin/ssh-keygen -Y verify -f <a> -I forge-user -n interplane-forge -s <s>as an argv exec (no shell), challenge on stdin, 5 s timeout, temp files in<data>/tmp/` removed after.
  5. On success: an account event (first time), a session event, and the cookie __Host-forge_session=<64 hex> (256 random bits), Max-Age 2592000 (30 days), HttpOnly, Secure, SameSite=Lax, Path=/, no Domain. The log stores only sha256(token) and the nonce, so the nonce stays spent after a restart. A first sign-in goes to <base>settings to choose a display name.

    Both cookies use the __Host- prefix, so the browser refuses them from a subdomain, over http, or with a Domain or another Path. Path=/ covers /forge/ on www.aienos.com. Tradeoff: on that shared origin the cookie also reaches the other apps on www.aienos.com; giving the forge its own host would remove that. Sessions issued under the old name forge_session no longer count: those users sign in again.

Display names: [a-z0-9-]{1,39}, no leading or trailing -, not a reserved route word, not taken (409). The forge owner (drakestapleton, the node NID) keeps its name and cannot be renamed. Profiles live at <base><name> or <base><z6Mk… key>, and show the DID.

Every form after sign-in carries csrf = the first 32 hex of HMAC(server key, csrf: + sha256(token)), compared in constant time. POST <base>logout writes a logout event and clears the cookie.

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

Social actions

All are POST, answered with 303 back to the page (back must be a local path starting with one /; //host is refused). All are idempotent: a second star is a no-op and writes nothing.

actionroutevisible
star / unstar<repo>/star, <repo>/unstarcount on the repo bar, <repo>/stargazers, the user's Starred list <base>stars
favorite / unfavorite<repo>/fav, <repo>/unfavprivate: only the user, at <base>stars?tab=favorites
watch / unwatch<repo>/watch, <repo>/unwatch<repo>/watchers
follow / unfollow<base>follow, <base>unfollow (field user)<user>?tab=followers, <user>?tab=following, also <user>/followers, <user>/following

Write gate (sowpre), in order: not signed in → 303 to <base>login; wrong or missing CSRF → 403; store off → 503; per-IP limit (server fratelim, 30 per minute) or per-DID limit (30 per minute) → 429. Following yourself is 400. Counts start at 0; nothing is seeded.

The log

<data>/social.log (default ~/forge-data/, override with FORGE_SOCIAL_DIR=/abs/dir/) is the only source of truth. One JSON object per line:

{"seq":N,"ts":S,"did":"did:key:z…","action":"star","target":"z…rid","prev":"<64 hex>"}

Actions: star unstar fav unfav watch unwatch follow unfollow account name session logout. prev is the hex sha256 of the previous line's bytes (without its newline); line 1 has 64 zeros. Events are written only when state changes. social.head holds <seq> <sha256 of line seq> and is replaced by rename after each append. social.key holds the 32-byte HMAC key (mode 600).

At start and on every reload (SIGHUP, a RIDS.md change, or the reload flag file) soload resets memory and replays the log with a strict parser. A changed, reordered or unparsable line, or a log that no longer matches social.head (truncation), logs SOCIAL-LOG TAMPER … on stderr and switches social off: writes 503, sign-in 503, pages still render with no social bar. Nothing is appended to a log that failed to verify. A head that lags the log by exactly one line (a crash between the append and the rename) is accepted.

Threat model: the chain detects accidental damage and naive edits. It is not keyed, so someone who can write the data dir can rewrite the whole chain and head. The data dir is the trust boundary (mode 700, owner only).

Evidence

social/tests/run.sh builds a test copy (data dir under a temp dir, port 18489), creates throwaway ed25519 keys, and drives the server with curl (build and helpers: social/tests/lib.sh). The test copy's units come from the build itself: ./run.sh seams lists them in the build's order with every slice as its seam, and social/tests/units.sh puts social/*.om in place of server/nosocial.om; social/tests/units-check.sh runs first and fails the build when lib.sh types a unit list or when an order change in run.sh would not reach the test copy. STORE_VARIANT=1 exports FORGE_STORE (default ~/interplane-store-owner, read only), so the same two commands list the store-reading source in place of the Radicle one; every other unit is the same. Last run, with its counts: social/tests/last-run.txt. It covers the full sign-in, the __Host- cookies (Path=/, no Domain) under both bases with a session working under /forge/, star 1 / unstar 0 / double star 1, favorites, watchers, follows, restart and in-process reload, an independent Python check of the chain, and the negatives: forged signature, a challenge spent by one failed attempt, malformed signature, tampered form MAC, missing pre cookie, replayed nonce, the old cookie name, missing or wrong CSRF, unsigned writes, reserved and taken names, self-follow, open redirect, tampered line, truncated log, write and sign-in floods.

social/tests/lockout.sh is the sign-in lockout test: 61 wrong-key sign-ins for one DID from 6 X-Real-IP values inside one minute, then a legitimate sign-in from a 7th IP must get 303. With SOCIAL_SRC=<dir> it runs against other social/*.om; the old code (60 checks per minute site-wide, challenge kept on failure) fails it with 429. Both runs: social/tests/lockout-last-run.txt.