After updating to release 4.5.6, direct Moodle activity links no longer preserve the original wantsurl after Microsoft / OpenID Connect login.
Description
When a user opens a direct link to a protected Moodle activity, for example https://example.com/mod/quiz/view.php?id=7209, the previous behavior was:
Direct activity link -> Moodle login -> Microsoft login -> back to the activity
The current behavior is:
Direct activity link -> Moodle login -> Microsoft login -> Moodle default page
The user is authenticated successfully, but the original activity URL is lost. Manual Moodle authentication still redirects correctly, so the issue seems specific to the Microsoft / OpenID Connect login flow.
Environment
- Moodle: 4.5.11+
- auth_oidc: 4.5.6
- local_o365: 4.5.6
- Login flow:
authcode
forceredirect: disabled
silentloginmode: disabled
forcelogin: disabled
alternateloginurl: empty
- Auto-login guests: disabled
Workaround tested successfully
We were able to fix the issue by preserving $SESSION->wantsurl in the existing OIDC state additional data, then restoring it after the OIDC callback before the final redirect.
File: auth/oidc/classes/loginflow/authcode.php
After $stateparams = ['forceflow' => 'authcode'];, add:
if (!empty($SESSION->wantsurl) && strpos($SESSION->wantsurl, $CFG->wwwroot) === 0) { $stateparams['wantsurl'] = $SESSION->wantsurl; }
After $this->handlelogin($oidcuniqid, $authparams, $tokenparams, $idtoken);, add:
if (!empty($additionaldata['wantsurl']) && strpos($additionaldata['wantsurl'], $CFG->wwwroot) === 0) { $SESSION->wantsurl = $additionaldata['wantsurl']; }
After purging Moodle caches, direct activity links correctly redirect back to the original activity after Microsoft login.
Expected behavior
After Microsoft / OpenID Connect authentication, users should be redirected back to the original Moodle URL stored in wantsurl.
Actual behavior
Users are redirected to the Moodle default page instead of the original activity.
Security note
The workaround validates that the restored URL starts with $CFG->wwwroot before assigning it back to $SESSION->wantsurl, to avoid open redirect issues.
After updating to release 4.5.6, direct Moodle activity links no longer preserve the original
wantsurlafter Microsoft / OpenID Connect login.Description
When a user opens a direct link to a protected Moodle activity, for example
https://example.com/mod/quiz/view.php?id=7209, the previous behavior was:Direct activity link -> Moodle login -> Microsoft login -> back to the activity
The current behavior is:
Direct activity link -> Moodle login -> Microsoft login -> Moodle default page
The user is authenticated successfully, but the original activity URL is lost. Manual Moodle authentication still redirects correctly, so the issue seems specific to the Microsoft / OpenID Connect login flow.
Environment
authcodeforceredirect: disabledsilentloginmode: disabledforcelogin: disabledalternateloginurl: emptyWorkaround tested successfully
We were able to fix the issue by preserving
$SESSION->wantsurlin the existing OIDC state additional data, then restoring it after the OIDC callback before the final redirect.File:
auth/oidc/classes/loginflow/authcode.phpAfter
$stateparams = ['forceflow' => 'authcode'];, add:if (!empty($SESSION->wantsurl) && strpos($SESSION->wantsurl, $CFG->wwwroot) === 0) { $stateparams['wantsurl'] = $SESSION->wantsurl; }After
$this->handlelogin($oidcuniqid, $authparams, $tokenparams, $idtoken);, add:if (!empty($additionaldata['wantsurl']) && strpos($additionaldata['wantsurl'], $CFG->wwwroot) === 0) { $SESSION->wantsurl = $additionaldata['wantsurl']; }After purging Moodle caches, direct activity links correctly redirect back to the original activity after Microsoft login.
Expected behavior
After Microsoft / OpenID Connect authentication, users should be redirected back to the original Moodle URL stored in
wantsurl.Actual behavior
Users are redirected to the Moodle default page instead of the original activity.
Security note
The workaround validates that the restored URL starts with
$CFG->wwwrootbefore assigning it back to$SESSION->wantsurl, to avoid open redirect issues.