mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-17 07:04:36 +00:00
GET /authorize validates the OAuth request through the provider and renders the consent page with a fresh CSRF token, a nonce'd CSP (scripts/styles by nonce plus Google Identity Services origins only, form-action 'self', frame-ancestors 'none'), no-store, X-Frame-Options DENY. The original query is echoed in a hidden field; nothing is stored between GET and POST. POST /authorize checks the CSRF double-submit, re-validates the request from the echoed query (a tampered redirect is refused locally, never followed), sends access_denied + state + iss back on cancel, signs in through the Authenticator, re-renders with the reason on failure (401 / 502, username prefilled, password never echoed), and on success calls finishAuthorization and redirects with the code. Never auto-approves. createApp takes injectable deps (default: the Artcraft authenticator for the configured upstream, and the public Google client id when the GOOGLE_CLIENT_ID binding is set — preview and production carry the id storyteller-web already verifies; local stays password-only). Tests (8, end to end through the Worker with the fake upstream served in-process): page + headers; missing/mismatched CSRF → 403; deny → access_denied redirect; wrong password → 401 re-render; incomplete form → 400; tampered request → 400; real sign-in → 302 with a code that exchanges for a bearer reaching /mcp, grant under user_localdev1, props holding the session the fake actually issued; Google credential path. pnpm check: typecheck, eslint, prettier, 152 tests passing. Claude-Session: https://claude.ai/code/session_01H3gfN2NCx3hBXSrZXYHUQ3