Fix Teams tab SSO broken by SameSite=Lax session cookies#3246
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts the Teams tab SSO flow to work around Moodle core’s SameSite=Lax session cookie behavior (introduced in MDL-83526) which prevents the browser from retaining the session in a cross-site iframe, causing the post-SSO navigation to appear anonymous.
Changes:
- After a successful SSO login, re-emits the current session cookie with
SameSite=None; Secureto allow it to be accepted in the Teams iframe. - Gates the re-emission behind a “secure cookies” check.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.