Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-23184

Use of optional_param() with PARAM_CLEAN and enablehtmlpurifier on produces unwanted HTML entities

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Libraries
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      When using the lib/moodlelib.php function optional_param() with PARAM_CLEAN (or PARAM_TEXT) to clean input parameters, unexpected and unwanted effects may be caused if the HTML purifier is enabled ($CFG->enablehtmlpurifier).

      This seems to be because optional_param() in turn calls clean_param(), which itself calls clean_text() (in lib/weblib.php). The default $format parameter in clean_text() is FORMAT_MOODLE, and clean_param() does not specify any alternative.

      The problem shows up if, for example, a parameter with an ampersand in its value is read in using optional_param() with the PARAM_CLEAN setting. For example, "This & that". With the HTML Purifier enabled, this gets returned from optional_param() as "This & that". That might be fine if the value were intended to be displayed, but this is input, so is more likely to be used for other purposes; for example, a database search.

      A workaround for this is to use PARAM_RAW or PARAM_NOTAGS for text input that might potentially not work if mangled with HTML entities, but there is potential for this to cause unintended problems if, say, a plugin is developed using PARAM_CLEAN without the HTML Purifier on, and then deployed in a Moodle that does have it on.

      Example output of attached script:

      With HTML purifier off, $value matches $expected
      With HTML purifier on, $value (This & that) does not match $expected (This & that)

        Attachments

          Activity

            People

            Assignee:
            skodak Petr Skoda
            Reporter:
            darenc Daren Chandisingh
            Tester:
            Nobody
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              24/Nov/10