Skip to content

feat: sign-in handoff page for private.nemar.org - #396

Merged
neuromechanist merged 15 commits into
stagingfrom
feature/private-site-authorize
Oct 2, 2026
Merged

neuromechanist merged 15 commits into
stagingfrom
feature/private-site-authorize

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Adds /auth/private/authorize, the middle hop of the sign-in handoff to private.nemar.org, NEMAR's site for access-controlled features. The private site sends a visitor without a session there to this page with a state it generated; the page proves the visitor is signed in, asks the backend for a one-time code bound to that state (POST /auth/private/grant, nemarOrg/nemar-cli#1577), and redirects to the private site's callback with the code.

What the page does

  • Validates state first (32 to 256 base64url characters); a missing or malformed value gets a 400 panel before anything else runs.
  • Answers GET only; any other method, HEAD included, gets 405 with Allow: GET before anything is read or minted.
  • Without a session, redirects to /login with a return address rebuilt from the validated state.
  • Forwards state unchanged in the grant body only, with the visitor's cookie and a pinned Origin, and never follows a redirect on that call; the callback URL carries the code alone, never the state (the private site keeps its own return path), and nothing logs the query string.
  • Maps the backend's answers: 401 back to sign-in, 403 to a not-verified panel (pending account, existing account copy) or a not-active panel (any other status), each with a link back to the private site, a redirect from the backend to the 503 panel, 400 to an invalid-request panel, 429 to a try-again-in-a-minute panel, anything else to a 503 panel.
  • Reads the target host from PRIVATE_SITE_BASE (an https origin on a nemar.org host, no credentials, normalized to its origin), defaulting to https://private.nemar.org only when the API is production; any other deployment without the setting refuses with 501 before minting a code.
  • Every response, redirects included, carries Cache-Control: no-store, Referrer-Policy: no-referrer and X-Robots-Tag: noindex; the middleware keeps a page-set no-referrer instead of overwriting it with the site-wide policy, whatever spelling of the path reached the page (ADR 0021).
  • No client script, and nothing on this site links to the page.
  • The docs handoff's grant call also stops following redirects.

Contract

test/private-site-contract-drift.test.ts compares the authorize path, the state parameter name and the callback path against nemar-cli's shared/contract/private-site.ts on dev, and checks the page file exists at the path the contract names; CI adds that file to its sparse checkout and runs the test in strict mode.

Staging

deploy-test.yml sets PRIVATE_SITE_BASE=https://private-test.nemar.org at build time; the value is inlined into the worker bundle, so wrangler.test.toml carries it for reference only.

Deploy order

The backend side (POST /auth/private/grant) is already on nemar-cli dev and deployed to the dev API; this page can ship to staging independently. The private site consumes this page later; until it exists nothing sends visitors here.

Testing

  • bun run test: 2767 passed, 3 skipped (drift test, no local contract); 2770/2770 with the nemar-cli dev contracts in strict mode
  • Drift test fails on a changed callback path and on a missing contract file in strict mode
  • bun run lint clean
  • bun run typecheck: 0 errors
  • bun run build succeeds; PRIVATE_SITE_BASE is inlined when set and absent when unset
  • Built worker checked locally with wrangler pages dev: all path spellings keep no-referrer, non-GET methods get 405, other routes keep the site-wide policy

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record. An independent review pass on e849236 (security first, all lenses; probes against the production build under wrangler pages dev and a fake backend) found no critical or important issues. Every finding is addressed in e97d087 through e78549b:

  • The middleware keeps a page-set no-referrer whatever spelling of the path reached the page (percent-encoded variants previously fell back to the site-wide policy); recorded as ADR 0021
  • The grant call never follows a redirect (a 3xx maps to the 503 panel); the docs handoff's grant call gets the same fix
  • The callback URL carries the code alone, matching the contract; the private site keeps its own return path
  • PRIVATE_SITE_BASE refuses credentials and is normalized to its origin
  • GET only; HEAD and every other method get 405 before anything is read or minted
  • Deadline and timeout tests for the grant call
  • Account panels link back to the private site; a comment records that production uses the in-code default

Kept by design: the state length bounds (32 to 256) are duplicated from the backend; the website's check is a pre-check and a disagreement fails closed at the backend's own validation.

neuromechanist added a commit that referenced this pull request Oct 1, 2026
Open PR #396 already adds ADR 0021. Also correct two claims the
review found overstated: the page reads approval_in_flight, and its
copy names GitHub Actions.
@neuromechanist
neuromechanist merged commit d402fcc into staging Oct 2, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/private-site-authorize branch October 2, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant