[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] Wiki rankings: prevent SQL injection via categId
"Espoir Baraka \(@esbarakabigega\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a84128730f85_3818bff0245e7@gitlab-sidekiq-low-urgency-cpu-bound-v2-b96b6f55-6z9fl.mail> |
Espoir Baraka pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki
Commits:
ea828b24 by Espoir Baraka at 2026-08-18T09:59:09+02:00
[FIX] Wiki rankings: prevent SQL injection via categId
---
* [FIX] Wiki rankings: prevent SQL injection via categId
---
* [FIX] Wiki rankings: prevent SQL injection via categId
---
* [FIX] Wiki rankings: prevent SQL injection via categId
- Improved category ID processing in `tiki-wiki_rankings.php` to ensure only positive integers are assigned.
- Introduced a new private method `buildWikiCategoryJoin` in `ranklib.php` to streamline SQL query construction for category joins, enhancing code readability and maintainability.
These changes enhance the robustness of category filtering in the rankings functionality.
(cherry picked from commit 7e4984fb4f0b047ccd5ad9816b3da9436abecbdc)
See merge request tikiwiki/tiki!10908
(cherry picked from commit 77114f7819f4a8b170c348f89f346b672f8002cf)
See merge request tikiwiki/tiki!10913
(cherry picked from commit d843dad0a5325503115803cafe87b7bdfaa1e2f8)
See merge request tikiwiki/tiki!10928
- - - - -
2 changed files:
- lib/rankings/ranklib.php
- tiki-wiki_rankings.php
Changes:
=====================================
lib/rankings/ranklib.php
=====================================
@@ -15,6 +15,34 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
class RankLib extends TikiLib
{
+ /**
+ * Build a parameterized wiki-page category join filter.
+ *
+ * @param array $categ Category ids (non-integers and non-positive values are ignored)
+ * @return array{0: string, 1: array} SQL fragment and bind values
+ */
+ private function buildWikiCategoryJoin(array $categ): array
+ {
+ $categIds = [];
+ foreach ($categ as $categId) {
+ $categId = (int) $categId;
+ if ($categId > 0) {
+ $categIds[] = $categId;
+ }
+ }
+
+ if (! $categIds) {
+ return ['', []];
+ }
+
+ $placeholders = implode(',', array_fill(0, count($categIds), '?'));
+ $mid = " INNER JOIN (`tiki_objects` as tob, `tiki_category_objects` as tco)"
+ . " ON (tp.`pageName` = tob.`itemId` and tob.`objectId` = tco.`catObjectId`)"
+ . " WHERE tob.`type` = 'wiki page' AND tco.`categId` IN ($placeholders)";
+
+ return [$mid, $categIds];
+ }
+
/**
* @param $limit
* @param array $categ
@@ -26,17 +54,7 @@ class RankLib extends TikiLib
global $user, $prefs;
$pagesAdded = [];
- $bindvals = [];
- $mid = '';
- if ($categ) {
- $mid .= " INNER JOIN (`tiki_objects` as tob, `tiki_category_objects` as tco) ON (tp.`pageName` = tob.`itemId` and tob.`objectId` = tco.`catObjectId`) WHERE tob.`type` = 'wiki page' AND (tco.`categId` = ?";
- $bindvals[] = $categ[0];
- //FIXME
- for ($i = 1, $icount_categ = count($categ); $i < $icount_categ; $i++) {
- $mid .= " OR tco.`categId` = " . $categ[$i];
- }
- $mid .= ")";
- }
+ [$mid, $bindvals] = $this->buildWikiCategoryJoin($categ);
$query = "select distinct tp.`pageName`, tp.`hits`, tp.`lang`, tp.`page_id` from `tiki_pages` tp $mid order by `hits` desc";
@@ -93,17 +111,7 @@ class RankLib extends TikiLib
$this->pageRank();
}
- $bindvals = [];
- $mid = '';
- if ($categ) {
- $mid .= " INNER JOIN (`tiki_objects` as tob, `tiki_category_objects` as tco) ON (tp.`pageName` = tob.`itemId` and tob.`objectId` = tco.`catObjectId`) WHERE tob.`type` = 'wiki page' AND (tco.`categId` = ?";
- //FIXME
- $bindvals[] = $categ[0];
- for ($i = 1, $icount_categ = count($categ); $i < $icount_categ; $i++) {
- $mid .= " OR tco.`categId` = " . $categ[$i];
- }
- $mid .= ")";
- }
+ [$mid, $bindvals] = $this->buildWikiCategoryJoin($categ);
$query = "select tp.`pageName`, tp.`pageRank` from `tiki_pages` tp $mid order by `pageRank` desc";
@@ -136,17 +144,7 @@ class RankLib extends TikiLib
{
global $user, $prefs;
- $bindvals = [];
- $mid = '';
- if ($categ) {
- $mid .= " INNER JOIN (`tiki_objects` as tob, `tiki_category_objects` as tco) ON (tp.`pageName` = tob.`itemId` and tob.`objectId` = tco.`catObjectId`) WHERE tob.`type` = 'wiki page' AND (tco.`categId` = ?";
- //FIXME
- $bindvals[] = $categ[0];
- for ($i = 1, $icount_categ = count($categ); $i < $icount_categ; $i++) {
- $mid .= " OR tco.`categId` = " . $categ[$i];
- }
- $mid .= ")";
- }
+ [$mid, $bindvals] = $this->buildWikiCategoryJoin($categ);
$query = "select tp.`pageName`, tp.`lastModif`, tp.`hits` from `tiki_pages` tp $mid order by `lastModif` desc";
@@ -600,23 +598,7 @@ $query = "select a.*, tf.*, max(b.`commentDate`) as `lastPost` from
*/
public function wiki_ranking_top_authors($limit, $categ = [])
{
- global $user;
-
- $bindvals = [];
- $mid = '';
- if ($categ) {
- $mid .= " INNER JOIN (`tiki_objects` as tob, `tiki_category_objects` as tco) ON (tp.`pageName` = tob.`itemId` and tob.`objectId` = tco.`catObjectId`)
- WHERE tob.`type` = 'wiki page'
- AND (tco.`categId` = ?"
- ;
-
- //FIXME
- $bindvals[] = $categ[0];
- for ($i = 1, $icount_categ = count($categ); $i < $icount_categ; $i++) {
- $mid .= " OR tco.`categId` = " . $categ[$i];
- }
- $mid .= ")";
- }
+ [$mid, $bindvals] = $this->buildWikiCategoryJoin($categ);
$query = "select distinct tp.`user`, count(*) as `numb` from `tiki_pages` tp $mid group by `user` order by " . $this->convertSortMode("numb_desc");
$result = $this->query($query, $bindvals, $limit, 0);
=====================================
tiki-wiki_rankings.php
=====================================
@@ -23,12 +23,16 @@ if (! isset($_REQUEST["limit"])) {
$limit = $_REQUEST["limit"];
}
-if (isset($_REQUEST["categId"]) && $_REQUEST["categId"] > 0) {
- $smarty->assign('categIdstr', $_REQUEST["categId"]);
- $categs = explode(",", $_REQUEST["categId"]);
-} else {
- $categs = [];
+$categs = [];
+if (isset($_REQUEST["categId"])) {
+ foreach (explode(",", (string) $_REQUEST["categId"]) as $categId) {
+ $categId = (int) $categId;
+ if ($categId > 0) {
+ $categs[] = $categId;
+ }
+ }
}
+$smarty->assign('categIdstr', implode(',', $categs));
$smarty->assign('categId', $categs);
$allrankings = [
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ea828b24cce71b42d5780492f2ee2fb9a6b5a553
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ea828b24cce71b42d5780492f2ee2fb9a6b5a553
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs