Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #97: Fix for open redirect in logout function #99

Merged
merged 2 commits into from
Nov 11, 2023

Conversation

Cyber-Wo0dy
Copy link
Contributor

#97 This is a suggested change to the logout function, limiting redirection to the url address selected in the configuration or, if there is no valid url in the configuration, redirecting to the Moodle home page. ;)

public function user_logout_userkey() {
global $CFG, $USER;

$redirect = required_param('return', PARAM_URL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to change this line to $redirect = required_param('return', PARAM_LOCALURL); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well observed @dmitriim! Because in this suggestion I thought about the option of preserving the redirection to an external address, according to the url registered in "Logout redirection URL". In this case, I have a question: if we define it as PARAM_LOCALURL the redirection will only be possible to addresses related to the Moodle installation, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we define it as PARAM_LOCALURL the redirection will only be possible to addresses related to the Moodle installation, right?

Yes, that's correct.

In your patch you're using $this->config->redirecturl which potentially confused you. This config is set in Moodle and used to always redirect a user after logging out from Moodle. E.g. redirecting to IDP logout page so a user is logged out from all apps at once.

However, in context of this issue $redirect is coning from outside of Moodle. E.g. when an external app requires users to logout from Moodle and then come back to the app for some other actions.

Hope that makes more sense now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, @dmitriim! Thank you for the clarifications. I will make a new commit with your suggestion.

@dmitriim
Copy link
Member

dmitriim commented Nov 8, 2023

Hi @Cyber-Wo0dy! Thanks for proposed fix! Would be nice to support that fix with unit tests.

@dmitriim dmitriim merged commit cd71596 into catalyst:MOODLE_33PLUS Nov 11, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants