Skip to content

Commit 8b028b8

Browse files
AngelFQCclaude
andcommitted
Security: enforce CSRF token on gradebook evaluation add/edit forms
The gradebook evaluation add and edit forms (EvalForm/FormValidator) were state-changing POST endpoints with no anti-CSRF token. FormValidator does not inject a CSRF token on its own, so the forms accepted forged cross-site submissions. Add the standard Chamilo legacy idiom: validate Security::check_token('post') before persisting (api_not_allowed on failure, clear_token on success) and emit a fresh sec_token hidden field on the display path, mirroring the pattern already used in exercise/tests_category.php and group/settings.php. Refs GHSA-vjmr-7vxh-wpg2 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 996c4f1 commit 8b028b8

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

public/main/gradebook/gradebook_add_eval.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
);
3232

3333
if ($form->validate()) {
34+
if (!Security::check_token('post')) {
35+
api_not_allowed(true);
36+
}
37+
Security::clear_token();
3438
$values = $form->exportValues();
3539
$entityManager = Database::getManager();
3640
$course = $entityManager->getRepository(Course::class)->find(api_get_course_int_id());
@@ -166,5 +170,9 @@
166170

167171
echo '</div>';
168172

173+
$token = Security::get_token();
174+
$form->addElement('hidden', 'sec_token');
175+
$form->setConstants(['sec_token' => $token]);
176+
169177
$form->display();
170178
Display::display_footer();

public/main/gradebook/gradebook_edit_eval.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
api_get_self().'?editeval='.intval($_GET['editeval']).'&'.api_get_cidreq()
3737
);
3838
if ($form->validate()) {
39+
if (!Security::check_token('post')) {
40+
api_not_allowed(true);
41+
}
42+
Security::clear_token();
3943
$values = $form->exportValues();
4044

4145
$entityManager = Database::getManager();
@@ -106,5 +110,10 @@
106110
</script>';
107111

108112
Display::display_header(get_lang('Edit evaluation'));
113+
114+
$token = Security::get_token();
115+
$form->addElement('hidden', 'sec_token');
116+
$form->setConstants(['sec_token' => $token]);
117+
109118
$form->display();
110119
Display::display_footer();

0 commit comments

Comments
 (0)