Skip to content

Accept the authorization-request POST from any site (nemar-cli#2020) - #503

Merged
neuromechanist merged 8 commits into
stagingfrom
feature/issue-2020-authorize-post
Nov 7, 2026
Merged

neuromechanist merged 8 commits into
stagingfrom
feature/issue-2020-authorize-post

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Owner decision W1 of nemar-cli#2020 (phase B6, slice S6): OpenID Connect Core 3.1.2.1 requires /oauth/authorize to accept a form POST, and the conformance module oidcc-ensure-post-request-succeeds sends it cross-site. Astro 6.3.3's built-in checkOrigin answers 403 to that before page code runs and has no exemption.

  • security.checkOrigin is now false (astro.config.mjs).
  • src/lib/origin-check.ts is the site's own check, run first in onRequest. It is Astro's rule line for line (a test sends 504 combinations of method, content type and Origin through both and compares), plus one exemption: method POST, path exactly /oauth/authorize, media type exactly application/x-www-form-urlencoded. Origin is not consulted for the exemption.
  • The consent form posts to the same path with the same type, and the two cannot be told apart before the body is read. The discriminator is the page's own: readAuthorizeInput(request, origin) answers forbidden (the built-in's 403, same body, before any API call) for any POST whose body names nemar_consent_token, nemar_request or nemar_decision, unless Origin equals the site's origin exactly and Sec-Fetch-Site, when sent, is same-origin.
  • Invariant (ADR 0031): an authorization-request POST can only render. A cross-site POST can only be read as check (sent to the API's check route, as the same string in a GET), invalid or forbidden; it can never reach the consent route.
  • No new route, no CORS change, no cookie change, no nemar-cli change.

Commits: page refusal first (inert until the middleware exemption exists), then the middleware and config together, then ADR 0031 (0030 is taken on the epic branch), changelog and handoff.

Allow / deny (real onRequest, then the page's input reader)

Request Result
cross-site, null, missing or sibling-subdomain Origin, urlencoded POST /oauth/authorize, authorization body allowed, read as check
same, body names a consent field (cross-site, null, missing, sibling, or right Origin with Sec-Fetch-Site: cross-site/same-site/none) 403
same-origin consent POST (with or without Sec-Fetch-Site: same-origin) allowed, read as consent
/oauth/authorize/, //oauth/authorize, /OAUTH/authorize, /oauth/authorize%2f, /oauth/%61uthorize, /oauth/authorize.json, ;x=1 suffix, cross-site 403
multipart, text/plain, form type named only in a parameter of another type, two folded content types (where duplicate headers are comma-joined, as on the Workers runtime; on Node's astro dev the first Content-Type wins, with no security impact because the check and the page read the same header), no content type, cross-site, to /oauth/authorize 403
PUT / PATCH / DELETE to /oauth/authorize, cross-site 403
every file under src/pages (globbed, so new endpoints are covered), cross-site urlencoded / multipart / text-plain, null or missing Origin 403, except /oauth/authorize + urlencoded
cross-site JSON, GET unchanged (left to CORS / safe), as in Astro

Threat analysis

  • CSRF on consent. The API cannot see the browser's Origin (the page pins its own on both API calls), so the website is the only Origin control. A consent decision is refused (403, Astro's wording, before any API call) unless Origin is exactly the site's and Sec-Fetch-Site, if present, is same-origin: null, a missing header, a sibling *.nemar.org and a forged Origin on a browser that says cross-site all fail. Any body naming any consent field counts, in any number, so a consent cannot be smuggled as an "authorization request" with a stray nemar_decision. Behind that, the API's consent token is an HMAC bound to the session and the request, which a forging page cannot know. The consent screen sends Referrer-Policy: same-origin so its own form keeps its Origin (unchanged).
  • Login CSRF. The authorization POST signs nobody in. It can only end in a 303 to /login?next=/oauth/authorize?<request>, where next passes safeRedirectPath; the sign-in forms themselves (/api/auth/code/*) keep the cross-site refusal (swept by the route test).
  • Clickjacking. Verified on a running astro dev: the page's responses (503 panel, and the 403) carry X-Frame-Options: DENY, Content-Security-Policy: ... frame-ancestors 'none' ..., Cache-Control: no-store, Referrer-Policy: no-referrer. The consent screen's own headers were not observed in a browser (it needs a live API); its frame-ancestors 'none' is pinned by the existing src/middleware.test.ts cases. Nothing was missing, nothing was added.
  • Open redirect. Unchanged by this PR and confirmed: the API (parseClientAndRedirect, nemar-cli services/oidc-authorize.ts) exact-matches redirect_uri against the client's registered list before any redirect (errors before that render a panel), and the page only follows a location that is absolute https (or loopback http) with no credentials (usableLocation). The POST path feeds the same code.
  • Parameter smuggling, body vs query. The page forwards the POST body string as the API's request, exactly as it forwards the GET query string; the API parses both with the same URLSearchParams, so duplicates (client_id, redirect_uri, the single-valued list), order and precedence are identical, and a test asserts the POST body reads as the same string a GET would. A POST reads only its body; the URL's query is ignored (tested). The sign-in return trip uses the API's canonical params.toString(), a GET, and nemar_auth_after is an API-signed marker bound to the client and a ten-minute window, so a body cannot forge one. The body is bounded at 32 KiB streamed; the API enforces its own 8192-character request limit.
  • Cookie on a cross-site POST. The session cookie is SameSite=Lax; __Host- (nemar-cli web-session.ts), so a cross-site POST carries none and lands on sign-in (tested: POST -> 303 login -> GET with the same parameters). A same-site POST (sibling *.nemar.org) does carry it; that request is still only an authorization request, which a top-level GET from the same page would be too, and its consent is refused. Not changed.

Gates

  • bun run lint: clean. bun run typecheck: 0 errors. bun run test: 168 files passed, 4628 passed, 14 skipped (3 files skipped, as before). bunx astro build: complete.
  • New: src/lib/origin-check.test.ts (30), test/origin-check-middleware.test.ts (43, includes the config assertion and the src/pages sweep), additions to src/lib/oidc-authorize.test.ts and test/oidc-authorize-ui.test.ts; src/middleware.test.ts POST shims now carry their own Origin (the built-in used to refuse them before onRequest).
  • Mutation run (each restored after): widen path (startsWith("/oauth"), startsWith(path), strip trailing slash, lower-case, decode) killed 15/10/5/4/3 tests; drop content-type check 12; drop consent discrimination 8; page ignores forbidden 1 (the page-wiring source test); only the token names consent 2; same-origin test always true 6; drop Sec-Fetch-Site 3; exempt any method 7; config back on 1; middleware call removed 18; refuse all content types 4. Every one failed at least one test.
  • Real server: astro dev with the API unreachable: cross-site authorization POST 503 (reached the page), cross-site consent POST 403, same-origin consent 503 (reached the API call), /oauth/authorize/, //oauth/authorize, /OAUTH/authorize, %2f, %61uthorize, multipart and /api/auth/logout cross-site all 403. Same-origin //oauth/authorize, /OAUTH/authorize and %2f are 404 (Astro does not route them); %61uthorize routes to the page, which is why that spelling is not exempt.

Review round 1 (Opus)

  • Cross-site POSTs are now refused unless the parser itself reads them as a plain authorization request AND they name no consent field (crossSiteInputGate); the field list is one exported constant (OIDC_CONSENT_FORM_FIELDS) held to the parser's source by a test. Chosen over refusing every nemar_-prefixed key because nemar_auth_after is a legitimate authorization parameter.
  • test/astro-origin-check-upgrade.test.ts fails when any Astro dist file other than the known five mentions checkOrigin, or anything but core/base-pipeline.js reads manifest.checkOrigin; ADR 0031 has the upgrade checklist line.
  • ADR 0031 now states that backslash, dot segments, %2e segments and a tab normalize to the exact path and are exempt (tested); every spelling that reaches the page but is not exempt fails closed.
  • Handoff step 4 corrected: the middleware's own 403 carries only a content type (as Astro's did); the security headers are on the page's own responses.

Merge note

When feature/issue-493-epic-compute-web merges to staging, both branches add a line after 0029 in .context/decisions/README.md (0030 there, 0031 here) and both edit .context/handoff.md. Resolution: keep both index lines in numeric order and both handoff sections.

Not verified

The conformance suite itself, a browser run through a live API (S7), and the real consent screen's response headers.

Manual check added to .context/handoff.md.

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 7acaaa8 into staging Nov 7, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2020-authorize-post branch November 7, 2026 09:37
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