Skip to content

Commit 9a7981e

Browse files
author
Marius Burkard
committed
- added htmlentities (XSS protection) to form data passed to template, fixes #4902
1 parent 5309338 commit 9a7981e

19 files changed

+41
-36
lines changed

interface/lib/classes/tform_actions.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function onError() {
287287
global $app, $conf;
288288

289289
$app->tpl->setVar("error", "<li>".$app->tform->errorMessage."</li>");
290-
$app->tpl->setVar($this->dataRecord);
290+
$app->tpl->setVar($this->dataRecord, null, true);
291291
$this->onShow();
292292
}
293293

interface/lib/classes/tpl.inc.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,26 @@ public function newTemplate($tmplfile)
226226
* using the keys as variable names and the values as variable values.
227227
* @param mixed $k key to define variable name
228228
* @param mixed $v variable to assign to $k
229+
* @param bool $encode if set to true use htmlentities on values
229230
* @return boolean true/false
230231
* @access public
231232
*/
232-
public function setVar($k, $v = null)
233+
public function setVar($k, $v = null, $encode = false)
233234
{
235+
global $app;
236+
234237
if (is_array($k)) {
235238
foreach($k as $key => $value){
236239
$key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key);
237240
if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $key) && $value !== null ) {
241+
if($encode == true) $value = $app->functions->htmlentities($value);
238242
$this->_vars[$key] = $value;
239243
}
240244
}
241245
} else {
242246
if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $k) && $v !== null) {
243247
if ($this->OPTIONS['CASELESS']) $k = strtolower($k);
248+
if($encode == true) $value = $app->functions->htmlentities($);
244249
$this->_vars[trim($k)] = $v;
245250
} else {
246251
return false;

interface/web/admin/directive_snippets_edit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ function onShowEnd() {
7070
if($this->id > 0){
7171
if($this->dataRecord['master_directive_snippets_id'] > 0){
7272
$is_master = true;
73-
$app->tpl->setVar("name", $this->dataRecord['name']);
74-
$app->tpl->setVar("type", $this->dataRecord['type']);
75-
$app->tpl->setVar("snippet", $this->dataRecord['snippet']);
73+
$app->tpl->setVar("name", $this->dataRecord['name'], true);
74+
$app->tpl->setVar("type", $this->dataRecord['type'], true);
75+
$app->tpl->setVar("snippet", $this->dataRecord['snippet'], true);
7676
}
7777
}
7878
$app->tpl->setVar("is_master", $is_master);

interface/web/dns/dns_slave_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function onShowEnd() {
149149
if($this->id > 0) {
150150
//* we are editing a existing record
151151
$app->tpl->setVar("edit_disabled", 1);
152-
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
152+
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"], true);
153153
} else {
154154
$app->tpl->setVar("edit_disabled", 0);
155155
}

interface/web/dns/dns_soa_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function onShowEnd() {
217217
if($this->id > 0) {
218218
//* we are editing a existing record
219219
$app->tpl->setVar("edit_disabled", 1);
220-
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
220+
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"], true);
221221

222222
$datalog = $app->db->queryOneRecord("SELECT sys_datalog.error, sys_log.tstamp FROM sys_datalog, sys_log WHERE sys_datalog.dbtable = 'dns_soa' AND sys_datalog.dbidx = ? AND sys_datalog.datalog_id = sys_log.datalog_id AND sys_log.message = CONCAT('Processed datalog_id ',sys_log.datalog_id) ORDER BY sys_datalog.tstamp DESC", 'id:' . $this->id);
223223
if(is_array($datalog) && !empty($datalog)){

interface/web/mail/mail_domain_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function onShowEnd() {
204204
if($this->id > 0) {
205205
//* we are editing a existing record
206206
$app->tpl->setVar("edit_disabled", 1);
207-
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
207+
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"], true);
208208
} else {
209209
$app->tpl->setVar("edit_disabled", 0);
210210
}

interface/web/mail/mail_mailinglist_edit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ function onShowEnd() {
124124
if($this->id > 0) {
125125
//* we are editing a existing record
126126
$app->tpl->setVar("edit_disabled", 1);
127-
$app->tpl->setVar("listname_value", $this->dataRecord["listname"]);
128-
$app->tpl->setVar("domain_value", $this->dataRecord["domain"]);
129-
$app->tpl->setVar("email_value", $this->dataRecord["email"]);
127+
$app->tpl->setVar("listname_value", $this->dataRecord["listname"], true);
128+
$app->tpl->setVar("domain_value", $this->dataRecord["domain"], true);
129+
$app->tpl->setVar("email_value", $this->dataRecord["email"], true);
130130
} else {
131131
$app->tpl->setVar("edit_disabled", 0);
132132
}

interface/web/mail/mail_user_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function onShowEnd() {
121121
if($this->dataRecord['autoresponder_subject'] == '') {
122122
$app->tpl->setVar('autoresponder_subject', $app->tform->lng('autoresponder_subject'));
123123
} else {
124-
$app->tpl->setVar('autoresponder_subject', $this->dataRecord['autoresponder_subject']);
124+
$app->tpl->setVar('autoresponder_subject', $this->dataRecord['autoresponder_subject'], true);
125125
}
126126

127127
$app->uses('getconf');

interface/web/mail/xmpp_domain_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function onShowEnd() {
211211
if($this->id > 0) {
212212
//* we are editing a existing record
213213
$app->tpl->setVar("edit_disabled", 1);
214-
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
214+
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"], true);
215215
} else {
216216
$app->tpl->setVar("edit_disabled", 0);
217217
}

interface/web/mailuser/mail_user_autoresponder_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function onShowEnd() {
8484
if($this->dataRecord['autoresponder_subject'] == '') {
8585
$app->tpl->setVar('autoresponder_subject', $app->tform->lng('autoresponder_subject'));
8686
} else {
87-
$app->tpl->setVar('autoresponder_subject', $this->dataRecord['autoresponder_subject']);
87+
$app->tpl->setVar('autoresponder_subject', $this->dataRecord['autoresponder_subject'], true);
8888
}
8989

9090
parent::onShowEnd();

0 commit comments

Comments
 (0)