mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
FIX #CVE-2023-4197
This commit is contained in:
parent
119f6b6a7f
commit
0ed6a63fb0
|
|
@ -76,6 +76,9 @@ function dolStripPhpCode($str, $replacewith = '')
|
|||
function dolKeepOnlyPhpCode($str)
|
||||
{
|
||||
$str = str_replace('<?=', '<?php', $str);
|
||||
$str = str_replace('<?php', '__LTINTPHP__', $str);
|
||||
$str = str_replace('<?', '<?php', $str); // replace the short_open_tag. It is recommended to set this is Off in php.ini
|
||||
$str = str_replace('__LTINTPHP__', '<?php', $str);
|
||||
|
||||
$newstr = '';
|
||||
|
||||
|
|
|
|||
|
|
@ -226,4 +226,27 @@ class WebsiteTest extends PHPUnit\Framework\TestCase
|
|||
print __METHOD__." result checkPHPCode=".$result."\n";
|
||||
$this->assertEquals($result, 1, 'checkPHPCode did not detect the string was dangerous');
|
||||
}
|
||||
|
||||
/**
|
||||
* testDolKeepOnlyPhpCode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDolKeepOnlyPhpCode()
|
||||
{
|
||||
$s = 'HTML content <?php exec("eee"); ?> and more HTML content';
|
||||
$result = dolKeepOnlyPhpCode($s);
|
||||
print __METHOD__." result dolKeepOnlyPhpCode=".$result."\n";
|
||||
$this->assertEquals('<?php exec("eee"); ?>', $result, 'dolKeepOnlyPhpCode did extract the correct string');
|
||||
|
||||
$s = 'HTML content <? exec("eee"); ?> and more HTML content';
|
||||
$result = dolKeepOnlyPhpCode($s);
|
||||
print __METHOD__." result dolKeepOnlyPhpCode=".$result."\n";
|
||||
$this->assertEquals('<?php exec("eee"); ?>', $result, 'dolKeepOnlyPhpCode did extract the correct string');
|
||||
|
||||
$s = 'HTML content <?php test() <?php test2(); ?> and more HTML content';
|
||||
$result = dolKeepOnlyPhpCode($s);
|
||||
print __METHOD__." result dolKeepOnlyPhpCode=".$result."\n";
|
||||
$this->assertEquals('<?php test() ?><?php test2(); ?>', $result, 'dolKeepOnlyPhpCode did extract the correct string');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user