Skip to content

Commit 9b9a55c

Browse files
committed
Backport Security Patches for Samples
1 parent 9e7df84 commit 9b9a55c

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,4 @@ jobs:
282282
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
283283
with:
284284
bodyFile: release-body.txt
285+
makeLatest: false

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1313

1414
### Fixed
1515

16-
- More context options may be needed for http(s) image. Backport of [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
16+
- More context options may be needed for http(s) image. Backport of [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
17+
- Backported security patches for Samples.
1718

1819
## 2024-12-08 - 2.1.5
1920

samples/Engineering/Convert-Online.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@
7878
$quantity = $_POST['quantity'];
7979
$fromUnit = $_POST['fromUnit'];
8080
$toUnit = $_POST['toUnit'];
81-
if (isset($units[$_POST['category']][$fromUnit], $units[$_POST['category']][$toUnit])) {
81+
if (!is_numeric($quantity)) {
82+
$helper->log('Quantity is not numeric');
83+
} elseif (isset($units[$_POST['category']][$fromUnit], $units[$_POST['category']][$toUnit])) {
8284
/** @var float|string */
8385
$result = ConvertUOM::CONVERT($quantity, $fromUnit, $toUnit);
8486

85-
echo "{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}", PHP_EOL;
87+
$helper->log("{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}");
8688
} else {
87-
echo 'Please enter quantity and select From Unit and To Unit', PHP_EOL;
89+
$helper->log('Please enter quantity and select From Unit and To Unit');
8890
}
8991
} else {
90-
echo 'Please enter quantity and select From Unit and To Unit', PHP_EOL;
92+
$helper->log('Please enter quantity and select From Unit and To Unit');
9193
}

samples/Wizards/NumberFormat/Accounting.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
$helper->log('The Sample Number Value must be numeric');
8686
} elseif (!is_numeric($_POST['decimals']) || str_contains((string) $_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
8787
$helper->log('The Decimal Places value must be positive integer');
88+
} elseif (!in_array($_POST['currency'], array_keys($currencies), true)) {
89+
$helper->log('Unrecognized currency symbol');
8890
} else {
8991
try {
9092
$wizard = new Wizard\Accounting($_POST['currency'], (int) $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position'], (bool) $_POST['spacing']);
@@ -93,12 +95,14 @@
9395
$helper->log('<hr /><b>Code:</b><br />');
9496
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
9597
$helper->log(
96-
"\$mask = Wizard\\Accounting('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
98+
"\$wizard = new Wizard\\Accounting('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
9799
. (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR')
98100
. ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL')
99101
. ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING')
100-
. ');<br />'
102+
. ');'
101103
);
104+
$helper->log('$mask = $wizard->format();');
105+
$helper->log('<br />');
102106
$helper->log('echo (string) $mask;');
103107
$helper->log('<hr /><b>Mask:</b><br />');
104108
$helper->log($mask . '<br />');

samples/Wizards/NumberFormat/Currency.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
$helper->log('The Sample Number Value must be numeric');
8686
} elseif (!is_numeric($_POST['decimals']) || str_contains((string) $_POST['decimals'], '.') || (int) $_POST['decimals'] < 0) {
8787
$helper->log('The Decimal Places value must be positive integer');
88+
} elseif (!in_array($_POST['currency'], array_keys($currencies), true)) {
89+
$helper->log('Unrecognized currency symbol');
8890
} else {
8991
try {
9092
$wizard = new Wizard\Currency($_POST['currency'], (int) $_POST['decimals'], isset($_POST['thousands']), (bool) $_POST['position'], (bool) $_POST['spacing']);
@@ -93,12 +95,14 @@
9395
$helper->log('<hr /><b>Code:</b><br />');
9496
$helper->log('use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;');
9597
$helper->log(
96-
"\$mask = Wizard\\Currency('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
98+
"\$wizard = new Wizard\\Currency('{$_POST['currency']}', {$_POST['decimals']}, Wizard\\Number::"
9799
. (isset($_POST['thousands']) ? 'WITH_THOUSANDS_SEPARATOR' : 'WITHOUT_THOUSANDS_SEPARATOR')
98100
. ', Wizard\Currency::' . (((bool) $_POST['position']) ? 'LEADING_SYMBOL' : 'TRAILING_SYMBOL')
99101
. ', Wizard\Currency::' . (((bool) $_POST['spacing']) ? 'SYMBOL_WITH_SPACING' : 'SYMBOL_WITHOUT_SPACING')
100-
. ');<br />'
102+
. ');'
101103
);
104+
$helper->log('$mask = $wizard->format();');
105+
$helper->log('<br />');
102106
$helper->log('echo (string) $mask;');
103107
$helper->log('<hr /><b>Mask:</b><br />');
104108
$helper->log($mask . '<br />');

src/PhpSpreadsheet/Helper/Downloader.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ class Downloader
3030
public function __construct(string $folder, string $filename, ?string $filetype = null)
3131
{
3232
if ((is_dir($folder) === false) || (is_readable($folder) === false)) {
33-
throw new Exception("Folder {$folder} is not accessable");
33+
throw new Exception('Folder is not accessible');
3434
}
3535
$filepath = "{$folder}/{$filename}";
3636
$this->filepath = (string) realpath($filepath);
3737
$this->filename = basename($filepath);
3838
if ((file_exists($this->filepath) === false) || (is_readable($this->filepath) === false)) {
39-
throw new Exception("{$this->filename} not found, or cannot be read");
39+
throw new Exception('File not found, or cannot be read');
4040
}
4141

4242
$filetype ??= pathinfo($filename, PATHINFO_EXTENSION);
4343
if (array_key_exists(strtolower($filetype), self::CONTENT_TYPES) === false) {
44-
throw new Exception("Invalid filetype: {$filetype} cannot be downloaded");
44+
throw new Exception('Invalid filetype: cannot be downloaded');
4545
}
4646
$this->filetype = strtolower($filetype);
4747
}

0 commit comments

Comments
 (0)