Skip to content

Commit a6e7932

Browse files
authored
Merge pull request #6662 from AngelFQC/p32q-6gh3-3gcv
Course description: Remove XSS when showing title
2 parents 857d594 + b21663f commit a6e7932

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

main/inc/ajax/course_home.ajax.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/* For licensing terms, see /license.txt */
33

4+
use Chamilo\CourseBundle\Entity\CCourseDescription;
45
use Chamilo\CourseBundle\Entity\CTool;
56
use ChamiloSession as Session;
67

@@ -290,15 +291,17 @@
290291
echo get_lang('PrivateAccess');
291292
break;
292293
}
293-
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
294-
$sql = "SELECT * FROM $table
295-
WHERE c_id = ".$course_info['real_id']." AND session_id = 0
296-
ORDER BY id";
297-
$result = Database::query($sql);
298-
if (Database::num_rows($result) > 0) {
299-
while ($description = Database::fetch_object($result)) {
300-
$descriptions[$description->id] = $description;
301-
}
294+
295+
/** @var array<int, CCourseDescription> $courseDescriptions */
296+
$courseDescriptions = Database::getManager()
297+
->getRepository(CCourseDescription::class)
298+
->findBy(['cId' => $course_info['real_id'], 'sessionId' => 0])
299+
;
300+
301+
$descriptions = [];
302+
303+
foreach ($courseDescriptions as $courseDescription) {
304+
$descriptions[$courseDescription->getIid()] = $courseDescription;
302305
// Function that displays the details of the course description in html.
303306
$content = CourseManager::get_details_course_description_html(
304307
$descriptions,

main/inc/lib/course.lib.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Chamilo\CoreBundle\Entity\SequenceResource;
99
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
1010
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
11+
use Chamilo\CourseBundle\Entity\CCourseDescription;
1112
use ChamiloSession as Session;
1213
use Doctrine\Common\Collections\Criteria;
1314

@@ -3442,24 +3443,24 @@ public static function getExtraFieldsToBePresented($courseId)
34423443
/**
34433444
* Lists details of the course description.
34443445
*
3445-
* @param array The course description
3446-
* @param string The encoding
3447-
* @param bool If true is displayed if false is hidden
3446+
* @param array<int, CCourseDescription> $descriptions The course description
3447+
* @param string $charset The encoding
3448+
* @param bool $action_show If true is displayed if false is hidden
34483449
*
34493450
* @return string The course description in html
34503451
*/
34513452
public static function get_details_course_description_html(
3452-
$descriptions,
3453-
$charset,
3454-
$action_show = true
3455-
) {
3453+
array $descriptions,
3454+
string $charset,
3455+
bool $action_show = true
3456+
): ?string {
34563457
$data = null;
3457-
if (isset($descriptions) && count($descriptions) > 0) {
3458+
if (count($descriptions) > 0) {
34583459
foreach ($descriptions as $description) {
34593460
$data .= '<div class="sectiontitle">';
34603461
if (api_is_allowed_to_edit() && $action_show) {
34613462
//delete
3462-
$data .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete&description_id='.$description->id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(
3463+
$data .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete&description_id='.$description->getIid().'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(
34633464
get_lang('ConfirmYourChoice'),
34643465
ENT_QUOTES,
34653466
$charset
@@ -3471,7 +3472,7 @@ public static function get_details_course_description_html(
34713472
);
34723473
$data .= '</a> ';
34733474
//edit
3474-
$data .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&description_id='.$description->id.'">';
3475+
$data .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&description_id='.$description->getIid().'">';
34753476
$data .= Display::return_icon(
34763477
'edit.png',
34773478
get_lang('Edit'),
@@ -3480,10 +3481,10 @@ public static function get_details_course_description_html(
34803481
);
34813482
$data .= '</a> ';
34823483
}
3483-
$data .= $description->title;
3484+
$data .= Security::remove_XSS($description->getTitle());
34843485
$data .= '</div>';
34853486
$data .= '<div class="sectioncomment">';
3486-
$data .= Security::remove_XSS($description->content);
3487+
$data .= Security::remove_XSS($description->getContent());
34873488
$data .= '</div>';
34883489
}
34893490
} else {

0 commit comments

Comments
 (0)