Skip to content

Commit b22c456

Browse files
committed
MDL-85333 mod_lti: Update sesskey handling for LTI pages
1 parent dcf9426 commit b22c456

8 files changed

Lines changed: 39 additions & 23 deletions

File tree

public/mod/lti/classes/output/tool_configure_page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function export_for_template(renderer_base $output) {
5353
$keyhelp = new help_icon('resourcekey', 'mod_lti');
5454
$secrethelp = new help_icon('password', 'mod_lti');
5555

56-
$url = new moodle_url('/mod/lti/typessettings.php', array('sesskey' => sesskey(), 'returnto' => 'toolconfigure'));
56+
$url = new moodle_url('/mod/lti/typessettings.php', ['returnto' => 'toolconfigure']);
5757
$data->configuremanualurl = $url->out();
5858
$url = new moodle_url('/admin/settings.php?section=modsettinglti');
5959
$data->managetoolsurl = $url->out();

public/mod/lti/locallib.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,7 @@ function lti_get_tool_table($tools, $id) {
17691769

17701770
$updateurl = clone($baseurl);
17711771
$updateurl->param('action', 'update');
1772+
$updateurl->remove_params('sesskey');
17721773
$updatehtml = $OUTPUT->action_icon($updateurl,
17731774
new \pix_icon('t/edit', $update, '', array('class' => 'iconsmall')), null,
17741775
array('title' => $update, 'class' => 'editing_update'));
@@ -1871,6 +1872,7 @@ function lti_get_tool_proxy_table($toolproxies, $id) {
18711872

18721873
$updateurl = clone($baseurl);
18731874
$updateurl->param('action', 'update');
1875+
$updateurl->remove_params('sesskey');
18741876
$updatehtml = $OUTPUT->action_icon($updateurl,
18751877
new \pix_icon('t/edit', $update, '', array('class' => 'iconsmall')), null,
18761878
array('title' => $update, 'class' => 'editing_update'));
@@ -4073,8 +4075,11 @@ function get_tool_type_icon_url(stdClass $type) {
40734075
* @return string The url to edit the tool type
40744076
*/
40754077
function get_tool_type_edit_url(stdClass $type) {
4076-
$url = new moodle_url('/mod/lti/typessettings.php',
4077-
array('action' => 'update', 'id' => $type->id, 'sesskey' => sesskey(), 'returnto' => 'toolconfigure'));
4078+
$url = new moodle_url('/mod/lti/typessettings.php', [
4079+
'action' => 'update',
4080+
'id' => $type->id,
4081+
'returnto' => 'toolconfigure',
4082+
]);
40784083
return $url->out();
40794084
}
40804085

@@ -4086,8 +4091,11 @@ function get_tool_type_edit_url(stdClass $type) {
40864091
* @return string The url to edit the tool type
40874092
*/
40884093
function get_tool_proxy_edit_url(stdClass $proxy) {
4089-
$url = new moodle_url('/mod/lti/registersettings.php',
4090-
array('action' => 'update', 'id' => $proxy->id, 'sesskey' => sesskey(), 'returnto' => 'toolconfigure'));
4094+
$url = new moodle_url('/mod/lti/registersettings.php', [
4095+
'action' => 'update',
4096+
'id' => $proxy->id,
4097+
'returnto' => 'toolconfigure',
4098+
]);
40914099
return $url->out();
40924100
}
40934101

public/mod/lti/registersettings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@
6161
$redirect = $returnurl;
6262
}
6363

64-
require_sesskey();
65-
6664
if ($action == 'delete') {
65+
require_sesskey();
6766
lti_delete_tool_proxy($id);
6867
redirect($redirect);
6968
}
@@ -81,6 +80,7 @@
8180
if ($form->is_cancelled()) {
8281
redirect($redirect);
8382
} else if ($data = $form->get_data()) {
83+
require_sesskey();
8484
$id = lti_add_tool_proxy($data);
8585
redirect($redirect);
8686
} else {

public/mod/lti/settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
$addtype = get_string('addtype', 'lti');
132132
$config = get_string('manage_tool_proxies', 'lti');
133133

134-
$addtypeurl = "{$CFG->wwwroot}/mod/lti/typessettings.php?action=add&sesskey={$USER->sesskey}";
134+
$addtypeurl = "{$CFG->wwwroot}/mod/lti/typessettings.php?action=add";
135135

136136
$template = <<< EOD
137137
<div id="lti_tabs" class="yui-navset">

public/mod/lti/templates/tool_configure.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
3232
Example context (json):
3333
{
34-
"configuremanualurl":"https://some.tool.example/mod/lti/typessettings.php?sesskey=OKl37bHflL&amp;returnto=toolconfigure",
34+
"configuremanualurl":"https://some.tool.example/mod/lti/typessettings.php?returnto=toolconfigure",
3535
"managetoolsurl":"https://some.tool.example/admin/settings.php?section=modsettinglti",
3636
"managetoolproxiesurl":"https://some.tool.example/mod/lti/toolproxies.php"
3737
}

public/mod/lti/toolproxies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
$registertype = get_string('registertype', 'lti');
8989
$config = get_string('manage_tools', 'lti');
9090

91-
$registertypeurl = "{$CFG->wwwroot}/mod/lti/registersettings.php?action=add&amp;sesskey={$USER->sesskey}&amp;tab=tool_proxy";
91+
$registertypeurl = "{$CFG->wwwroot}/mod/lti/registersettings.php?action=add&amp;tab=tool_proxy";
9292

9393
$template = <<< EOD
9494
<div id="tp_tabs" class="yui-navset">

public/mod/lti/toolssettings.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@
4343
// No guest autologin.
4444
require_login(0, false);
4545

46-
require_sesskey();
47-
4846
// Check this is for a tool created from a tool proxy.
4947
$err = empty($id);
5048
if (!$err) {
5149
$type = lti_get_type_type_config($id);
5250
$err = empty($type->toolproxyid);
5351
}
5452
if ($err) {
55-
$params = array('action' => $action, 'id' => $id, 'sesskey' => sesskey(), 'tab' => $tab);
56-
if (!empty($returnto)) {
57-
$params['returnto'] = $returnto;
58-
}
53+
$params = array_filter([
54+
'action' => $action,
55+
'id' => $id,
56+
'sesskey' => optional_param('sesskey', '', PARAM_RAW),
57+
'tab' => $tab,
58+
'returnto' => $returnto,
59+
]);
5960
$redirect = new moodle_url('/mod/lti/typessettings.php', $params);
6061
redirect($redirect);
6162
}
@@ -77,9 +78,11 @@
7778
}
7879

7980
if ($action == 'accept') {
81+
require_sesskey();
8082
lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
8183
redirect($redirect);
8284
} else if (($action == 'reject') || ($action == 'delete')) {
85+
require_sesskey();
8386
lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
8487
redirect($redirect);
8588
}
@@ -93,6 +96,7 @@
9396
$form = new mod_lti_edit_types_form($pageurl, (object)array('isadmin' => true, 'istool' => true));
9497

9598
if ($data = $form->get_data()) {
99+
require_sesskey();
96100
$type = new stdClass();
97101
if (!empty($id)) {
98102
$type->id = $id;

public/mod/lti/typessettings.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@
6565
// No guest autologin.
6666
require_login(0, false);
6767

68-
require_sesskey();
69-
7068
// Check this is not for a tool created from a tool proxy.
7169
if (!empty($id)) {
7270
$type = lti_get_type_type_config($id);
7371
if (!empty($type->toolproxyid)) {
74-
$sesskey = required_param('sesskey', PARAM_RAW);
75-
$params = array('action' => $action, 'id' => $id, 'sesskey' => $sesskey, 'tab' => $tab);
76-
if (!empty($returnto)) {
77-
$params['returnto'] = $returnto;
78-
}
72+
$params = array_filter([
73+
'action' => $action,
74+
'id' => $id,
75+
'sesskey' => optional_param('sesskey', '', PARAM_RAW),
76+
'tab' => $tab,
77+
'returnto' => $returnto,
78+
]);
7979
$redirect = new moodle_url('/mod/lti/toolssettings.php', $params);
8080
redirect($redirect);
8181
}
@@ -111,12 +111,15 @@
111111
}
112112

113113
if ($action == 'accept') {
114+
require_sesskey();
114115
lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
115116
redirect($redirect);
116117
} else if ($action == 'reject') {
118+
require_sesskey();
117119
lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
118120
redirect($redirect);
119121
} else if ($action == 'delete') {
122+
require_sesskey();
120123
lti_delete_type($id);
121124
redirect($redirect);
122125
}
@@ -140,6 +143,7 @@
140143
);
141144

142145
if ($data = $form->get_data()) {
146+
require_sesskey();
143147
$type = new stdClass();
144148
if (!empty($id)) {
145149
$type->id = $id;

0 commit comments

Comments
 (0)