Skip to content

Commit fe09c59

Browse files
[Survey] fix: Use correct HTMLPurifier to process inputs (#11287)
* fix: Use correct HTMLPurifier to process inputs * fix: Add strict types declaration
1 parent b8b844d commit fe09c59

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

components/ILIAS/Survey/Editing/class.ilSurveyEditorGUI.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*
1717
*********************************************************************/
1818

19+
declare(strict_types=1);
20+
1921
use ILIAS\Survey\Editing\EditManager;
2022
use ILIAS\Survey\Editing\EditingGUIRequest;
2123

@@ -48,6 +50,7 @@ class ilSurveyEditorGUI
4850
protected ilObjSurveyGUI $parent_gui;
4951
protected ilObjSurvey $object;
5052
protected array $print_options;
53+
protected \ilHtmlPurifierInterface $purifier;
5154

5255
public function __construct(ilObjSurveyGUI $a_parent_gui)
5356
{
@@ -72,6 +75,7 @@ public function __construct(ilObjSurveyGUI $a_parent_gui)
7275
$this->tpl = $tpl;
7376

7477
$this->ctrl->saveParameter($this, array("pgov", "pgov_pos"));
78+
$this->purifier = new ilSvyStandardPurifier();
7579

7680
$this->print_options = array(
7781
//0 => $this->lng->txt('none'),
@@ -962,6 +966,8 @@ protected function initHeadingForm(
962966
$heading->setRows(10);
963967
$heading->setCols(80);
964968
$heading->setRequired(true);
969+
$heading->usePurifier(true);
970+
$heading->setPurifier($this->purifier);
965971
$form->addItem($heading);
966972

967973
$insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
@@ -1027,12 +1033,7 @@ public function saveHeadingObject(): void
10271033

10281034
$form = $this->initHeadingForm($q_id);
10291035
if ($form->checkInput()) {
1030-
$tags = ilObjAdvancedEditing::_getUsedHTMLTags("survey");
1031-
$purifier = new HTMLPurifier($tags);
1032-
$heading = $form->getInput("heading");
1033-
1034-
$heading = $purifier->purify($heading);
1035-
1036+
$heading = $this->purifier->purify($form->getInput("heading"));
10361037
$this->object->saveHeading($heading, $form->getInput("insertbefore"));
10371038
$this->ctrl->redirect($this, "questions");
10381039
}

components/ILIAS/Survey/Settings/class.SettingsFormGUI.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
namespace ILIAS\Survey\Settings;
2222

23-
use HTMLPurifier;
2423
use ILIAS\Survey\InternalGUIService;
2524
use ILIAS\Survey\Mode\UIModifier;
2625
use ILIAS\Survey\InternalDomainService;
@@ -40,13 +39,15 @@ class SettingsFormGUI
4039
protected \ILIAS\Survey\Mode\FeatureConfig $feature_config;
4140
protected \ilRbacSystem $rbacsystem;
4241
private \ilGlobalTemplateInterface $main_tpl;
42+
protected \ilHtmlPurifierInterface $purifier;
4343

4444
public function __construct(
4545
InternalGUIService $ui_service,
4646
InternalDomainService $domain_service,
4747
\ilObjectService $object_service,
4848
\ilObjSurvey $survey,
49-
UIModifier $modifier
49+
UIModifier $modifier,
50+
\ilHtmlPurifierInterface $purifier
5051
) {
5152
global $DIC;
5253
$this->main_tpl = $DIC->ui()->mainTemplate();
@@ -59,6 +60,7 @@ public function __construct(
5960
$this->domain_service = $domain_service;
6061
$this->modifier = $modifier;
6162
$this->feature_config = $this->domain_service->modeFeatureConfig($survey->getMode());
63+
$this->purifier = $purifier;
6264
}
6365

6466
public function checkForm(\ilPropertyFormGUI $form): bool
@@ -334,6 +336,9 @@ public function withBeforeStart(
334336
$intro->setUseRte(true);
335337
$intro->setRteTagSet("mini");
336338
}
339+
$intro->usePurifier(true);
340+
$intro->setPurifier(new \ilSvyStandardPurifier());
341+
337342
$form->addItem($intro);
338343

339344
return $form;
@@ -452,6 +457,8 @@ public function withAfterEnd(
452457
$finalstatement->setUseRte(true);
453458
$finalstatement->setRteTagSet("mini");
454459
}
460+
$finalstatement->usePurifier(true);
461+
$finalstatement->setPurifier(new \ilSvyStandardPurifier());
455462
$form->addItem($finalstatement);
456463

457464
// mail notification
@@ -885,14 +892,10 @@ public function saveForm(
885892
} else {
886893
$survey->setEndDate("");
887894
}
888-
$tags = ilObjAdvancedEditing::_getUsedHTMLTags("survey");
889-
$purifier = new HTMLPurifier($tags);
895+
$introduction = $this->purifier->purify($form->getInput('introduction'));
890896

891-
$introduction = $form->getInput("introduction");
892-
$introduction = $purifier->purify($introduction);
893897
$survey->setIntroduction($introduction);
894-
$outro = $form->getInput("outro");
895-
$outro = $purifier->purify($outro);
898+
$outro = $this->purifier->purify($form->getInput('outro'));
896899
$survey->setOutro($outro);
897900
$survey->setShowQuestionTitles((bool) $form->getInput("show_question_titles"));
898901

components/ILIAS/Survey/Settings/class.UIFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
/**
64
* This file is part of ILIAS, a powerful learning management system
75
* published by ILIAS open source e-Learning e.V.
@@ -18,6 +16,8 @@
1816
*
1917
*********************************************************************/
2018

19+
declare(strict_types=1);
20+
2121
namespace ILIAS\Survey\Settings;
2222

2323
use ILIAS\Survey\InternalGUIService;
@@ -48,7 +48,8 @@ public function __construct(
4848
$this->domain_service,
4949
$object_service,
5050
$survey,
51-
$mode_ui_modifier
51+
$mode_ui_modifier,
52+
new \ilSvyStandardPurifier()
5253
);
5354
}
5455

components/ILIAS/SurveyQuestionPool/Questions/class.SurveyQuestionGUI.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*
1717
*********************************************************************/
1818

19+
declare(strict_types=1);
20+
1921
use ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest;
2022
use ILIAS\SurveyQuestionPool\Editing\EditManager;
21-
use ILIAS\LegalDocuments\HTMLPurifier;
2223

2324
/**
2425
* Basic class for all survey question types
@@ -45,6 +46,7 @@ abstract class SurveyQuestionGUI
4546
protected string $parent_url = "";
4647
protected ilLogger $log;
4748
public ?SurveyQuestion $object = null;
49+
protected \ilHtmlPurifierInterface $purifier;
4850

4951
public function __construct($a_id = -1)
5052
{
@@ -91,6 +93,7 @@ public function __construct($a_id = -1)
9193
->editing();
9294
$this->gui = $DIC->survey()->internal()->gui();
9395
$this->domain = $DIC->survey()->internal()->domain();
96+
$this->purifier = new ilSvyStandardPurifier();
9497
}
9598

9699
abstract protected function initObject(): void;
@@ -265,6 +268,8 @@ protected function initEditForm(): ilPropertyFormGUI
265268
$question->setUseRte(true);
266269
$question->setRteTagSet("mini");
267270
}
271+
$question->usePurifier(true);
272+
$question->setPurifier($this->purifier);
268273
$form->addItem($question);
269274

270275
// obligatory
@@ -330,13 +335,10 @@ protected function saveForm(): bool
330335
$this->object->setAuthor($form->getInput("author"));
331336
$this->object->setDescription($form->getInput("description"));
332337

333-
$tags = ilObjAdvancedEditing::_getUsedHTMLTags("survey");
334-
$purifier = new HTMLPurifier($tags);
335-
$question = $form->getInput("question");
336-
337-
$question = $purifier->purify($question);
338+
$this->object->setQuestiontext(
339+
$this->purifier->purify($form->getInput("question"))
340+
);
338341

339-
$this->object->setQuestiontext($question);
340342
$this->object->setObligatory($form->getInput("obligatory"));
341343

342344
$this->importEditFormValues($form);

0 commit comments

Comments
 (0)