Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Verifies if https enabled only secure cookies allowed
  19   *
  20   * This prevents redirections and sending of cookies to unsecure port.
  21   *
  22   * @package    core
  23   * @category   check
  24   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  25   * @copyright  2008 petr Skoda
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  
  29  namespace core\check\http;
  30  
  31  defined('MOODLE_INTERNAL') || die();
  32  
  33  use core\check\check;
  34  use core\check\result;
  35  
  36  /**
  37   * Verifies if https enabled only secure cookies allowed
  38   *
  39   * This prevents redirections and sending of cookies to unsecure port.
  40   *
  41   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  42   * @copyright  2008 petr Skoda
  43   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44   */
  45  class cookiesecure extends check {
  46  
  47      /**
  48       * Get the short check name
  49       *
  50       * @return string
  51       */
  52      public function get_name(): string {
  53          return get_string('check_cookiesecure_name', 'report_security');
  54      }
  55  
  56      /**
  57       * A link to a place to action this
  58       *
  59       * @return action_link|null
  60       */
  61      public function get_action_link(): ?\action_link {
  62          return new \action_link(
  63              new \moodle_url('/admin/settings.php?section=httpsecurity#admin-cookiesecure'),
  64              get_string('httpsecurity', 'admin'));
  65      }
  66  
  67      /**
  68       * Return result
  69       * @return result
  70       */
  71      public function get_result(): result {
  72          global $CFG;
  73          $details = get_string('check_cookiesecure_details', 'report_security');
  74          if (!is_https()) {
  75              $status = result::WARNING;
  76              $summary = get_string('check_cookiesecure_http', 'report_security');
  77              return new result($status, $summary, $details);
  78          }
  79  
  80          if (!is_moodle_cookie_secure()) {
  81              $status = result::ERROR;
  82              $summary = get_string('check_cookiesecure_error', 'report_security');
  83          } else {
  84              $status = result::OK;
  85              $summary = get_string('check_cookiesecure_ok', 'report_security');
  86          }
  87          return new result($status, $summary, $details);
  88      }
  89  }
  90