|
22 | 22 | * (per-environment runtime) — mirroring `runSetInitialPassword`. |
23 | 23 | */ |
24 | 24 |
|
| 25 | +import { inProcessRedispatchUrl } from './in-process-redispatch.js'; |
| 26 | + |
25 | 27 | export interface RegisterSsoFormResult { |
26 | 28 | /** HTTP status to return to the caller. */ |
27 | 29 | status: number; |
@@ -57,7 +59,9 @@ async function resolveActiveOrganizationId( |
57 | 59 | if (cookie) h.set('cookie', cookie); |
58 | 60 | const authz = headers.get('authorization'); |
59 | 61 | if (authz) h.set('authorization', authz); |
60 | | - const resp = await handle(new Request(sessionUrl, { method: 'GET', headers: h })); |
| 62 | + // [#22398] A cookie request reads without renewal: this response's cookie |
| 63 | + // is never sent (`in-process-redispatch.ts`). |
| 64 | + const resp = await handle(new Request(inProcessRedispatchUrl(sessionUrl, h), { method: 'GET', headers: h })); |
61 | 65 | if (!resp.ok) return undefined; |
62 | 66 | const data: any = await resp.json().catch(() => null); |
63 | 67 | const org = data?.session?.activeOrganizationId ?? data?.activeOrganizationId; |
@@ -201,7 +205,9 @@ export async function runRegisterSsoProviderFromForm( |
201 | 205 | // regression) when no active org is set. |
202 | 206 | const organizationId = await resolveActiveOrganizationId(handle, innerUrl, headers); |
203 | 207 |
|
204 | | - const innerReq = new Request(innerUrl, { |
| 208 | + // [#22398] `/sso/register` reads the session too (the ADR-0135 D6 before-hook |
| 209 | + // and `sessionMiddleware`), and only status and body come back from here. |
| 210 | + const innerReq = new Request(inProcessRedispatchUrl(innerUrl, headers), { |
205 | 211 | method: 'POST', |
206 | 212 | headers, |
207 | 213 | body: JSON.stringify({ providerId, issuer, domain, oidcConfig, ...(organizationId ? { organizationId } : {}) }), |
@@ -298,7 +304,8 @@ export async function runRegisterSamlProviderFromForm( |
298 | 304 | // can manage the provider — see the OIDC helper above. |
299 | 305 | const organizationId = await resolveActiveOrganizationId(handle, innerUrl, headers); |
300 | 306 |
|
301 | | - const innerReq = new Request(innerUrl, { |
| 307 | + // [#22398] Same rule as the OIDC bridge's inner `/sso/register`. |
| 308 | + const innerReq = new Request(inProcessRedispatchUrl(innerUrl, headers), { |
302 | 309 | method: 'POST', |
303 | 310 | headers, |
304 | 311 | body: JSON.stringify({ providerId, issuer, domain, samlConfig, ...(organizationId ? { organizationId } : {}) }), |
@@ -401,7 +408,9 @@ export async function runRequestDomainVerification( |
401 | 408 | if (!rw) return { status: 400, body: { success: false, error: { code: 'INVALID_REQUEST', message: 'Bad request URL' } } }; |
402 | 409 | const headers = forwardAuthHeaders(request, rw.origin); |
403 | 410 |
|
404 | | - const resp = await handle(new Request(rw.innerUrl, { method: 'POST', headers, body: JSON.stringify({ providerId }) })); |
| 411 | + // [#22398] The inner route reads the session (`sessionMiddleware`); only its |
| 412 | + // status and body come back from here. |
| 413 | + const resp = await handle(new Request(inProcessRedispatchUrl(rw.innerUrl, headers), { method: 'POST', headers, body: JSON.stringify({ providerId }) })); |
405 | 414 | let parsed: any = {}; |
406 | 415 | try { const t = await resp.text(); parsed = t ? JSON.parse(t) : {}; } catch { parsed = {}; } |
407 | 416 | if (!resp.ok) { |
@@ -451,7 +460,9 @@ export async function runVerifyDomain( |
451 | 460 | if (!rw) return { status: 400, body: { success: false, error: { code: 'INVALID_REQUEST', message: 'Bad request URL' } } }; |
452 | 461 | const headers = forwardAuthHeaders(request, rw.origin); |
453 | 462 |
|
454 | | - const resp = await handle(new Request(rw.innerUrl, { method: 'POST', headers, body: JSON.stringify({ providerId }) })); |
| 463 | + // [#22398] The inner route reads the session (`sessionMiddleware`); only its |
| 464 | + // status and body come back from here. |
| 465 | + const resp = await handle(new Request(inProcessRedispatchUrl(rw.innerUrl, headers), { method: 'POST', headers, body: JSON.stringify({ providerId }) })); |
455 | 466 | let parsed: any = {}; |
456 | 467 | try { const t = await resp.text(); parsed = t ? JSON.parse(t) : {}; } catch { parsed = {}; } |
457 | 468 | if (resp.ok) { |
|
0 commit comments