1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
From 8ee84b67eca8a8178fec498188d968d95212e932 Mon Sep 17 00:00:00 2001
From: MaurĂcio Meneghini Fauth <mauricio@mfauth.net>
Date: Sun, 12 Jan 2025 22:39:06 -0300
Subject: Fix XSS vulnerability on Insert page
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: MaurĂcio Meneghini Fauth <mauricio@mfauth.net>
---
libraries/classes/InsertEdit.php | 4 ++--
psalm-baseline.xml | 2 +-
test/classes/InsertEditTest.php | 14 ++++++++++++--
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php
index 3e6ab3e411..72971c0b88 100644
--- a/libraries/classes/InsertEdit.php
+++ b/libraries/classes/InsertEdit.php
@@ -1124,8 +1124,8 @@ private function getSpecialCharsAndBackupFieldForInsertingMode(
} elseif ($trueType === 'binary' || $trueType === 'varbinary') {
$specialChars = bin2hex($column['Default']);
} elseif (substr($trueType, -4) === 'text') {
- $textDefault = substr($column['Default'], 1, -1);
- $specialChars = stripcslashes($textDefault !== false ? $textDefault : $column['Default']);
+ $textDefault = (string) substr($column['Default'], 1, -1);
+ $specialChars = htmlspecialchars(stripcslashes($textDefault !== '' ? $textDefault : $column['Default']));
} else {
$specialChars = htmlspecialchars($column['Default']);
}
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index a07466f7bf..4f053c0a6a 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -8183,7 +8183,7 @@
<code>$specialChars</code>
<code>$specialChars</code>
<code>$specialCharsEncoded</code>
- <code>$textDefault !== false ? $textDefault : $column['Default']</code>
+ <code>$textDefault !== '' ? $textDefault : $column['Default']</code>
<code>$transformationPlugin->getScripts()</code>
<code>$transformation[$type . '_options'] ?? ''</code>
<code>$trueType</code>
diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php
index 6bbe885c12..c3f8234586 100644
--- a/test/classes/InsertEditTest.php
+++ b/test/classes/InsertEditTest.php
@@ -1714,9 +1714,9 @@ public function providerForTestGetSpecialCharsAndBackupFieldForInsertingMode():
[
false,
'"lorem\"ipsem"',
- 'lorem"ipsem',
+ 'lorem"ipsem',
'',
- 'lorem"ipsem',
+ 'lorem"ipsem',
],
],
'varchar with html special chars' => [
@@ -1732,6 +1732,16 @@ public function providerForTestGetSpecialCharsAndBackupFieldForInsertingMode():
'hello world<br><b>lorem</b> ipsem',
],
],
+ 'text with html special chars' => [
+ ['True_Type' => 'text', 'Default' => '\'</textarea><script>alert(1)</script>\''],
+ [
+ false,
+ '\'</textarea><script>alert(1)</script>\'',
+ '</textarea><script>alert(1)</script>',
+ '',
+ '</textarea><script>alert(1)</script>',
+ ],
+ ],
];
}
--
2.30.2
|