diff --git a/.serena/memories/backend/auth-permissions-product-domains.md b/.serena/memories/backend/auth-permissions-product-domains.md index 3209813bff..56ca732a67 100644 --- a/.serena/memories/backend/auth-permissions-product-domains.md +++ b/.serena/memories/backend/auth-permissions-product-domains.md @@ -2,19 +2,10 @@ ## Auth and sessions -- Main auth RPC commands live in `app.rpc.commands.auth`; LDAP and OIDC provider logic live in `app.auth.ldap` and `app.auth.oidc`, with LDAP-specific RPC checks in `app.rpc.commands.ldap`. +- LDAP identity, SSO redirects and invitation-based registration: `mem:backend/auth-sso`. - Public auth endpoints must explicitly set `::rpc/auth false`; RPC auth defaults to enabled. Session cookie creation/deletion is usually attached as an RPC response transform. -- Basic Penpot registration is token staged: prepare/register creates or verifies temporary tokens, then profile creation/session setup is reused by other auth backends. The frontend `/auth/verify-token` flow is a hub for registration confirmation, email change, and invitation tokens. -- OIDC-compatible providers share a generic flow: redirect to provider, validate callback/request token, fetch identity data, then login an existing profile or register a new one. Known providers may have hardcoded endpoints; generic OIDC can use discovery/configured endpoints. -- LDAP login validates credentials against the external directory, fetches identity data, then logs in or registers a matching Penpot profile. LDAP registration is not a separate Penpot signup flow. -- LDAP session identity MUST come from the directory-returned email (`info.email`): the profile matching the typed email can differ (aliases, UPNs, multi-valued `mail` attributes) and is used only for lockout checks, never to bind the session. - Account lockout (flag `:account-lockout`, `app.auth.login-lockout`) is Redis-backed and keyed per profile id. Password and LDAP flows check/increment on the profile derived from the typed email and clear on the profile that actually logs in. - Lockout and RPC rate limits share the `app.http.errors/handle-error :rate-limit` HTTP path: status 429, body `{:type :rate-limit :code ... :hint ... :ttl ...}`, and any supplied `::http/headers` preserved. Account lockout raises `:code :account-locked` and, when it carries a non-nil `:ttl` (seconds), the handler adds `retry-after`. The RPC limiter (`app.rpc.rlimit`) raises `:code :request-blocked` and sets `retry-after` itself in `::http/headers` (seconds until the longest rejecting limit resets), alongside `x-rate-limit-remaining`/`x-rate-limit-reset`. CORS (`app.http.middleware/with-cors-headers`) exposes `content-type`, `retry-after`, and both `x-rate-limit-*` headers. External flags: `enable-account-lockout`, `enable-rpc-rlimit`. -- Logout may return an OIDC provider redirect URI when the session claims include provider/session data and the provider has a logout URI. -- Organization SSO (Nitrate): the RPC `check-nitrate-sso` takes the route's **query string proper** (`:query-string`, e.g. `screen=workspace&team-id=…`), never a URL and never with the `?` separator: the client strips it (`rt/token->query-string`) and the server puts it back. The server builds the destination with `app.auth.oidc/build-dest-url` (`public-uri` + `?` + the params, parsed and rendered back), so the redirect can never leave the public URI; a value whose parsed keys are not param names is not a route: a URL parses into a single key holding the whole URL, and a key carrying `:`, `/`, `?` or `#` is rejected with a `:warn` and the user lands on the public URI (the RPC never fails because of it). Do not reason from `u/map->query-string`: it keeps a valueless key as `key=`, so rendering is not what filters a URL out — the key shape is. A leading `?` is still trimmed server-side, so a client bundled before the trim keeps its destination. Never require `screen`: the root of the app carries its params instead of a screen (`?template=…`), and `check-nitrate-sso` is called from that branch too (`dtm/resolve-login-team-id`, which today reads only `:authorized` and never follows the redirect, so a wrong destination there is a silent `:warn` and not a visible break); the callback re-checks the destination before redirecting, which covers state tokens minted before that. The state token also carries `:profile-id`: only that session is granted the `props :sso` entry (`session-mismatch` otherwise, and the redirect still happens). -- Organization SSO needs `app.nitrate/organization-access?` whenever the RPC receives an `:organization-id` (that id always comes from the client): the profile must be a member of the organization or its owner; otherwise the RPC answers `{:authorized true :reason :no-organization-access}`, the same short-circuit shape as `:no-team-access`. -- Invitation tokens are verified through token issuers and only accepted when the token member id/email matches the authenticated profile; otherwise login proceeds without consuming the invitation. -- When public registration is disabled, invitation-based password registration also requires a matching, non-expired `team_invitation` row; registration revalidates it under a row lock before creating the profile. SSO registration (OIDC and compatible providers) follows the OIDC callback gate: it requires `:registration` or `:oidc-registration`, or a team invitation token issued for the registering email (an invitation substitutes the flags only when `member-email` matches the OIDC/`prepared-register` email via `clean-email`, as in the password flow, which raises `:email-does-not-match-invitation` otherwise). The OIDC callback verifies the invitation JWT and the email before redirecting to register, and `register-profile` revalidates the invitation under a row lock when no SSO flag is set; it never requires password login. Only OIDC-typed backends (`oidc-provider-types` in `app.auth.oidc`) take the SSO registration gate; any other `:backend` in a prepared-register token is rejected as `:invalid-token`. - Access tokens (`app.http.access-token`): personal tokens have JWT issuer `access-token` and DB type other than `mcp`; MCP tokens have issuer `urn:penpot:mcp-token` (`actoken/mcp-token-issuer`) and DB type `mcp`. Authentication requires issuer and type to agree, and the claim `uid` to match the row's profile; other issuers and undecryptable tokens are treated as anonymous. - Management RPC (`/api/management/methods/:name`) is shared-key only. The middleware authenticates ` `; the RPC wrapper `wrap-shared-key-authorization` authorizes the key id against the method's `::rpc/allowed-shared-keys` set. Absent metadata accepts any configured key; all current methods declare one (`exporter`/`media-processor` for `upload-tempfile`, `nexus` for file analysis, `exporter` for jobs, `admin-console` for Nitrate). A valid key outside the set answers 403 `:shared-key-not-allowed`; denied calls do not reach the audit wrapper. - Personal tokens need flag `:access-tokens`. MCP tokens need `:mcp` or `:access-tokens`, and only on routes whose `actoken/authz` gets `::actoken/allow-mcp true` (the RPC routes); elsewhere (e.g. assets) they are anonymous. diff --git a/.serena/memories/backend/auth-sso.md b/.serena/memories/backend/auth-sso.md new file mode 100644 index 0000000000..37b5ed3fba --- /dev/null +++ b/.serena/memories/backend/auth-sso.md @@ -0,0 +1,8 @@ +# Backend SSO and registration + +- Start at `app.auth.oidc`, `app.rpc.commands.auth` and `app.rpc.commands.ldap`. For HTTP session and token boundaries see `mem:backend/http-rpc` and `mem:backend/auth-permissions-product-domains`. +- LDAP binds the session to the directory-returned email, not the typed login: aliases and multi-valued attributes can resolve to a different profile. Lockout checks use the typed identity, but successful login clears the counter for the profile actually logged in. +- `check-nitrate-sso` receives the client route as a query string, not an absolute URL. `build-dest-url` validates parameter keys and builds the destination under `public-uri`; invalid input falls back there. Accept root routes without `screen`, and keep callback revalidation for older state tokens. The state token binds the SSO grant to the profile that initiated it: a different session must not receive that grant. +- A client-supplied organization ID requires `app.nitrate/organization-access?` before SSO; callers without organization access get the no-access short circuit, not an SSO challenge. +- When public registration is disabled, a matching invitation can allow registration. Password registration rechecks the non-expired invitation row under lock. OIDC registration requires `:registration`, `:oidc-registration` or an invitation whose member email matches the provider email after `clean-email`; the callback verifies it and registration revalidates it under lock when the flags are off. Only recognized OIDC provider types take the SSO registration path. Keep invitation identity checks on authenticated login too. +- Test both the root and workspace route forms, malformed redirect targets, changed sessions and invitation email mismatches. Frontend query-string construction: `mem:frontend/routing-app-shell-subtleties`. For test flags and setup see `mem:backend/testing`. diff --git a/.serena/memories/backend/core.md b/.serena/memories/backend/core.md index 29070ee4d1..36422e9ef7 100644 --- a/.serena/memories/backend/core.md +++ b/.serena/memories/backend/core.md @@ -19,6 +19,7 @@ JVM Clojure backend. Start in `app.main` for Integrant wiring, `app.rpc.commands - Graph projection parity, debug sessions, access and native resource ownership: `mem:backend/graph-experiment`. - Session lifetime, token `:exp` and session GC: `mem:backend/session-expiration`. - Auth, product permissions, teams, projects, invitations, comments and webhooks: `mem:backend/auth-permissions-product-domains`. +- LDAP identity, SSO redirects and invitation-based registration: `mem:backend/auth-sso`. - WebSocket connection ownership and revocation: `mem:backend/websocket-subscriptions`. - Audit event attribution, fan-out and privacy: `mem:audit-log`; cursor ordering, archival and retention: `mem:backend/audit-consumers`. - Service layout, task queues versus Pub/Sub, and horizontal scaling: `mem:prod-infra/core`. diff --git a/.serena/memories/frontend/routing-app-shell-subtleties.md b/.serena/memories/frontend/routing-app-shell-subtleties.md index c9ff6309aa..d80f303a21 100644 --- a/.serena/memories/frontend/routing-app-shell-subtleties.md +++ b/.serena/memories/frontend/routing-app-shell-subtleties.md @@ -2,7 +2,7 @@ - Start at `app.main.ui.routes`, `app.main.router` and `app.util.browser-history`. The token is `location.search`, not a store field; preserve the configured `public-uri` origin and subpath. The route table and legacy hash compatibility live in `app.main.ui.routes`. - Push of the current token does not write or notify; replace always writes and notifies, even for the same token, so URL corrections reach the router. `app.util.dom/replace-history-state!` intentionally rewrites without routing; do not substitute a notifying replace. -- Route data uses query params. A repeated param can decode as a vector; use `rt/get-query-param` for a scalar. Use `rt/token->query-string` at the SSO boundary: the server owns the destination origin. Use `rt/token->url` for a client-side absolute URL; do not require `screen`, since root flows can carry params such as a template without a route name. See `mem:backend/auth-permissions-product-domains`. +- Route data uses query params. A repeated param can decode as a vector; use `rt/get-query-param` for a scalar. Use `rt/token->query-string` at the SSO boundary: the server owns the destination origin. Use `rt/token->url` for a client-side absolute URL; do not require `screen`, since root flows can carry params such as a template without a route name. See `mem:backend/auth-sso`. - `rt/nav-raw` exits the router; tests observe its destination by dereferencing the event, not by looking for an app listener. Unknown or empty routes verify the profile and teams before redirecting so root and invitation flows do not race. See `mem:frontend/auth-events` for login and invitations. - Use the team-scoped navigation helpers in `app.main.data.common` rather than building the route at the call site. Their private `resolve-team-id` considers the team already on screen before the profile default, so the user's personal team does not replace the current team. An invalid team route fails explicitly rather than rendering a blank shell. - For store exceptions, React boundaries and report limits/classification see `mem:frontend/error-reporting`. For the client reaction to lost membership and job events see `mem:frontend/websocket-notifications`.