Skip to content

Phase B3: /oauth/authorize page - #501

Merged
neuromechanist merged 14 commits into
stagingfrom
feature/issue-2017-oauth-authorize-page
Nov 6, 2026
Merged

neuromechanist merged 14 commits into
stagingfrom
feature/issue-2017-oauth-authorize-page

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds /oauth/authorize, the authorization endpoint page of NEMAR's OpenID Connect provider (nemarOrg/nemar-cli#2017, nemar-cli ADR 0119). The page decides nothing: it forwards the authorization request and the person's Cookie header to the API's check route (POST /auth/oidc/authorize), and follows or renders the answer; the consent form posts back to the page, which forwards the person's answer to the consent route (POST /auth/oidc/consent). The API side is nemarOrg/nemar-cli#2036.

Base and merge order. This PR is no longer stacked: #499 merged into staging, and this branch was rebased onto staging, which is its base. It must not merge until the nemar-cli OIDC epic (nemarOrg/nemar-cli#2014) reaches nemar-cli dev, and its CI must be re-run on its head then, before it merges. Please do not merge it without the owner.

What changed

  • src/pages/oauth/authorize.astro: GET and POST, server-rendered, no client script, shaped like src/pages/auth/private/authorize.astro. Every response carries Cache-Control: no-store, X-Robots-Tag: noindex and X-Frame-Options: DENY; the consent screen carries Referrer-Policy: same-origin and every other response no-referrer. Any other method (HEAD included) is 405 before anything is read. A redirect answer is followed with 302 (303 after a POST); login and reauth go to /login?next=/oauth/authorize?<request> (with error=session_required for reauth); consent, rule_refused and the error codes render a panel with their status. The consent screen names the host either answer sends the person to. A comment notes that the API answers 404 until its HOST_PREFIXED_SESSION_COOKIE is on.
  • src/lib/oidc-authorize.ts: the pure view model: reading the request (a GET's query, a POST form read through a streaming size cap, or the page's own consent form), mapping each API answer to one outcome with every shape validated (an unusable location or origin is the unavailable panel, never a redirect; [::1] is accepted as a loopback origin), the sign-in return path, the copy for each panel, and the statuses. The closed list of redirect errors now includes unsupported_response_type.
  • src/lib/oidc-authorize-api.ts: the two calls, shaped like private-auth-api.ts: pinned Origin, forwarded Cookie, the fixed caller marker header the API requires, redirect: "manual", a deadline, never throws, logs no value.
  • src/pages/api/v1/[...path].ts and src/lib/proxy-path.ts: the general browser proxy answers 404 for any path that names the authorization routes once it is decoded and normalized, and it never forwards the caller marker, so an answer that carries a code or a consent token reaches only the page's server code. Since review round 2 the decision is made on the path the fetch would actually request (the upstream URL's resolved pathname), tabs and line breaks are dropped and \ is read as / before matching, as the URL parser does, and a capture holding a control character or a backslash is refused with 400 before any URL is built.
  • src/pages/settings.astro (review round 2): "Connect your ORCID" submits a form POST to /auth/orcid/start?mode=link instead of following a link, because the API now arms an ORCID link only from a POST that carries this site's Origin and a session (Phase B3: OIDC authorization and consent nemar-cli#2036, ADR 0119 rule 10); the button, its copy and where it leads are unchanged. src/pages/auth/orcid/start.ts and src/lib/orcid-proxy.ts comments say so. With the API's HOST_PREFIXED_SESSION_COOKIE off (production today) this is a partial fix: a link can no longer be armed by a cross-site navigation, but a legacy session cookie set from a sibling host can still stand in for the person's own session until the production flag is on, which is what closes it.
  • src/middleware.ts: on /oauth/authorize, frame-ancestors 'none' and X-Frame-Options: DENY; a page-set X-Frame-Options: DENY is kept as a tightening signal on any path. The page's same-origin referrer policy is kept as a tightening of the site's no-referrer (under no-referrer a browser sends the consent form's Origin as null, and Astro's own cross-site form check refuses it). The site-wide form-action 'self' blocks the redirect after the consent post, so the page names the one validated client origin in an internal header, and applySecurityHeaders adds it to form-action on that path only, re-validating it as a strict serialized origin, and deletes the header from every response. Everything under /oauth bypasses the edge cache entirely.
  • src/lib/host.ts: /oauth added to APP_ROUTE_PREFIXES. src/lib/osa-widget.ts: /oauth added to the widget's excluded paths, so no third-party script runs on the consent screen.
  • src/lib/account-copy.ts: the oidc.consent.* (including oidc.consent.redirect_host), oidc.rule.* and oidc.error.* keys, transcribed from nemar-cli's shared/contract/account-copy.ts, with the same // DRAFT: wording pending the owner (#2017) marker above oidc.consent.compute_spend.
  • README.md: the development sign-in uses the legacy cookie name, so under bun run dev the page sends you to sign in again in a loop; how to try it locally. CHANGELOG.md: entries under [Unreleased], including the 404-until-flag note.
  • .github/workflows/ci.yml: adds shared/contract/oidc-authorize.ts and shared/oidc.ts to the nemar-cli sparse checkout and sets NEMAR_CLI_OIDC_AUTHORIZE_CONTRACT.

Tests

  • src/lib/oidc-authorize.test.ts (36): methods, request reading and the streaming cap, every answer kind and every malformed shape, the strict origin check (including [::1], and hosts the URL parser keeps as an origin but a policy would split on: ;, ', ,, *), the sign-in return path, each panel's copy and status including the redirect host line, every oidc.* sentence printed by some panel, app-host routing and the widget exclusion.
  • src/lib/oidc-authorize-api.test.ts (6): route, body, pinned Origin, forwarded Cookie, the caller marker, no redirect following, no logged values.
  • src/lib/proxy-path.test.ts (44) and test/routes/api-v1-proxy-oidc.test.ts (12): the proxy's refusal across encodings, case, dot and empty segments and a query; control characters and backslashes in a capture (400, nothing upstream); spellings the URL parser resolves or decodes onto the routes (404, nothing upstream); and an ordinary path still forwarded.
  • test/account-tiers-ui.test.ts (59): the unlinked card's Connect button is a form POST to the link start, and no anchor points at the link or relink start.
  • test/oidc-authorize-ui.test.ts (19): source-level guards on the page's order and wiring (this repository renders no Astro page in a test), including the consent screen's referrer policy.
  • src/middleware.test.ts (137 in the file): framing, form-action widened only for a valid origin on that path, header removal, the same-origin tightening kept, the whole-middleware path, and the edge-cache bypass with a control.
  • test/oidc-authorize-contract-drift.test.ts (4): the constants and closed lists (now including the caller header and value, the marker window and the redirect errors) against nemar-cli's shared/contract/oidc-authorize.ts, and the page path against shared/oidc.ts, strict under NEMAR_CLI_OIDC_AUTHORIZE_CONTRACT.
  • Mutation proofs: 23 in the first pass, 11 in review round 1 and 9 in review round 2 (round 2: the Connect form back to GET or back to a link, the route deciding on the capture instead of the fetched path, the capture check without its control-character or backslash refusal, and the filter without its tab or backslash handling, each killed by its test; round 1: the proxy forwarding the routes, skipping decoding, case or dot segments, or keeping the query; the client without the caller marker; form-action without [::1]; an unbounded POST body; the consent screen without the redirect host; the middleware dropping same-origin; the page back on no-referrer), each a single exact edit killed by its test, files restored byte for byte.

Real browser run

Run once locally in installed Google Chrome under Playwright (headless), against astro dev on localhost:4321 with PUBLIC_API_BASE_URL pointed at a local API. The local API serves the real nemar-cli Worker entry point from nemarOrg/nemar-cli#2036's head over that repository's OIDC test harness (every migration on SQLite), with a person account holding a proven ORCID iD, a __Host- session cookie, and a client registered through the owner route with a loopback redirect address to a stand-in callback recorder. 29 checks, all pass:

  • Deny: the consent screen (200, Referrer-Policy: same-origin, form-action 'self' http://127.0.0.1:19999, frame-ancestors 'none', the redirect host named), then the client's callback with error=access_denied, the request's state, iss, and no code.
  • Allow: the same screen, then the callback with a code, state and iss and no error; the code is stored for that client and that redirect address, and one grant is recorded.
  • A repeat with the grant live goes straight to the callback with a new code and no consent screen.
  • Both consent form posts carried the site's own Origin, and the browser logged no console errors and no Content Security Policy reports.
  • Negative control: with the consent screen set back to no-referrer, the Deny post never left /oauth/authorize.

The run is not added to the repository's Playwright suite, which runs against a live API; it needs a local API from the nemar-cli checkout.

Gates

  • bun run lint: pass. bun run typecheck: 0 errors, 0 warnings.
  • bun run test, after the rebase onto staging: 167 files passed, 2 skipped; 4533 tests passed, 9 skipped (drift tests whose sibling checkout path does not exist beside this worktree). Run with NEMAR_CLI_OIDC_AUTHORIZE_CONTRACT and NEMAR_CLI_ACCOUNT_COPY pointing at Phase B3: OIDC authorization and consent nemar-cli#2036's branch. This PR's eight test files together: 248 pass.
  • bun run build: exit 0, run once, before the rebase onto staging.
  • Review round 2 head (1edf987): bun run lint passes (405 files); bun run typecheck 0 errors, 0 warnings; the proxy, Settings and drift tests (proxy-path, api-v1-proxy-oidc, account-tiers-ui, profile-gaps-ui, settings-cli-keys, identity-conflict-pages, api-binding-call-sites, account-copy-drift, oidc-authorize-contract-drift, the drift tests pointed at Phase B3: OIDC authorization and consent nemar-cli#2036's branch): 9 files, 231 pass; bun run build: exit 0 (217 seconds, slowed by a catalog fetch in the image step); nemar-cli's test/account-copy-parity.test.ts against this branch's src/lib/account-copy.ts: 9 pass.
  • The Cloudflare Pages preview for 165a581 failed at once and is unexplained: the local build of that head passes, and staging (3680546) and the pre-rebase head (364fddb) both deployed. The preview for 1edf987 was still building when this was written.

CI sequencing

Each repository's CI compares its copy and contract against the other's pre-release branch: this repository's drift tests read nemar-cli dev, and nemar-cli's parity test reads this repository's staging. A change that adds copy keys on both sides cannot be green on both at once. nemarOrg/nemar-cli#2036 merges into its epic branch with its parity test named as the only red. Here, test/oidc-authorize-contract-drift.test.ts and test/account-copy-drift.test.ts are red until the epic reaches nemar-cli dev; that red is expected, and CI must be re-run on this PR's head then, before it merges. Locally both pass against the nemar-cli PR's branch.

Not done, or for the owner

  • The compute-spend sentence (oidc.consent.compute_spend, "It can also reserve and spend your NEMAR compute time.") is a draft that needs the owner's wording (#2017 escalation), marked in both copy files.
  • The private-site and docs grant routes are reachable through the general proxy in the same way the authorization routes were; they are unchanged here, as instructed, and whether they get the same guard is the owner's decision.
  • A cross-site POST authorization request (a client's form_post) is refused by Astro's own security.checkOrigin before the page runs, and the session cookie (SameSite=Lax) would not travel with it anyway; GET is the supported method in practice. Same-site POST (the consent form) works.
  • Screens are documented in #2020.

Base automatically changed from feature/issue-2015-host-cookie-reader to staging November 4, 2026 19:58
@neuromechanist
neuromechanist force-pushed the feature/issue-2017-oauth-authorize-page branch from 364fddb to 165a581 Compare November 4, 2026 20:09
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 99fd85a into staging Nov 6, 2026
8 of 9 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2017-oauth-authorize-page branch November 6, 2026 21:48
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