Repository navigation
Phase B3: /oauth/authorize page - #501
Merged
Merged
Conversation
Base automatically changed from
feature/issue-2015-host-cookie-reader
to
staging
November 4, 2026 19:58
neuromechanist
force-pushed
the
feature/issue-2017-oauth-authorize-page
branch
from
November 4, 2026 20:09
364fddb to
165a581
Compare
Deploying nemar-website with
|
| Latest commit: |
f9f6d73
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2ce98b0d.nemar-website.pages.dev |
| Branch Preview URL: | https://feature-issue-2017-oauth-aut.nemar-website.pages.dev |
3 tasks
This was referenced Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sCookieheader 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 ontostaging, which is its base. It must not merge until the nemar-cli OIDC epic (nemarOrg/nemar-cli#2014) reaches nemar-clidev, 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 likesrc/pages/auth/private/authorize.astro. Every response carriesCache-Control: no-store,X-Robots-Tag: noindexandX-Frame-Options: DENY; the consent screen carriesReferrer-Policy: same-originand every other responseno-referrer. Any other method (HEAD included) is 405 before anything is read. A redirect answer is followed with 302 (303 after a POST);loginandreauthgo to/login?next=/oauth/authorize?<request>(witherror=session_requiredforreauth);consent,rule_refusedand 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 itsHOST_PREFIXED_SESSION_COOKIEis 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 includesunsupported_response_type.src/lib/oidc-authorize-api.ts: the two calls, shaped likeprivate-auth-api.ts: pinnedOrigin, forwardedCookie, the fixed caller marker header the API requires,redirect: "manual", a deadline, never throws, logs no value.src/pages/api/v1/[...path].tsandsrc/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=linkinstead 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.tsandsrc/lib/orcid-proxy.tscomments say so. With the API'sHOST_PREFIXED_SESSION_COOKIEoff (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'andX-Frame-Options: DENY; a page-setX-Frame-Options: DENYis kept as a tightening signal on any path. The page'ssame-originreferrer policy is kept as a tightening of the site'sno-referrer(underno-referrera browser sends the consent form's Origin asnull, and Astro's own cross-site form check refuses it). The site-wideform-action 'self'blocks the redirect after the consent post, so the page names the one validated client origin in an internal header, andapplySecurityHeadersadds it toform-actionon that path only, re-validating it as a strict serialized origin, and deletes the header from every response. Everything under/oauthbypasses the edge cache entirely.src/lib/host.ts:/oauthadded toAPP_ROUTE_PREFIXES.src/lib/osa-widget.ts:/oauthadded to the widget's excluded paths, so no third-party script runs on the consent screen.src/lib/account-copy.ts: theoidc.consent.*(includingoidc.consent.redirect_host),oidc.rule.*andoidc.error.*keys, transcribed from nemar-cli'sshared/contract/account-copy.ts, with the same// DRAFT: wording pending the owner (#2017)marker aboveoidc.consent.compute_spend.README.md: the development sign-in uses the legacy cookie name, so underbun run devthe 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: addsshared/contract/oidc-authorize.tsandshared/oidc.tsto the nemar-cli sparse checkout and setsNEMAR_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, everyoidc.*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) andtest/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-actionwidened only for a valid origin on that path, header removal, thesame-origintightening 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'sshared/contract/oidc-authorize.ts, and the page path againstshared/oidc.ts, strict underNEMAR_CLI_OIDC_AUTHORIZE_CONTRACT.form-actionwithout[::1]; an unbounded POST body; the consent screen without the redirect host; the middleware droppingsame-origin; the page back onno-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 devonlocalhost:4321withPUBLIC_API_BASE_URLpointed 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: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 witherror=access_denied, the request'sstate,iss, and no code.stateandissand no error; the code is stored for that client and that redirect address, and one grant is recorded.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 ontostaging: 167 files passed, 2 skipped; 4533 tests passed, 9 skipped (drift tests whose sibling checkout path does not exist beside this worktree). Run withNEMAR_CLI_OIDC_AUTHORIZE_CONTRACTandNEMAR_CLI_ACCOUNT_COPYpointing 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 ontostaging.1edf987):bun run lintpasses (405 files);bun run typecheck0 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'stest/account-copy-parity.test.tsagainst this branch'ssrc/lib/account-copy.ts: 9 pass.165a581failed at once and is unexplained: the local build of that head passes, andstaging(3680546) and the pre-rebase head (364fddb) both deployed. The preview for1edf987was 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'sstaging. 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.tsandtest/account-copy-drift.test.tsare red until the epic reaches nemar-clidev; 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
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.form_post) is refused by Astro's ownsecurity.checkOriginbefore 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.