Skip to content

Commit ec20827

Browse files
committed
Add StringFilter to sanitize any external input
1 parent eca361d commit ec20827

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/WebApp/Component/I18nFormElement.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function getError($languageKey = NULL) {
5050
return isset($this->errors[$languageKey]) ? I18N::_($this->errors[$languageKey]) : NULL;
5151
}
5252

53-
public static function getPostValues($name, $languages) {
53+
public static function getPostValues($name, $languages, $filter = NULL) {
5454
$rc = array();
5555
$request = \TgUtils\Request::getRequest();
5656
foreach ($languages AS $key => $label) {
57-
$rc[$key] = $request->getPostParam($name.'-'.$key);
57+
$rc[$key] = $request->getPostParam($name.'-'.$key, NULL, $filter);
5858
if ($rc[$key] != NULL) $rc[$key] = trim($rc[$key]);
5959
}
6060
return $rc;

src/WebApp/RestPage.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use TgLog\Log;
66
use TgLog\Error;
77
use WebApp\Component\Alert;
8+
use TgUtils\StringFilters;
89

910
class RestPage extends Page {
1011

@@ -110,10 +111,18 @@ protected function getJsonBody() {
110111
return $this->jsonBody;
111112
}
112113

113-
protected function getJsonParam($key, $default = NULL) {
114+
/**
115+
* Returns the JSON parameter with the given key.
116+
* @param string $key - the object attribute of root JSON object
117+
* @param mixed $default - the default value if not available
118+
* @param StringFilter $filter - the filter to apply for the param (NULL will mean NOHTML)
119+
* @return the filtered value or default value.
120+
*/
121+
protected function getJsonParam($key, $default = NULL, $filter = NULL) {
114122
$obj = $this->getJsonBody();
115123
if (!isset($obj->$key)) return $default;
116-
return $obj->$key;
124+
if ($filter == NULL) $filter = StringFilters::$NO_HTML;
125+
return $filter->filter($obj->$key);
117126
}
118127
}
119128

0 commit comments

Comments
 (0)