Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

Each anonymous /live viewer gets a stable guest name from src/guest-names.ts, keyed by an HttpOnly browser-id cookie - lobby and test only #411

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

Each anonymous /live viewer now gets a guest name that stays the same for their browser, and the socket is told it once as {type:'you', guest:{name, colour}}. I couldn't run the type check here, because bun install and bun x tsc fail with a read-only tempdir error. The forge's check will be the first type check.

Notes

shipped merged

opened this

Each anonymous /live viewer now gets a guest name that stays the same for their browser, and the socket is told it once as {type:'you', guest:{name, colour}}. I couldn't run the type check here, because bun install and bun x tsc fail with a read-only tempdir error. The forge's check will be the first type check.

  • Cookie: the page GET (GET / and /index.html in src/server.ts) sets arm_browser, 128 random bits in hex, as HttpOnly; Secure; SameSite=Lax. It does this only when the request has no well-formed one. The new src/browser-id.ts holds the cookie logic.
  • Names: src/lobby.ts reads the cookie on the /live upgrade and picks a name with nameFor(id, inUse). Several tabs from one browser share one name, and the name is freed when that browser's last socket closes.
  • Absent or malformed cookie: the socket gets a random id of its own, so it gets its own name.
  • Tests: src/lobby.test.ts covers different cookies getting different names, the same cookie keeping its name after a reconnect and across a second tab, and a malformed cookie being treated as absent. src/server.test.ts covers the cookie being set only when absent.
  • Test run: I ran src/lobby.test.ts, src/server.test.ts and src/guest-names.test.ts: 107 pass, 1 fails. The failure is the "serves the model, its meshes and the vendored libraries" test, which fails the same way without my changes. I did not run the rest of bun --cwd Software/so101 test. forge.json is untouched.

Closes #396

1 earlier comment · 1 event
commented

Each anonymous /live viewer now gets a guest name that stays the same for their browser, and the socket is told it once as {type:'you', guest:{name, colour}}. I couldn't run the type check here, because bun install and bun x tsc fail with a read-only tempdir error. The forge's check will be the first type check.

  • Cookie: the page GET (GET / and /index.html in src/server.ts) sets arm_browser, 128 random bits in hex, as HttpOnly; Secure; SameSite=Lax. It does this only when the request has no well-formed one. The new src/browser-id.ts holds the cookie logic.
  • Names: src/lobby.ts reads the cookie on the /live upgrade and picks a name with nameFor(id, inUse). Several tabs from one browser share one name, and the name is freed when that browser's last socket closes.
  • Absent or malformed cookie: the socket gets a random id of its own, so it gets its own name.
  • Tests: src/lobby.test.ts covers different cookies getting different names, the same cookie keeping its name after a reconnect and across a second tab, and a malformed cookie being treated as absent. src/server.test.ts covers the cookie being set only when absent.
  • Test run: I ran src/lobby.test.ts, src/server.test.ts and src/guest-names.test.ts: 107 pass, 1 fails. The failure is the "serves the model, its meshes and the vendored libraries" test, which fails the same way without my changes. I did not run the rest of bun --cwd Software/so101 test. forge.json is untouched.
Changes requested — before the latest push

Logic and tests look sound (cookie only names a guest, never grants identity; malformed ids are ignored; names freed on last close). Two things to fix, first one first:

  1. The preview does not show it working. GET / on https://arm--411--forge-trevato-apps.open-platform.sh/ returns 200 with no Set-Cookie header. forge.json runs bench/fake-serve.ts, so the preview never goes through the changed GET / handler. Make the preview door set arm_browser (route the fake server's page through the same setBrowserId/browserCookie path) so it can be checked with curl -i.
  2. In lobby.ts the new guests field and its comment were inserted between the lastPosted doc comment and lastPosted, which orphans that comment. Move the new lines above it.

Also: the author could not run the type check; please make sure the forge check is green (the guest! non-null assertion on guests.get could be avoided by having claim return the name only).

commented

Both review points are fixed and pushed. I couldn't run the type check here because bun x tsc fails on a read-only tempdir, so the forge check will be its first run. I didn't re-check the preview after the push. curl -i on GET / there should now show Set-Cookie: arm_browser=….

  • No cookie on the preview: the preview runs bench/fake-serve.ts, which serves the page through the relay's page() in src/relay.ts. That is not the GET / handler in src/server.ts that I had changed. The relay now calls browserCookie and sets arm_browser itself, before the gzip branch, so both the gzip and plain paths carry it. I removed the cookie code from src/server.ts, so that file and src/server.test.ts now match main, and the relay is the only place that sets it. The cookie test moved into src/lobby.test.ts. It fetches / through the relay and checks the cookie is set only when absent.
  • Orphaned comment: the guests field and its comment now sit above the lastPosted doc comment in src/lobby.ts, so each comment is back beside its own field.
  • Non-null assertion: the you frame now takes the name from seat.guest.name, so the ! is gone.

I ran src/lobby.test.ts, src/relay.test.ts and src/server.test.ts: 123 pass, 1 fails. The failure is "serves the model, its meshes and the vendored libraries", which also fails on a clean checkout without my changes.

Approved

Approved. The preview sets arm_browser (128 random bits, hex, HttpOnly; Secure; SameSite=Lax) on GET / and /index.html. The lobby reads it only on the /live upgrade, and only for sockets with no verified identity, so no signed identity is taken from it. A malformed or absent cookie gets a fresh random id, and the cookie is read by regex-validated shape. The name is held by a socket count and released on close. Tests cover distinct names, a stable name across reconnect and a second tab, the cookie set only when absent, and a malformed cookie. The change is lobby-only and adds no dependency. Two things I would do next: 1) set the cookie only when the response status is 200, so the 404 page does not mint ids; 2) add a short README line on the guest name and the cookie, and say whether the terminal door will get it.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs