Fix Teams tab SSO broken by SameSite=Lax session cookies#3247
Open
patmr7 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses Microsoft Teams tab SSO failures caused by Moodle core setting the session cookie SameSite=Lax, which is not accepted in a cross-site iframe context. After a successful SSO login, it re-emits the session cookie with SameSite=None; Secure so the browser will retain the authenticated session when embedded in Teams.
Changes:
- After successful Teams SSO (
$loginsuccess), re-emit the PHP session cookie withSameSite=None; Secure. - Preserve the existing behavior of returning
200on success and401on failure.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+172
to
+182
| // The session cookie set by core carries SameSite=Lax (MDL-83526), which browsers reject in | ||
| // the cross-site iframe of the Teams tab, so re-emit it with "SameSite=None; Secure". | ||
| if (is_moodle_cookie_secure()) { | ||
| setcookie(session_name(), session_id(), [ | ||
| 'path' => $CFG->sessioncookiepath, | ||
| 'domain' => $CFG->sessioncookiedomain, | ||
| 'secure' => true, | ||
| 'httponly' => (bool) $CFG->cookiehttponly, | ||
| 'samesite' => 'None', | ||
| ]); | ||
| } |
Since MDL-83526 (Moodle 4.5.12, 5.0.8, 5.1.5 and 5.2.1), core sets SameSite=Lax on the session cookie, which browsers reject in the cross-site iframe of the Teams tab. The SSO login in sso_login.php succeeded server-side, but the browser dropped the cookie and the subsequent course page request was anonymous, showing the login page. Re-emit the session cookie with "SameSite=None; Secure" after a successful SSO login, mirroring the exception core makes for the Moodle mobile app. Fix Teams tab SSO broken by SameSite=Lax session cookies Since MDL-83526 (Moodle 4.5.12, 5.0.8, 5.1.5 and 5.2.1), core sets SameSite=Lax on the session cookie, which browsers reject in the cross-site iframe of the Teams tab. The SSO login in sso_login.php succeeded server-side, but the browser dropped the cookie and the subsequent course page request was anonymous, showing the login page. Re-emit the session cookie with "SameSite=None; Secure" after a successful SSO login, mirroring the exception core makes for the Moodle mobile app.
Since MDL-83526 (Moodle 4.5.12, 5.0.8, 5.1.5 and 5.2.1), core sets SameSite=Lax on the session cookie, which browsers reject in the cross-site iframe of the Teams tab. The SSO login in sso_login.php succeeded server-side, but the browser dropped the cookie and the subsequent course page request was anonymous, showing the login page. Re-emit the session cookie with "SameSite=None; Secure" after a successful SSO login, mirroring the exception core makes for the Moodle mobile app. Fix Teams tab SSO broken by SameSite=Lax session cookies Since MDL-83526 (Moodle 4.5.12, 5.0.8, 5.1.5 and 5.2.1), core sets SameSite=Lax on the session cookie, which browsers reject in the cross-site iframe of the Teams tab. The SSO login in sso_login.php succeeded server-side, but the browser dropped the cookie and the subsequent course page request was anonymous, showing the login page. Re-emit the session cookie with "SameSite=None; Secure" after a successful SSO login, mirroring the exception core makes for the Moodle mobile app.
Comment on lines
+183
to
+190
| $cookieparams = session_get_cookie_params(); | ||
| setcookie(session_name(), session_id(), [ | ||
| 'path' => $cookieparams['path'], | ||
| 'domain' => $cookieparams['domain'], | ||
| 'secure' => true, | ||
| 'httponly' => $cookieparams['httponly'], | ||
| 'samesite' => 'None', | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since MDL-83526 (Moodle 4.5.12, 5.0.8, 5.1.5 and 5.2.1), core sets SameSite=Lax on the session cookie, which browsers reject in the cross-site iframe of the Teams tab. The SSO login in sso_login.php succeeded server-side, but the browser dropped the cookie and the subsequent course page request was anonymous, showing the login page.
Re-emit the session cookie with "SameSite=None; Secure" after a successful SSO login, mirroring the exception core makes for the Moodle mobile app.