Skip to content

Commit

Permalink
Fix sanitize website module
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 27, 2023
1 parent a633766 commit e0cd351
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
12 changes: 8 additions & 4 deletions htdocs/core/lib/website.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ function dolStripPhpCode($str, $replacewith = '')

$newstr = '';

//split on each opening tag
$parts = explode('<?php', $str);
// Split on each opening tag
//$parts = explode('<?php', $str);
$parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);

if (!empty($parts)) {
$i = 0;
foreach ($parts as $part) {
Expand Down Expand Up @@ -77,8 +79,10 @@ function dolKeepOnlyPhpCode($str)

$newstr = '';

//split on each opening tag
$parts = explode('<?php', $str);
// Split on each opening tag
//$parts = explode('<?php', $str);
$parts = preg_split('/'.preg_quote('<?php', '/').'/i', $str);

if (!empty($parts)) {
$i = 0;
foreach ($parts as $part) {
Expand Down
5 changes: 5 additions & 0 deletions test/phpunit/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public static function suite()
require_once dirname(__FILE__).'/AccountingAccountTest.php';
$suite->addTestSuite('AccountingAccountTest');

// Rest
require_once dirname(__FILE__).'/RestAPIUserTest.php';
$suite->addTestSuite('RestAPIUserTest');
require_once dirname(__FILE__).'/RestAPIDocumentTest.php';
Expand Down Expand Up @@ -270,6 +271,10 @@ public static function suite()
require_once dirname(__FILE__).'/EmailCollectorTest.php';
$suite->addTestSuite('EmailCollectorTest');

// Website
require_once dirname(__FILE__).'/WebsiteTest.php';
$suite->addTestSuite('Website');

return $suite;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,22 @@ public function testGetPagesFromSearchCriterias()
// We must found no line (so code should be KO). If we found somethiing, it means there is a SQL injection of the 1=1
$this->assertEquals($res['code'], 'KO');
}

/**
* testDolStripPhpCode
*
* @return void
*/
public function testDolStripPhpCode()
{
global $db;

$s = "abc\n<?php echo 'def'\n// comment\n ?>ghi";
$result = dolStripPhpCode($s);
$this->assertEquals("abc\n<span phptag></span>ghi", $result);

$s = "abc\n<?PHP echo 'def'\n// comment\n ?>ghi";
$result = dolStripPhpCode($s);
$this->assertEquals("abc\n<span phptag></span>ghi", $result);
}
}

0 comments on commit e0cd351

Please sign in to comment.