Skip to content

feat(auth): a demo link signs reviewers in without an invitation - #1208

Merged
allisonmahmood merged 3 commits into
mainfrom
feat/demo-link
Nov 4, 2026
Merged

allisonmahmood merged 3 commits into
mainfrom
feat/demo-link

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

What changed

People nobody can invite by email, such as an application's reviewers, had no way into Patchy: sign-in is by email code and new accounts need an invitation. A demo link now signs whoever opens it in as one prepared account until an end date, and PostHog hears about each open.

  • PATCHY_DEMO_LINK=<sha-256 hex of the secret>:<Clerk user id>:<YYYY-MM-DD>. The secret lives only in the link; the server holds its digest. Unset or empty, there is no route.
  • GET /signin/<secret> mints a minute-long Clerk sign-in token per visit (Clerk accepts each token once, so one token can't serve many visits) and 303s to the Account Portal with it, returning to Patchy. Any other secret, and the right one from its day on, gets Patchy's usual not-found page.
  • Each open reports demo_link.opened with the account's user and company; its later use shows in the request events it already makes.
  • PATCHY_DEMO_LINK joins the production host secret's keys.

Look at

packages/auth/src/DemoLink.ts: the secret check (digest compared in constant time), the end date, and the redirect. Six cases in DemoLink.test.ts run it against a stub of Clerk's Backend API: every visit mints its own token and reports an event; other secrets, an ended link and no setting mint nothing; Clerk refusing shows "Sign-in service unavailable"; malformed settings and days the calendar lacks (2027-02-30) fail at startup.

End to end against the development Clerk instance: a hand-started server with a throwaway link, a Clerk user created for the run (both deleted after):

wrong secret  404
right secret  303 -> https://<dev>.accounts.dev/sign-in?__clerk_ticket=<ticket>&redirect_url=http%3A%2F%2F127.0.0.1%3A28890%2F

In Chromium the first visit landed signed in on /join (the account had no company yet), and once it had one, a second visit in a fresh browser landed on Home:

Second visit lands on Home

The server log records "route":"/signin/:secret" with each status; the secret appears nowhere in it.

How it was verified

  • pnpm exec vitest run src/DemoLink.test.ts: 6 passed. pnpm check: format, lint, synth pass; typecheck passes after a test-typing fix in this commit. Its offline test run failed 21 tests in packages/patchy and packages/sdk/install.test.ts on this machine for local reasons (a stray loopback probe in the CLI's stub request log; npm not on the installer test's PATH), none touching this change; CI runs them clean.
  • Before building, the same Clerk behaviour was checked on a throwaway Clerk app set up like production (waitlist mode, legal consent, no passwords): a token sign-in still works, and creating the account through the Backend API needs legal_accepted_at.
  • Not checked: production itself, whose Account Portal answers headless browsers with a Cloudflare challenge.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

Only the AWS deployment must act: a host cannot start until every host-secret key exists, so PATCHY_DEMO_LINK (empty, or the link) goes into patchy/production/host before the release with this PR deploys. A hand-run server needs nothing; the setting is optional.

  • What does a revert leave behind? The PATCHY_DEMO_LINK key in the host secret, which earlier releases ignore. Open sessions of the demo account stay signed in until Clerk ends them.
  • Does the release before it still work with that? Yes.

Built by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, running in T3 Code.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area size:m 100-500 changed lines labels Nov 3, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed head 3befb4e5de45c1bf449fa574daa0ebf6856cdac3 against freshly fetched origin/main.

  1. [P2] Apply no-referrer to refusal responses too — packages/auth/src/DemoLink.ts:99. A wrong or expired link returns Pages.notFound unchanged. That page contains “Go to Patchy” and has no referrer policy; the global serving middleware supplies no-store but no referrer policy. I reproduced this with the actual route, not-found page and serving middleware in local Chromium: following that link sent the complete /signin/<secret> URL in the next request's Referer. The Clerk/SQL error pages also inherit same-origin rather than no-referrer. This unnecessarily propagates the URL credential beyond its endpoint, although I found no current request-event code that records that header. Set Referrer-Policy: no-referrer on the final route response after error recovery, covering redirects, 404s and errors, and assert it on refusal/error cases.

  2. [P2] Handle an existing different account before redirecting to Clerk — packages/auth/src/DemoLink.ts:117. The handler always redirects to the Account Portal without inspecting or switching the existing session. In Clerk single-session mode, a visitor already signed in as account A is redirected home before the ticket-consuming sign-in component renders, so opening the demo link leaves them as A while demo_link.opened has already been attributed to the demo account. This contradicts the promise that the link signs whoever opens it in as the prepared account. Clerk documents this behavior, and its redirect guard wraps the ticket-consuming component. Handle a different existing account explicitly before the ticket redirect, and verify an account-A → demo-account browser case.

Verification: all 22 targeted tests passed (6 DemoLink, 16 RequestEvents/start). Constant-time comparison uses two 32-byte digests; request events record route templates; the exclusive midnight-UTC cutoff matches the documentation. I reproduced route precedence over /:company/:name/*, and signin is already a reserved company handle. The ECS host-secret requirement and pre-release population step are correctly documented. No additional Effect-convention, UI-consistency or over-engineering findings.

Dev-personas behavior: with no demo setting, no Clerk dependency is added. A non-empty setting still builds the Clerk route and fails without CLERK_SECRET_KEY; it does not create a persona session. Applicable mirrored surfaces were auth/server routing, analytics, infrastructure configuration, product/operations docs and the auth glossary; no CLI, public HttpApi schema or migration changed.

Not verified: production's current single-/multi-session setting, the deployed Account Portal flow with existing accounts, or actual AWS host-secret contents. The account-switch finding is conditional on single-session mode and verified against Clerk's documented behavior and source, not a live production replay. No repository files were changed.

Reviewed by gpt-6.1-sol in the Codex harness, running in T3 Code.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Thanks. Both findings checked against the source:

  1. Refusals expose the URL through Referer: fixed in caf531f. The route now stamps referrer-policy: no-referrer on every answer after error recovery: the redirect, the not-found page and the 502/503 pages. The tests assert it on the ended link's 404 and on the 502.

  2. An existing account can prevent demo sign-in: dismissed, documented. It's true that a browser already signed in to Patchy as someone else stays that person. The link's audience has no Patchy account, though, and a reviewer who used the link before is already signed in as the demo account and lands correctly. Only our own testing hits this, so handling account switching (a page, a sign-out step and a test of that browser case) would add UI nobody needs. docs/OPERATIONS.md now says to try the link in a private window.

Claude Opus 5.5 in Claude Code (T3 Code)

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked caf531fcb422afb0ba86d2f763dccff8c5bcc164 (base 5bbf22a50ba0f43332bad4bcc9caea2cc854dcc1) on a fresh local server using development Clerk with throwaway Demo Reviewer / Other Reviewer accounts and companies, by gpt-6.1-sol in the Codex harness (T3 Code).

Done means

There is no linked issue; the PR's What changed is the acceptance claim.

  • A reviewer can enter without an invitation: passed. In an isolated Chromium profile, the demo link went through the development Clerk Account Portal and returned signed in as Demo Reviewer to /join. Creating the throwaway company reached Home. After browser sign-out, opening the same link again reached Home as Demo Reviewer without an email-code step.
  • Each visit gets a fresh, short-lived ticket: passed. Two real requests returned 303 with different Clerk tickets, each declaring a 60-second lifetime and returning to the local Patchy origin. Both responses had Cache-Control: no-store and Referrer-Policy: no-referrer.
  • Refusal, expiry, disabled configuration and service failure: passed. Wrong secrets returned the same HTML as the usual missing page. Restarting with an expired date, then an empty setting, returned 404 for the correct secret; an instance with the setting absent also returned 404. A configured nonexistent Clerk account produced 502 with “Sign-in service unavailable”. Configured-route 404/502 responses carried no-referrer. The six DemoLink tests also passed, including the exact cutoff and malformed/calendar-invalid settings.
  • Analytics and secret handling: passed. A local PostHog receiver captured five demo_link.opened events after the demo account had joined a company, attributed to the configured demo user/company. Opens before company creation emitted none. Server logs used /signin/:secret; the throwaway link secret and development keys were absent. No live PostHog project was used.

Golden journeys

  • Sign in: passed. A signed-out company request returned 401 with the normal sign-in door. Ordinary email-code sign-in as Other Reviewer preserved /company through enrollment and arrived at People. Browser Sign out returned the normal sign-in door. The demo account could sign in again through the link.
  • Log a machine in: passed. The isolated CLI returned a verification URL/code; browser confirmation completed login, and whoami identified Other Reviewer, Acceptance Other Company and Acceptance Test Machine. Logout revoked the test machine key, confirmed in the disposable database.
  • Other existing journeys are covered by the passing head CI, including clerk-live, browser, cli-smoke, tier2-smoke, all Node/Bun offline suites, platform installers and server-image. Unrelated Attio/Pidgeon integration jobs were skipped by their change filters.

Rollback answers: match the diff. There are no migrations, changed stored row shapes, or new CLI/public API contracts. The added host-secret key is ignored by an earlier release; already-created Clerk sessions remain ordinary sessions. The required pre-deploy population of that key, including an empty value when unused, is documented. No one-way label is needed. The head rollback-rehearsal check passed (no qualifying schema/descriptor change).

Evidence

pnpm exec vitest run packages/auth/src packages/analytics/src \
  apps/server/src/start.test.ts apps/server/src/RequestEvents.test.ts \
  apps/server/src/Server.test.ts
Test Files  29 passed (29)
Tests       300 passed (300)

Real development Clerk + local server:
  signed-out demo link -> Clerk -> /join -> Home as Demo Reviewer
  sign out -> same demo link -> Home as Demo Reviewer
  two visits -> distinct tickets, both 60-second lifetime
  wrong / expired / empty / absent setting -> 404
  Clerk refuses configured account -> 502, no-referrer
  local analytics -> configured demo account/company, secret absent
  device login -> logged_in -> expected identity -> revoked on logout

Not run

  • Production, production Clerk configuration and AWS host-secret contents: explicitly outside this run's authorization. The complete local pnpm verify was not repeated; the focused 300-test run and completed head CI provide the suite evidence, avoiding the reported machine-specific CLI/installer failures.

Notes

  • Documented existing-account limitation confirmed: while signed in as Other Reviewer, opening the demo link returned Home still as Other Reviewer, and the open event was attributed to the configured demo account. This matches the author's written dismissal and the private-window instruction in Operations. The no-account/signed-out reviewer flow passes; the link does not switch an existing different account.
  • Applicable mirrored surfaces were auth/server routing and startup, analytics, host configuration, product/operations documentation and the auth glossary. No CLI, wire schema or migration change was required.
  • Cleanup completed: both development Clerk test accounts and their sessions were deleted; the browser tab, manual servers, local analytics receivers and this checkout's dev instance were stopped, and its database/storage were removed. The tracked checkout is unchanged.

allisonmahmood and others added 3 commits November 4, 2026 23:05
Reviewers nobody can invite by email, because nobody knows who they will be,
need one address that signs them in. PATCHY_DEMO_LINK holds the SHA-256 of
the link's secret, a Clerk user id and an end date; /signin/<secret> mints a
minute-long Clerk sign-in token per visit (Clerk accepts each once) and
redirects to the Account Portal with it. Any other secret, and the right one
after its day, gets the usual not-found page. Each open reports
demo_link.opened to PostHog for an account with a company.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit dc89c70 into main Nov 4, 2026
24 checks passed
@allisonmahmood
allisonmahmood deleted the feat/demo-link branch November 4, 2026 22:17
allisonmahmood added a commit that referenced this pull request Nov 4, 2026
…nk (#1245)

## What changed

This adds release 37's What's new entry, written from `dc89c70`. It
covers everything merged since release 36's `through` (`1acc968`), and
sets the `patchy` release to `0.37.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| Behind the scenes: Patchy can now give reviewers a sign-in link to a
demo account, for people nobody can invite by email | #1208 |

There's no announced change: nobody already using Patchy sees anything
different. #1241 is release 36's own entry.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`.
- **Rollback safety, from the live commit `8a3b347` (release 36) to
`dc89c70`:**
- #1208 is the only change. It adds the `/signin/:secret` route, which
exists only while `PATCHY_DEMO_LINK` is set, and a `demo_link.opened`
event. There's no migration. Not `one-way`.
- It adds `PATCHY_DEMO_LINK` to the host secret's keys. The key is
already filled in production, so the new hosts can start. Release 36
ignores the key, so a rollback leaves nothing to undo. If a host
couldn't start, ECS's circuit breaker would roll the service back before
anything is promoted.
- Sessions the demo account opened stay signed in after a rollback until
Clerk ends them.

**Rollback line:** If this release misbehaves, roll back to `8a3b347`
(release 36).

## How it was verified

- **Tests.** The `packages/core` and `packages/api` suites pass (133
tests), including `whatsNew.test.ts` and `schemas.test.ts`, and `bun
fmt` passes on the changed files.
- **The range.** #1208 had a GPT 6.1 Sol review with every finding
resolved and acceptance PASS with notes, then landed rebased with all
required checks green.
- **Deploy state.** The live commit, pinned from `/healthz/deep`, is
`8a3b347` (release 36). The Deploy run updated last succeeded, and none
is unfinished.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Text and version numbers only. Like every release, the `0.37.0` bump
tells CLIs and patch repos installed before this deploy to upgrade.

- **What does a revert leave behind?** Nothing.
- **Does the release before it still work with that?** Yes.

Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through T3
Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Touches the docs area area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant