Skip to content

Commit eb75f1e

Browse files
committed
Merge branch '3.1' into 3.2
2 parents 24c1cb0 + bd527db commit eb75f1e

File tree

7 files changed

+60
-8
lines changed

7 files changed

+60
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ This is a log of major user-visible changes in each phpMyFAQ release.
3838
- updated Japanese translation (Advanced Bear)
3939
- updated Dutch translation (Bob Coret)
4040

41+
### phpMyFAQ v3.1.16 - 2023-07-16
42+
43+
- fixed multiple security vulnerabilities (Thorsten)
44+
- fixed minor bugs (Thorsten)
45+
4146
### phpMyFAQ v3.1.15 - 2023-06-17
4247

4348
- fixed minor bugs (Thorsten)

phpmyfaq/admin/api/user.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpMyFAQ\Filter;
2323
use phpMyFAQ\Helper\MailHelper;
2424
use phpMyFAQ\Permission;
25+
use phpMyFAQ\Report;
2526
use phpMyFAQ\Session\Token;
2627
use phpMyFAQ\Strings;
2728
use phpMyFAQ\Translation;
@@ -94,8 +95,8 @@
9495
$userObject->status = $user->getStatus();
9596
$userObject->isSuperAdmin = $user->isSuperAdmin();
9697
$userObject->isVisible = $user->getUserData('is_visible');
97-
$userObject->displayName = $user->getUserData('display_name');
98-
$userObject->userName = $user->getLogin();
98+
$userObject->displayName = Report::sanitize($user->getUserData('display_name'));
99+
$userObject->userName = Report::sanitize($user->getLogin());
99100
$userObject->email = $user->getUserData('email');
100101
$userObject->authSource = $user->getUserAuthSource();
101102
$userData[] = $userObject;

phpmyfaq/admin/report.export.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119

120120
$content = '';
121121
foreach ($text as $row) {
122-
$content .= implode(';', $row);
122+
$csvRow = array_map(['phpMyFAQ\Report', 'sanitize'], $row);
123+
$content .= implode(';', $csvRow);
123124
$content .= "\r\n";
124125
}
125126

phpmyfaq/src/phpMyFAQ/Link.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ public function toHtmlAnchor(): string
262262
}
263263

264264
if (!empty($this->tooltip)) {
265-
$htmlAnchor .= sprintf(' title="%s"', addslashes($this->tooltip));
265+
$htmlAnchor .= sprintf(' title="%s"', Strings::htmlentities($this->tooltip));
266266
}
267267

268268
if (!empty($this->name)) {
269-
$htmlAnchor .= sprintf(' name="%s"', $this->name);
269+
$htmlAnchor .= sprintf(' name="%s"', Strings::htmlentities($this->name));
270270
} else {
271271
if (!empty($this->url)) {
272272
$htmlAnchor .= sprintf(' href="%s"', $url);
@@ -280,10 +280,10 @@ public function toHtmlAnchor(): string
280280
}
281281
$htmlAnchor .= '>';
282282
if (('0' == $this->text) || (!empty($this->text))) {
283-
$htmlAnchor .= $this->text;
283+
$htmlAnchor .= Strings::htmlentities($this->text);
284284
} else {
285285
if (!empty($this->name)) {
286-
$htmlAnchor .= $this->name;
286+
$htmlAnchor .= Strings::htmlentities($this->name);
287287
} else {
288288
$htmlAnchor .= $url;
289289
}

phpmyfaq/src/phpMyFAQ/Report.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,18 @@ public function convertEncoding(string $outputString = ''): string
139139
$toBeRemoved = ['=', '+', '-', 'HYPERLINK'];
140140
return str_replace($toBeRemoved, '', $outputString);
141141
}
142+
143+
/**
144+
* Sanitizes input to avoid CSV injection.
145+
* @param string|int $value
146+
* @return string
147+
*/
148+
public static function sanitize($value): string
149+
{
150+
if (preg_match('/[=\+\-\@\|]/', $value)) {
151+
$value = '"' . str_replace('"', '""', $value) . '"';
152+
}
153+
154+
return $value;
155+
}
142156
}

phpmyfaq/src/phpMyFAQ/Search/Database/Mysqli.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Configuration $config)
4848
public function search(string $searchTerm): mixed
4949
{
5050
if (is_numeric($searchTerm) && $this->config->get('search.searchForSolutionId')) {
51-
parent::search($searchTerm);
51+
return parent::search($searchTerm);
5252
} else {
5353
$relevance = $this->config->get('search.enableRelevance');
5454
$columns = $this->getResultColumns();

tests/phpMyFAQ/ReportTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace phpMyFAQ;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class ReportTest extends TestCase
8+
{
9+
10+
public function testSanitize(): void
11+
{
12+
$data = [
13+
['John Doe', 'john.doe@example.com', '12345'],
14+
['Jane Smith', 'jane.smith@example.com', '=SUM(A1:A10)'],
15+
];
16+
17+
$actual = [];
18+
19+
$expected = [
20+
'John Doe,"john.doe@example.com",12345',
21+
'Jane Smith,"jane.smith@example.com","=SUM(A1:A10)"'
22+
];
23+
24+
foreach ($data as $row) {
25+
$csvRow = array_map(['phpMyFAQ\Report', 'sanitize'], $row);
26+
$actual[] = implode(',', $csvRow);
27+
}
28+
29+
$this->assertEquals($expected, $actual);
30+
}
31+
}

0 commit comments

Comments
 (0)