Issues (4069)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

include/dir_inc.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42
43
function copy_recursive( $source, $dest ){
44
45
46
    if( is_file( $source ) ){
47
        return( copy( $source, $dest ) );
48
    }
49
    if( !sugar_is_dir($dest, 'instance') ){
50
        sugar_mkdir( $dest );
51
    }
52
53
    $status = true;
54
55
    $d = dir( $source );
56
    if($d === false) {
57
    	return false;
58
    }
59
    while(false !== ($f = $d->read())) {
60
        if( $f == "." || $f == ".." ) {
61
            continue;
62
        }
63
        $status &= copy_recursive( "$source/$f", "$dest/$f" );
64
    }
65
    $d->close();
66
    return $status;
67
}
68
69
function mkdir_recursive($path, $check_is_parent_dir = false)
70
{
71 1
	if(sugar_is_dir($path, 'instance')) {
72
		return(true);
73
	}
74 1
	if(sugar_is_file($path, 'instance')) {
75
	    if(!empty($GLOBALS['log'])) {
76
		    $GLOBALS['log']->fatal("ERROR: mkdir_recursive(): argument $path is already a file.");
77
	    }
78
		return false;
79
	}
80
81
    //make variables with file paths
82 1
	$pathcmp = $path = rtrim(clean_path($path), '/');
83 1
	$basecmp =$base = rtrim(clean_path(getcwd()), '/');
84 1
	if(is_windows()) {
85
        //make path variable lower case for comparison in windows
86
	    $pathcmp = strtolower($path);
87
	    $basecmp = strtolower($base);
88
	}
89
90 1
    if($basecmp == $pathcmp) {
91
        return true;
92
    }
93 1
    $base .= "/";
94 1
	if(strncmp($pathcmp, $basecmp, strlen($basecmp)) == 0) {
95
        /* strip current path prefix */
96
	    $path = substr($path, strlen($base));
97
	}
98 1
	$thePath = '';
99 1
	$dirStructure = explode("/", $path);
100 1
	if($dirStructure[0] == '') {
101
	    // absolute path
102
        $base = '/';
103
        array_shift($dirStructure);
104
	}
105 1
	if(is_windows()) {
106
	    if(strlen($dirStructure[0]) == 2 && $dirStructure[0][1] == ':') {
107
	        /* C: prefix */
108
	        $base = array_shift($dirStructure)."\\";
109
	    } elseif ($dirStructure[0][0].$dirStructure[0][1] == "\\\\") {
110
	        /* UNC absolute path */
111
	        $base = array_shift($dirStructure)."\\".array_shift($dirStructure)."\\"; // we won't try to mkdir UNC share name
112
	    }
113
	}
114 1
	foreach($dirStructure as $dirPath) {
115 1
		$thePath .= $dirPath."/";
116 1
		$mkPath = $base.$thePath;
117
118 1
		if(!is_dir($mkPath )) {
119 1
			if(!sugar_mkdir($mkPath)) return false;
120
		}
121
	}
122 1
	return true;
123
}
124
125
function rmdir_recursive( $path ){
126
    if( is_file( $path ) ){
127
        return( unlink( $path ) );
128
    }
129
    if( !is_dir( $path ) ){
130
       	if(!empty($GLOBALS['log'])) {
131
            $GLOBALS['log']->fatal( "ERROR: rmdir_recursive(): argument $path is not a file or a dir." );
132
       	}
133
        return false;
134
    }
135
136
    $status = true;
137
138
    $d = dir( $path );
139
    
140
    while(($f = $d->read()) !== false){
141
        if( $f == "." || $f == ".." ){
142
            continue;
143
        }
144
        $status &= rmdir_recursive( "$path/$f" );
145
    }
146
    $d->close();
147
    $rmOk = @rmdir($path);
148
    if($rmOk === FALSE){
149
        $GLOBALS['log']->error("ERROR: Unable to remove directory $path");
150
    }
151
    return( $status );
152
}
153
154
function findTextFiles( $the_dir, $the_array ){
155
    if(!is_dir($the_dir)) {
156
		return $the_array;
157
	}
158
	$d = dir($the_dir);
159
    while (false !== ($f = $d->read())) {
160
        if( $f == "." || $f == ".." ){
161
            continue;
162
        }
163
        if( is_dir( "$the_dir/$f" ) ){
164
            // i think depth first is ok, given our cvs repo structure -Bob.
165
            $the_array = findTextFiles( "$the_dir/$f", $the_array );
166
        }
167
        else {
168
            switch( mime_content_type( "$the_dir/$f" ) ){
169
                // we take action on these cases
170
                case "text/html":
171
                case "text/plain":
172
                    array_push( $the_array, "$the_dir/$f" );
173
                    break;
174
                // we consciously skip these types
175
                case "application/pdf":
176
                case "application/x-zip":
177
                case "image/gif":
178
                case "image/jpeg":
179
                case "image/png":
180
                case "text/rtf":
181
                    break;
182
                default:
183
                    $GLOBALS['log']->info( "no type handler for $the_dir/$f with mime_content_type: " . mime_content_type( "$the_dir/$f" ) . "\n" );
184
            }
185
        }
186
    }
187
    return( $the_array );
188
}
189
190
191
function getBacktraceString() {
192
    ob_start();
193
    debug_print_backtrace();
194
    $contents = ob_get_contents();
195
    ob_end_clean();
196
    return $contents;
197
}
198
199
200
function findAllFiles( $the_dir, $the_array, $include_dirs=false, $ext='', $exclude_dir=''){
201
	// jchi  #24296
202
	if(!empty($exclude_dir)){
203
		$exclude_dir = is_array($exclude_dir)?$exclude_dir:array($exclude_dir);
204
		foreach($exclude_dir as $ex_dir){
205
			if($the_dir == $ex_dir){
206
				  return $the_array;
207
			}
208
		}
209
	}
210
	$the_dir = rtrim($the_dir, "/\\");
211
	//end
212
    if(!is_dir($the_dir)) {
213
		return $the_array;
214
	}
215
	$d = dir($the_dir);
216
217
    if(is_null($d)) {
218
        $backtrace = getBacktraceString();
219
        $emsg = 'wrong parameter for dir() function: ' . $the_dir . "\n" . $backtrace;
220
        $GLOBALS['log']->fatal($emsg);
221
        return $the_array;
222
    }
223
    if($d === false) {
224
        $backtrace = getBacktraceString();
225
        $emsg = 'dir() function return with another error: ' . $the_dir . "\n" . $backtrace;
226
        $GLOBALS['log']->fatal($emsg);
227
        return $the_array;
228
    }
229
230
    while (false !== ($f = $d->read())) {
231
        if( $f == "." || $f == ".." ){
232
            continue;
233
        }
234
235
        if( is_dir( "$the_dir/$f" ) ) {
236
			// jchi  #24296
237
			if(!empty($exclude_dir)){
238
				//loop through array to compare directories..
239
				foreach($exclude_dir as $ex_dir){
0 ignored issues
show
The expression $exclude_dir of type array|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
240
					if("$the_dir/$f" == $ex_dir){
241
						  continue 2;
242
					}
243
				}
244
			}
245
			//end
246
247
			if($include_dirs) {
248
				$the_array[] = clean_path("$the_dir/$f");
249
			}
250
            $the_array = findAllFiles( "$the_dir/$f", $the_array, $include_dirs, $ext);
251
        } else {
252
			if(empty($ext) || preg_match('/'.$ext.'$/i', $f)){
253
				$the_array[] = "$the_dir/$f";
254
			}
255
        }
256
257
258
    }
259
    rsort($the_array);
260
    return $the_array;
261
}
262
263
function findAllFilesRelative( $the_dir, $the_array ){
264
    if(!is_dir($the_dir)) {
265
		return $the_array;
266
	}
267
    $original_dir   = getCwd();
268
    if(is_dir($the_dir)){
269
    	chdir( $the_dir );
270
    	$the_array = findAllFiles( ".", $the_array );
271
    	if(is_dir($original_dir)){
272
    		chdir( $original_dir );
273
    	}
274
    }
275
    return( $the_array );
276
}
277
278
/*
279
 * Obtain an array of files that have been modified after the $date_modified
280
 *
281
 * @param the_dir			the directory to begin the search
282
 * @param the_array			array to hold the results
283
 * @param date_modified		the date to use when searching for files that have
284
 * 							been modified
285
 * @param filter			optional regular expression filter
286
 *
287
 * return					an array containing all of the files that have been
288
 * 							modified since date_modified
289
 */
290
function findAllTouchedFiles( $the_dir, $the_array, $date_modified, $filter=''){
291
    if(!is_dir($the_dir)) {
292
		return $the_array;
293
	}
294
	$d = dir($the_dir);
295
    while (false !== ($f = $d->read())) {
296
        if( $f == "." || $f == ".." ){
297
            continue;
298
        }
299
        if( is_dir( "$the_dir/$f" ) ){
300
            // i think depth first is ok, given our cvs repo structure -Bob.
301
            $the_array = findAllTouchedFiles( "$the_dir/$f", $the_array, $date_modified, $filter);
302
        }
303
        else {
304
        	$file_date = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s', filemtime("$the_dir/$f"))) - date('Z'));
305
306
        	if(strtotime($file_date) > strtotime($date_modified) && (empty($filter) || preg_match($filter, $f))){
307
        		 array_push( $the_array, "$the_dir/$f");
308
        	}
309
        }
310
    }
311
    return $the_array;
312
}
313