mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
With oauth2-login-style redirect and OIDC_REDIRECTION_ENABLED, the browser looped between WeKan and the identity provider until the provider started rate-limiting the repeated /authorize requests. Template.userFormsLayout.onCreated (client/components/main/layouts.js) fired the auto-redirect unconditionally on every render. Meteor's redirect-style OAuth has no dedicated callback route - the identity provider's callback bounces the browser back to this SAME sign-in page - and the login method that follows a successful callback completes asynchronously, racing this template's own re-render. When the auto-redirect check ran before that login had finished, it saw "not logged in yet" and fired a brand new navigation straight back to the provider, forever. Fixed with a one-shot sessionStorage flag (client/lib/oidcAutoRedirect.js) that survives the full-page round trip to the provider and back, so the bounce-back render does not re-fire the redirect. Cleared on both login success and login failure (config/accounts.js), so a later logout, or a genuine error, can still trigger the auto-redirect again rather than leaving the sign-in page permanently stuck the other way. Thanks to Alishara and xet7 ! Fixes #6681,
53 lines
2.3 KiB
JavaScript
53 lines
2.3 KiB
JavaScript
// #6681: OIDC_REDIRECTION_ENABLED auto-login sent the browser to the identity
|
|
// provider on EVERY render of the sign-in page (userFormsLayout), with no
|
|
// guard against re-firing. With `oauth2-login-style: redirect`, the IdP's
|
|
// callback lands back on that same sign-in page (Meteor's redirect-style
|
|
// OAuth has no dedicated callback route of its own) - and the actual login
|
|
// method call that follows a successful callback completes asynchronously,
|
|
// racing against this page's own re-render. When the auto-redirect check ran
|
|
// before that login had finished, it saw "not logged in" and fired a BRAND
|
|
// new navigation straight back to the identity provider, forever - until the
|
|
// provider started rate-limiting the repeated /authorize hits (the reporter's
|
|
// exact symptom: Microsoft Entra ID blocking further attempts).
|
|
//
|
|
// The fix: a one-shot flag in sessionStorage (survives the full-page
|
|
// navigation to the IdP and back, cleared when the tab closes) marks that
|
|
// this tab already sent the browser once. A second render of the sign-in
|
|
// page - the callback bounce-back - sees the flag and does NOT navigate
|
|
// again, leaving Meteor's own oauth completion to finish the login
|
|
// undisturbed. The flag is cleared on both a successful login and a login
|
|
// failure (config/accounts.js), so a genuine later logout, or a real error,
|
|
// can still trigger the auto-redirect again rather than being stuck forever
|
|
// the other way.
|
|
const OIDC_AUTO_REDIRECT_FLAG = 'wekan-oidc-auto-redirect-pending';
|
|
|
|
// sessionStorage can throw (private browsing in some older browsers, storage
|
|
// disabled by policy). Failing OPEN (treat as "not yet redirected") matches
|
|
// this code's behavior before the flag existed at all, rather than turning a
|
|
// storage restriction into a second, different way to break the same login.
|
|
function readFlag() {
|
|
try {
|
|
return sessionStorage.getItem(OIDC_AUTO_REDIRECT_FLAG) === '1';
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function setFlag() {
|
|
try {
|
|
sessionStorage.setItem(OIDC_AUTO_REDIRECT_FLAG, '1');
|
|
} catch (error) {
|
|
// Nothing to do: the auto-redirect will simply be able to fire again.
|
|
}
|
|
}
|
|
|
|
function clearFlag() {
|
|
try {
|
|
sessionStorage.removeItem(OIDC_AUTO_REDIRECT_FLAG);
|
|
} catch (error) {
|
|
// Nothing to do.
|
|
}
|
|
}
|
|
|
|
export const OidcAutoRedirect = { hasAlreadyFired: readFlag, markFired: setFlag, clear: clearFlag };
|