Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
Fixed some security issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Globulopolis committed Aug 8, 2021
1 parent 24d2346 commit 81c7d79
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 10 deletions.
29 changes: 29 additions & 0 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function checkAccess($is_index = false)
}

$ids = Common::getRequestVar('id', array(), 'array');
$ids = $this->toInteger($ids);

if (empty($ids) && $action == 'counter_exists') {
return true;
Expand Down Expand Up @@ -785,4 +786,32 @@ private function getModel()
{
return new Model();
}

/**
* Convert array to integer values.
*
* @param array $array The source array to convert
* @param int|array $default A default value to assign if $array is not an array
*
* @return array
*/
public function toInteger($array, $default = null)
{
if (is_array($array))
{
return array_map('intval', $array);
}

if ($default === null)
{
return array();
}

if (is_array($default))
{
return static::toInteger($default);
}

return array((int) $default);
}
}
2 changes: 1 addition & 1 deletion Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function load()
}

/**
* Save some string datas into a cache record.
* Save some string data into a cache record.
*
* @param mixed $data Cache data.
*
Expand Down
8 changes: 6 additions & 2 deletions Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function publish($state = 1)
$this->api->checkAccess();

$ids = Common::getRequestVar('id', array(), 'array');
$ids = $this->api->toInteger($ids);

if (empty($ids)) {
$this->api->enqueueMessage($this->translator->translate('Counter_List_make_selection'), 'error');
Expand Down Expand Up @@ -168,6 +169,7 @@ public function remove()
$this->api->checkAccess();

$ids = Common::getRequestVar('id', array(), 'array');
$ids = $this->api->toInteger($ids);

if (empty($ids)) {
$this->api->enqueueMessage($this->translator->translate('Counter_List_make_selection'), 'error');
Expand Down Expand Up @@ -209,7 +211,9 @@ public function clearCache()
throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch'));
}

$result = $this->api->clearCache(Common::getRequestVar('id', array(), 'array'));
$ids = Common::getRequestVar('id', array(), 'array');
$ids = $this->api->toInteger($ids);
$result = $this->api->clearCache($ids);

if (strtolower(Common::getRequestVar('format', '', 'string')) === 'json') {
Json::sendHeaderJSON();
Expand Down Expand Up @@ -312,7 +316,7 @@ public function apply($task = 'apply')
$this->api->enqueueMessage($this->translator->translate('Counter_Saved'), 'success', 'toast');
}

if ($task == 'apply') {
if ($task === 'apply') {
$this->redirectToIndex('Counter', 'edit', null, null, null, array('id' => $result));
} else {
$this->redirectToIndex('Counter', 'index');
Expand Down
4 changes: 2 additions & 2 deletions Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function getItem($id)
throw new \Exception(Piwik::translate('Counter_Error_has_occurred'));
}

$row = Db::fetchRow("SELECT id, idsite, title, params, visits, views, published FROM " . $this->table . " WHERE id = " . (int)$id[0]);
$row = Db::fetchRow("SELECT id, idsite, title, params, visits, views, published FROM " . $this->table . " WHERE id = " . (int) $id[0]);

$result['id'] = $row['id'];
$result['idsite'] = $row['idsite'];
Expand Down Expand Up @@ -184,7 +184,7 @@ public function getItem($id)
$rows = Db::fetchAll("SELECT s.main_url, u.url"
. "\n FROM " . Common::prefixTable('site') . " AS s"
. "\n LEFT JOIN " . Common::prefixTable('site_url') . " AS u ON s.idsite = u.idsite"
. "\n WHERE s.idsite = " . (int)$row['idsite']);
. "\n WHERE s.idsite = " . (int) $row['idsite']);

$origins = array();
$p = array('/http:\/\//', '/https:\/\//');
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Display Hits/Visits on image. Display Hits/Visits/from Countries stats as text v
See http://xn--80aeqbhthr9b.com/en/others/piwik/10-piwik-graphical-counter.html

## Changelog
3.0.3
* Fixed some security issues.

3.0.2
* Use force_ssl option for live visitors counter javascript file.

Expand Down
4 changes: 2 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
"Params_padd_left": "from left",
"Params_padd_top": " from above",
"Params_img_path": "Image filepath",
"Params_img_path_desc": "Absolute path to the image. The only supported types png and gif",
"Params_img_path_desc": "Absolute path to the image. The only supported types jpg, png, gif. Do not store any images in plugin folder as it will be deleted after plugin update.",
"Params_datestart": "Start date",
"Params_datestart_period": "or period",
"Params_datestart_desc": "Date from which will start counting visits. To compute all visits set the date when piwik was installed or date when site was added. Format - year-month-day<br />For example - 2000-01-01<br />If both fields are left blank, the date will be taken from the parameter <strong>date</strong> in the url.",
"Params_token_auth": "User token",
"Params_token_auth_desc": "The token of a user with view (preview) rights. If you do not specify, then piwik report an error, and the counter will be zero. You can also create additional users and assign the appropriate rights.",
"Params_fontpath": "Font filepath",
"Params_fontpath_desc": "Absolute path to a font file in TrueType format.",
"Params_fontpath_desc": "Absolute path to a font file in TrueType format. Do not store any fonts in plugin folder as it will be deleted after plugin update.",
"Params_fontsize": "Font size",
"Params_fontsize_desc": "Font size - 7pt. For GD1 - 7px",
"Params_pos_sep": "Configuration labels",
Expand Down
4 changes: 2 additions & 2 deletions lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
"Params_padd_left": " слева",
"Params_padd_top": " сверху",
"Params_img_path": "Путь к изображению",
"Params_img_path_desc": "Абсолютный путь к файлу изображения счетчика. Поддерживаемые форматы png и gif",
"Params_img_path_desc": "Абсолютный путь к файлу изображения счетчика. Поддерживаемые форматы jpg, png, gif. Не храните изображения счетчика в папке плагина, т.к. эта папка будет очищена после обновления плагина.",
"Params_datestart": "Дата начала",
"Params_datestart_period": "или период",
"Params_datestart_desc": "Дата с которой будет начат подсчет посещений. Для подсчета всех посещений устанавливайте дату установки piwik или дату когда был добавлен сайт. По умолчанию при создании счетчика и выборе сайта из списка, в поле даты будет подставленна дата добавления сайта в систему. Формат - год-месяц-число<br />К примеру - 2000-01-01<br />Если оба поля оставить пустыми, то дата будет браться из параметра <strong>date</strong> в url.",
"Params_token_auth": "Токен пользователя",
"Params_token_auth_desc": "Токен пользователя с правами view(просмотр). Если не указать, то piwik сообщит об ошибке, а на счетчике будут нули. Для анонимного пользователя указывайте anonymous. Также вы можете создать дополнительного пользователя и назначить ему соответствующие права.",
"Params_fontpath": "Путь к файлу шрифта",
"Params_fontpath_desc": "Абсолютный путь к файлу шрифта в формате TrueType.",
"Params_fontpath_desc": "Абсолютный путь к файлу шрифта в формате TrueType. Не храните шрифты счетчика в папке плагина, т.к. эта папка будет очищена после обновления плагина.",
"Params_fontsize": "Размер шрифта",
"Params_fontsize_desc": "Размер шрифта - 7pt. Для версии GD1 - 7px",
"Params_pos_sep": "Настройки надписей",
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Counter",
"version": "3.0.2",
"version": "3.0.3",
"description": "Display Hits/Visits on image. Display Hits/Visits/from Countries stats as text via ajax requests.",
"theme": false,
"require": {
Expand Down

0 comments on commit 81c7d79

Please sign in to comment.