π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
π OIDC max failed attempts
Alicia Sykesb61687c30d75
diff --git a/src/utils/auth/OidcAuth.js b/src/utils/auth/OidcAuth.jsindex 48fbe118..257c7d26 100644--- a/src/utils/auth/OidcAuth.js+++ b/src/utils/auth/OidcAuth.js@@ -3,6 +3,10 @@ import { localStorageKeys } from '@/utils/config/defaults';import ErrorHandler from '@/utils/logging/ErrorHandler';import { statusMsg, statusErrorMsg } from '@/utils/logging/CoolConsole';+// Session storage config for storing last sign-in attempt+const SIGNIN_GUARD_KEY = 'dashy.oidc.signin-attempt';+const SIGNIN_GUARD_THRESHOLD_MS = 5 * 1000;+const getAppConfig = () => {const Accumulator = new ConfigAccumulator();const config = Accumulator.config();@@ -51,6 +55,13 @@ class OidcAuth {async login() {const url = new URL(window.location.href);const code = url.searchParams.get('code');+ const providerError = url.searchParams.get('error');++ // Provider redirected back with an error+ if (providerError && !code) {+ const desc = url.searchParams.get('error_description') || '';+ throw new Error(`OIDC provider returned ${providerError}: ${desc}`);+ }if (code) {// Populate localStorage before the reload so the post-reload route guard@@ -64,7 +75,20 @@ class OidcAuth {const user = await this.userManager.getUser();if (user === null) {if (!isOidcGuestAccessEnabled()) {+ // Bail with error, if we've literally just redirected. Prevents loop+ const lastAttempt = Number(sessionStorage.getItem(SIGNIN_GUARD_KEY)) || 0;+ if (Date.now() - lastAttempt < SIGNIN_GUARD_THRESHOLD_MS) {+ sessionStorage.removeItem(SIGNIN_GUARD_KEY);+ throw new Error(+ 'OIDC sign-in redirect loop detected. Check provider redirect URIs '+ + 'and that id_token claims include a username.',+ );+ }await this.userManager.signinRedirect();+ // Mark the attempt only once signinRedirect has resolved (i.e. the+ // navigation actually fired). If it threw β e.g. discovery fetch failed+ // β we leave the guard untouched so a manual retry isn't blocked.+ sessionStorage.setItem(SIGNIN_GUARD_KEY, String(Date.now()));}} else {this.persistUserInfo(user);@@ -78,11 +102,17 @@ class OidcAuth {const isAdmin = (Array.isArray(groups) && groups.includes(this.adminGroup))|| (Array.isArray(roles) && roles.includes(this.adminRole))|| false;- statusMsg(`user: ${user.profile.preferred_username} admin: ${isAdmin}`, JSON.stringify(info));+ // Fall back through username candidates so USERNAME is always a non-empty+ const username = user.profile.preferred_username+ || user.profile.email+ || user.profile.sub+ || 'oidc-user';+ statusMsg(`Authenticated as ${username} ${isAdmin ? '(admin)' : '(non-admin)'}`, JSON.stringify(info));localStorage.setItem(localStorageKeys.KEYCLOAK_INFO, JSON.stringify(info));- localStorage.setItem(localStorageKeys.USERNAME, user.profile.preferred_username);+ localStorage.setItem(localStorageKeys.USERNAME, username);localStorage.setItem(localStorageKeys.ISADMIN, isAdmin);if (user.id_token) localStorage.setItem(localStorageKeys.ID_TOKEN, user.id_token);+ sessionStorage.removeItem(SIGNIN_GUARD_KEY);}async logout() {