Skip to content

Commit d9c37bf

Browse files
committed
Security: Remove "Security::remove_XSS", fix htmleditor get value
Related: 099ec41
1 parent b3fa8b0 commit d9c37bf

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

main/inc/ajax/agenda.ajax.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22
/* For licensing terms, see /license.txt */
3+
34
/**
45
* Responses to AJAX calls.
56
*/
7+
68
$type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], ['personal', 'course', 'admin']) ? $_REQUEST['type'] : 'personal';
79

810
if ($type == 'personal') {
@@ -28,9 +30,9 @@
2830
break;
2931
}
3032
$add_as_announcement = isset($_REQUEST['add_as_annonuncement']) ? $_REQUEST['add_as_annonuncement'] : null;
31-
$title = isset($_REQUEST['title']) ? Security::remove_XSS($_REQUEST['title']) : null;
32-
$content = isset($_REQUEST['content']) ? Security::remove_XSS($_REQUEST['content']) : null;
33-
$comment = isset($_REQUEST['comment']) ? Security::remove_XSS($_REQUEST['comment']) : null;
33+
$title = isset($_REQUEST['title']) ? $_REQUEST['title'] : null;
34+
$content = isset($_REQUEST['content']) ? $_REQUEST['content'] : null;
35+
$comment = isset($_REQUEST['comment']) ? $_REQUEST['comment'] : null;
3436
$userToSend = isset($_REQUEST['users_to_send']) ? $_REQUEST['users_to_send'] : [];
3537

3638
echo $agenda->addEvent(

main/inc/lib/formvalidator/Element/HtmlEditor.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(
3131
$config = []
3232
) {
3333
if (empty($name)) {
34-
return false;
34+
throw new \Exception('Name is required');
3535
}
3636

3737
parent::__construct($name, $elementLabel, $attributes);
@@ -54,9 +54,9 @@ public function __construct(
5454
*/
5555
public function toHtml()
5656
{
57-
$value = Security::remove_XSS($this->getValue());
5857
if ($this->editor) {
5958
if ($this->editor->getConfigAttribute('fullPage')) {
59+
$value = $this->getValue();
6060
if (strlen(trim($value)) == 0) {
6161
// TODO: To be considered whether here to add
6262
// language and character set declarations.
@@ -70,10 +70,9 @@ public function toHtml()
7070
return $this->getFrozenHtml();
7171
} else {
7272
$styleCss = $this->editor->getConfigAttribute('style');
73+
$style = false;
7374
if ($styleCss) {
7475
$style = true;
75-
} else {
76-
$style = false;
7776
}
7877

7978
return $this->buildEditor($style);
@@ -87,7 +86,7 @@ public function toHtml()
8786
*/
8887
public function getFrozenHtml()
8988
{
90-
return $this->getValue();
89+
return $this->getCleanValue();
9190
}
9291

9392
/**
@@ -99,9 +98,9 @@ public function buildEditor($style = false)
9998
{
10099
$result = '';
101100
if ($this->editor) {
102-
$this->editor->value = Security::remove_XSS($this->getValue());
101+
$this->editor->value = $this->getCleanValue();
103102
$this->editor->setName($this->getName());
104-
if ($style == true) {
103+
if ($style === true) {
105104
$result = $this->editor->createHtmlStyle();
106105
} else {
107106
$result = $this->editor->createHtml();

main/inc/lib/pear/HTML/QuickForm/element.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,30 @@ public function setValue($value)
253253
*/
254254
public function getValue()
255255
{
256-
// interface
257256
return null;
258-
} // end func getValue
257+
}
259258

260-
// }}}
261-
// {{{ freeze()
259+
/**
260+
* @return string
261+
*/
262+
public function getCleanValue()
263+
{
264+
$value = $this->cleanValueFromParameter($this->getValue());
265+
266+
return $value;
267+
}
268+
269+
/**
270+
* @param string $value
271+
*
272+
* @return string
273+
*/
274+
public function cleanValueFromParameter($value)
275+
{
276+
$value = @htmlspecialchars($value, ENT_COMPAT, HTML_Common::charset());
277+
278+
return $value;
279+
}
262280

263281
/**
264282
* Freeze the element so that only its value is returned
@@ -302,12 +320,16 @@ public function getFrozenHtml()
302320
// Modified by Ivan Tcholakov, 16-MAR-2010.
303321
//return ('' != $value? htmlspecialchars($value): '&nbsp;') .
304322
// $this->_getPersistantData();
323+
if (!empty($value)) {
324+
$value = $this->getCleanValue();
325+
} else {
326+
$value = '&nbsp;';
327+
}
328+
329+
$value .= $this->_getPersistantData();
305330

306-
$value = ('' != $value ? @htmlspecialchars($value, ENT_COMPAT, HTML_Common::charset()): '&nbsp;') .
307-
$this->_getPersistantData();
308331
return '<span class="freeze">'.$value.'</span>';
309-
//
310-
} //end func getFrozenHtml
332+
}
311333

312334
/**
313335
* Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on

0 commit comments

Comments
 (0)