diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index f2fc6806093..bd49699e398 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -297,11 +297,6 @@ class api { throw new moodle_exception('enablewsdescription', 'webservice'); } - // Only requests from the Moodle mobile or desktop app. This enhances security to avoid any type of XSS attack. - if (!\core_useragent::is_moodle_app()) { - throw new moodle_exception('apprequired', 'tool_mobile'); - } - if (!is_https()) { throw new moodle_exception('httpsrequired', 'tool_mobile'); } diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php index 830c0602390..1650d220861 100644 --- a/admin/tool/mobile/classes/external.php +++ b/admin/tool/mobile/classes/external.php @@ -286,6 +286,13 @@ class external extends external_api { } } + + // Only requests from the Moodle mobile or desktop app. This enhances security to avoid any type of XSS attack. + // This code goes intentionally here and not inside the check_autologin_prerequisites() function because it + // is used by other PHP scripts that can be opened in any browser. + if (!\core_useragent::is_moodle_app()) { + throw new moodle_exception('apprequired', 'tool_mobile'); + } api::check_autologin_prerequisites($USER->id); if (isset($_GET['privatetoken']) or empty($privatetoken)) {