From d88aa76c773170e8c396d767c00245d07d2c0e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 5 Jan 2017 13:20:59 +0100 Subject: [PATCH] MDL-57580 mod_assign: Fix the incorrect type of some input parameters The PARAM_TEXT has been misused in certain cases here. The 'action' parameter seems to always be alphabetic, with values like savesubmission, editsubmission and others as handled in assign::view(). Fixing the action handling fixes the reported XSS issue. While working on it, I spotted two more places where PARAM_TEXT does not seem appropriate. I include changes for them too, even if they are no strictly related to the reported bug and there are no known ways to abuse it. * The 'plugin' looks like PARAM_PLUGIN and is even declared as such in some other parts of the assignment code (such as feedback forms). * The 'workflowstate' is one of the ASSIGN_MARKING_WORKFLOW_STATE constants and is supposed to be alpha in external function input parameters handling, too. --- mod/assign/externallib.php | 4 ++-- mod/assign/locallib.php | 8 ++++---- mod/assign/view.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index 6f0e4ee5c38..f2ab0750ab6 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -780,7 +780,7 @@ class mod_assign_external extends external_api { 'locked' => new external_value(PARAM_INT, 'locked', VALUE_OPTIONAL), 'mailed' => new external_value(PARAM_INT, 'mailed', VALUE_OPTIONAL), 'extensionduedate' => new external_value(PARAM_INT, 'extension due date', VALUE_OPTIONAL), - 'workflowstate' => new external_value(PARAM_TEXT, 'marking workflow state', VALUE_OPTIONAL), + 'workflowstate' => new external_value(PARAM_ALPHA, 'marking workflow state', VALUE_OPTIONAL), 'allocatedmarker' => new external_value(PARAM_INT, 'allocated marker', VALUE_OPTIONAL) ) ) @@ -1036,7 +1036,7 @@ class mod_assign_external extends external_api { 'locked' => new external_value(PARAM_INT, 'locked'), 'mailed' => new external_value(PARAM_INT, 'mailed'), 'extensionduedate' => new external_value(PARAM_INT, 'extension due date'), - 'workflowstate' => new external_value(PARAM_TEXT, 'marking workflow state', VALUE_OPTIONAL), + 'workflowstate' => new external_value(PARAM_ALPHA, 'marking workflow state', VALUE_OPTIONAL), 'allocatedmarker' => new external_value(PARAM_INT, 'allocated marker') ) ) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index cbf9535c0f5..482d5b53360 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -2212,7 +2212,7 @@ class assign { $o = ''; $pluginsubtype = required_param('pluginsubtype', PARAM_ALPHA); - $plugintype = required_param('plugin', PARAM_TEXT); + $plugintype = required_param('plugin', PARAM_PLUGIN); $pluginaction = required_param('pluginaction', PARAM_ALPHA); $plugin = $this->get_plugin_by_type($pluginsubtype, $plugintype); @@ -2268,7 +2268,7 @@ class assign { $submissionid = optional_param('sid', 0, PARAM_INT); $gradeid = optional_param('gid', 0, PARAM_INT); - $plugintype = required_param('plugin', PARAM_TEXT); + $plugintype = required_param('plugin', PARAM_PLUGIN); $item = null; if ($pluginsubtype == 'assignsubmission') { $plugin = $this->get_submission_plugin_by_type($plugintype); @@ -5119,7 +5119,7 @@ class assign { $record->userid = $userid; if ($modified >= 0) { $record->grade = unformat_float(optional_param('quickgrade_' . $record->userid, -1, PARAM_TEXT)); - $record->workflowstate = optional_param('quickgrade_' . $record->userid.'_workflowstate', false, PARAM_TEXT); + $record->workflowstate = optional_param('quickgrade_' . $record->userid.'_workflowstate', false, PARAM_ALPHA); $record->allocatedmarker = optional_param('quickgrade_' . $record->userid.'_allocatedmarker', false, PARAM_INT); } else { // This user was not in the grading table. @@ -6213,7 +6213,7 @@ class assign { $mform->setType('userid', PARAM_INT); $mform->addElement('hidden', 'action', 'savesubmission'); - $mform->setType('action', PARAM_TEXT); + $mform->setType('action', PARAM_ALPHA); } /** diff --git a/mod/assign/view.php b/mod/assign/view.php index 9fa7e24395d..88fb5f8084d 100644 --- a/mod/assign/view.php +++ b/mod/assign/view.php @@ -28,7 +28,7 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php'); $id = required_param('id', PARAM_INT); $urlparams = array('id' => $id, - 'action' => optional_param('action', '', PARAM_TEXT), + 'action' => optional_param('action', '', PARAM_ALPHA), 'rownum' => optional_param('rownum', 0, PARAM_INT), 'useridlistid' => optional_param('action', 0, PARAM_INT)); @@ -50,4 +50,4 @@ $completion->set_module_viewed($cm); // Get the assign class to // render the page. -echo $assign->view(optional_param('action', '', PARAM_TEXT)); +echo $assign->view(optional_param('action', '', PARAM_ALPHA));