.ai/principles/distilled/authentication.md
AuthFinders (lib/gitlab/auth/auth_finders.rb); deploy tokens, bearer tokens, job tokens, and sessions are checked in a specific priority — reordering can cause one token type to shadow another.API::APIGuard (lib/api/api_guard.rb).Authn::IamService::JwtValidationService.check_rate_limit! for rate limiting on token creation and verification endpoints.glpat- (PAT), gldt- (deploy token), glcbt- (CI job token), gloas- (OAuth application secret).TokenAuthenticatable concern with add_authentication_token_field.insecure: true storage strategy; use digest: true for SHA-256 or encrypted: :required for AES-256-GCM encryption at rest.PRIVATE-TOKEN header for PATs or Authorization: Bearer for OAuth.ActiveSupport::SecurityUtils.secure_compare) to defend against timing attacks.ActiveSession.Rack::Attack (config/initializers/rack_attack.rb) for login throttling.Gitlab::ApplicationRateLimiter for feature-level rate limits (for example, token creation, password resets).openid_connect_signing_key) without coordinating with the infrastructure team; it is stored in Rails credentials.extern_uid through the API, set trusted_extern_uid to false; the base OAuth login class (lib/gitlab/auth/o_auth/user.rb) checks trusted_extern_uid? before resolving the user — when overriding user lookup in a subclass, verify the override also checks this flag.RelayState parameters before using them as redirect targets (past incident: open redirect via unvalidated RelayState in SAML Single Logout).extern_uid without setting trusted_extern_uid to false; unverified extern_uid changes can enable account takeover.GroupSaml::User), verify the override checks trusted_extern_uid?; the base class checks this but overrides can bypass it.extern_uid without verifying the identity is trusted (trusted_extern_uid?).read_api or other limited-scope tokens to bypass sudo mode or elevated authentication requirements.InternalRedirect#sanitize_redirect or safe_redirect_path to validate all user-supplied redirect targets in password reset flows; DO NOT pass raw parameters to redirect_to — always provide a fallback: redirect_to sanitize_redirect(params[:redirect]) || root_path.user.blocked? check.redirect_to; use InternalRedirect#sanitize_redirect or safe_redirect_path — redirect helpers return nil for invalid targets, so always provide a fallback.composite_identity_enforced: true (must be configured programmatically — not available in the UI).user:* (must be configured programmatically — not available in the UI).user:$ID for the human user who originated the AI request, plus any required base scopes (for example, api).Gitlab::Auth::Identity.resolve_composite_identity_actor(current_user) to resolve the actor for any write operation; DO NOT determine the composite identity context manually.resolve_composite_identity_actor wherever authorship is set (notes, issues/MRs, commits, pipeline user context).:authentication context (service account is attributed); web/assignment flows tag :permission_check context (human is attributed) — DO NOT override this context manually.group: group::authentication for authentication feature flags.For the full picture, see: