2
0
forked from Wavyzz/dolibarr

Share not allowed extension into the method getExecutableContent()

This commit is contained in:
ldestailleur
2025-04-01 17:53:33 +02:00
parent 3edadbd8b8
commit 5d51d0679b
4 changed files with 113 additions and 61 deletions

View File

@@ -14118,16 +14118,35 @@ function fetchObjectByElement($element_id, $element_type, $element_ref = '', $us
return $ret;
}
/**
* Return array of extension for executable files of text files that can contains executable code.
*
* @return array Array of extensions
*/
function getExecutableContent()
{
$arrayofregexextension = array(
'htm', 'html', 'shtml', 'js', 'phar', 'php', 'php3', 'php4', 'php5', 'phtml', 'pht', 'pl', 'py', 'cgi', 'ksh', 'sh', 'shtml',
'bash', 'bat', 'cmd', 'wpk', 'exe', 'dmg', 'appimage'
);
return $arrayofregexextension;
}
/**
* Return if a file can contains executable content
*
* @param string $filename File name to test
* @return boolean True if yes, False if no
* @param string $filename File name to test
* @return boolean True if yes, False if no
*/
function isAFileWithExecutableContent($filename)
{
if (preg_match('/\.(htm|html|js|phar|php|php\d+|phtml|pht|pl|py|cgi|ksh|sh|shtml|bash|bat|cmd|wpk|exe|dmg)$/i', $filename)) {
return true;
$arrayofregexextension = getExecutableContent();
foreach ($arrayofregexextension as $fileextension) {
if (preg_match('/\.'.preg_quote($fileextension, '/').'$/i', $filename)) {
return true;
}
}
return false;