* fix(auth): add missing state parameter to OIDC authorization URL
The OIDC login route generates a state UUID and stores it in the
oidc_state cookie, but never includes it in the authorization URL.
This causes the OIDC callback to receive state=null, failing with
'oidc_error=missing_code' because the provider has no state to echo.
Add url.searchParams.set('state', state) after setting scope, so the
state parameter is sent to the OIDC provider and returned in the
callback for proper CSRF protection.
* test(auth): add regression coverage for OIDC login state parameter
Adds a TDD regression test proving the fix in this PR: the OIDC login
route now includes the state query parameter in the authorization
redirect URL, and it matches the oidc_state cookie value set on the
same response. Modeled on tests/unit/oidc-callback.test.ts.
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
* fix(auth): use originEarly for OIDC err redirects (#10224)
* test(auth): verify OIDC err redirects use proxy origin (#10224)
---------
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Two findings from automated security review of the just-merged #6973 OIDC login gate:
- HIGH: the allowlist matched the `email` claim without checking `email_verified`, so
an attacker with an IdP account whose unverified email equals an allowlisted address
could pass the gate. Now the email claim is only honored when email_verified === true.
- MEDIUM: error redirects built their target from the raw Host header (reflected
open-redirect). Now resolved against the framework-parsed request URL.
Regression test added asserting an unverified allowlisted email is rejected.
* feat(auth): optional OIDC for dashboard admin gate (password remains fallback)
- Settings: oidcEnabled + issuer/client/secret/scopes/redirect/allowedSubjects
- Public routes: /api/auth/oidc/ prefix (authorize + callback reachable)
- isAuthRequired: full OIDC config acts as auth method (gate requires login); partial does not (bootstrap preserved)
- New endpoints:
- GET /api/auth/oidc/login — IdP redirect (absolute redirect_uri from request + discovery)
- GET /api/auth/oidc/callback — code exchange, ID token validation (jose + JWKS), optional sub/email whitelist, mints identical 30d auth_token JWT + cookie as password login, redirects to /dashboard
- require-login endpoint now returns oidcEnabled
- Login UI: conditional OIDC button when enabled; password form untouched as fallback
- Tests:
- public-api-routes: OIDC prefixes are public
- api-auth: isAuthRequired true with full OIDC (no password); partial OIDC keeps bootstrap semantics
No new deps. No changes to proxy, keys, managementPassword, policies, MCP, CLI. Single-admin preserved.
* feat(auth): add integration test and fixes for OIDC dashboard login gate
- Add comprehensive integration test for /api/auth/oidc/callback
(happy path + error paths: invalid_state, subject_not_allowed,
not_configured, token_exchange, id_token_invalid, missing_code,
server_misconfigured)
- Use static test seam (oidcCallbackInternals) for cookie store
- Mark setupComplete on first successful OIDC login (bootstrap parity)
- Ensure all redirects use absolute URLs (Next.js 16 compatibility)
- Verify identical auth_token JWT/cookie behavior as password path
- No new dependencies; reuses jose + fetch
Password login remains fully supported as fallback.
* fix(auth): address all Gemini Code Assist review comments for OIDC dashboard login gate
- Add module-level JWKS client cache (Record) + getJwksClient helper
- Wrap token exchange fetch + .json() in try/catch with 10s timeout
- Add 5s timeout to discovery fetch in both /login and /callback routes
- Case-insensitive email comparison in oidcAllowedSubjects whitelist
- Make oidc_state cookie 'secure' dynamic based on request protocol (matches auth_token)
- Expose clearJwksCache on test seam for isolation
All reviewer suggestions applied (adjusted for project rules on Map/Record).
Tests: 53/53 pass.
* fix(auth): wire OIDC config into updateSettingsSchema + SECURITY_IMPACTING_KEYS + encrypt/decrypt + non-empty subjects guard (address maintainer review)
* fix(auth): declare storedPasswordHash + align bootstrap contract for oidcEnabled
The security-impacting-keys re-auth gate in PATCH /api/settings assigned to
`storedPasswordHash` without ever declaring it (no `let`/`const`), so every
PATCH touching a SECURITY_IMPACTING_KEYS field (requireLogin, newPassword,
oidcEnabled, oidcClientSecret, the bypass toggles) threw a ReferenceError in
strict-mode ESM and fell through to the generic 500 handler. That masked the
expected 400/401/200 outcomes in settings-audit and settings-route-password
password-migration tests. Declare it as a block-scoped `const` where it's
first assigned.
Also updates the login-bootstrap-route contract tests: the public
/api/settings/require-login GET now legitimately includes `oidcEnabled` in
its response (the login page needs it to decide whether to render the OIDC
button) — the three closed-shape assertions are extended to expect
`oidcEnabled: false`, matching route.ts's existing behavior.
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
---------
Co-authored-by: mikolaj92 <mikolaj92@users.noreply.github.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouzapw@users.noreply.github.com>