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.

ModuleBuilder/parsers/parser.modifysubpanel.php (6 issues)

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)
3
    die ( 'Not A Valid Entry Point' ) ;
4
/*********************************************************************************
5
 * SugarCRM Community Edition is a customer relationship management program developed by
6
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
7
8
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
9
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
10
 *
11
 * This program is free software; you can redistribute it and/or modify it under
12
 * the terms of the GNU Affero General Public License version 3 as published by the
13
 * Free Software Foundation with the addition of the following permission added
14
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
15
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
16
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
21
 * details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License along with
24
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
25
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26
 * 02110-1301 USA.
27
 *
28
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
29
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
30
 *
31
 * The interactive user interfaces in modified source and object code versions
32
 * of this program must display Appropriate Legal Notices, as required under
33
 * Section 5 of the GNU Affero General Public License version 3.
34
 *
35
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
36
 * these Appropriate Legal Notices must retain the display of the "Powered by
37
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
38
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
39
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
40
 ********************************************************************************/
41
42
43
44
/*
45
 * Modify an exising Subpanel
46
 * Typically called from Studio for a deployed (OOB or installed custom module)
47
 * 
48
 * Uses the listview editor to modify the subpanel
49
 * Uses SubPanelDefinitions to load the definitions for the subpanel, and SubPanel to save them, using the unique SubPanel override mechanism
50
 * There are two relevant modules for every subpanel - the module whose detailview this subpanel will appear in ($module_name), and the module that is the source of the data for the subpanel ($subPanelParentModule)
51
 */
52
53
require_once ('modules/ModuleBuilder/parsers/parser.modifylistview.php') ;
54
55
class ParserModifySubPanel extends ParserModifyListView
56
{
57
    
58
    var $listViewDefs = false ;
59
    var $defaults = array ( ) ;
60
    var $additional = array ( ) ;
61
    var $available = array ( ) ;
62
    var $columns = array ( 'LBL_DEFAULT' => 'getDefaultFields' , 'LBL_HIDDEN' => 'getAvailableFields' ) ;
63
    
64
    function init ($module_name , $subPanelName)
65
    {
66
        $GLOBALS [ 'log' ]->debug ( "in ParserModifySubPanel: module_name={$module_name} child_module={$subPanelName}" ) ;
67
        $this->moduleName = $module_name ;
68
        $this->subPanelName = $subPanelName ;
69
        global $beanList, $beanFiles ;
70
        
71
        // Sometimes we receive a module name which is not in the correct CamelCase, so shift to lower case for all beanList lookups
72
        $beanListLower = array_change_key_case ( $beanList ) ;
73
        
74
        // Retrieve the definitions for all the available subpanels for this module
75
        $class = $beanListLower [ strtolower ( $this->moduleName ) ] ;
76
        require_once ($beanFiles [ $class ]) ;
77
        $module = new $class ( ) ;
78
        require_once ('include/SubPanel/SubPanelDefinitions.php') ;
79
        $spd = new SubPanelDefinitions ( $module ) ;
80
        
81
        // Get the lists of fields already in the subpanel and those that can be added in
82
        // Get the fields lists from an aSubPanel object describing this subpanel from the SubPanelDefinitions object
83
        $this->originalListViewDefs = array ( ) ;
84
        if (array_key_exists ( strtolower ( $this->subPanelName ), $spd->layout_defs [ 'subpanel_setup' ] ))
85
        {
86
            $originalPanel = $spd->load_subpanel ( $this->subPanelName, true ) ;
87
            $this->originalListViewDefs = $originalPanel->get_list_fields () ;
88
            $this->panel = $spd->load_subpanel ( $subPanelName, false ) ;
89
            $this->listViewDefs = $this->panel->get_list_fields () ;
90
            
91
            // Retrieve a copy of the bean for the parent module of this subpanel - so we can find additional fields for the layout
92
            $subPanelParentModuleName = $this->panel->get_module_name () ;
93
            $this->subPanelParentModule = null ;
94
95
            if (! empty ( $subPanelParentModuleName ) && isset($beanListLower[strtolower($subPanelParentModuleName)]))
96
            {
97
                $class = $beanListLower[strtolower($subPanelParentModuleName)];
98
                if (isset($beanFiles [ $class ]))
99
                {
100
                    require_once ($beanFiles [ $class ]) ;
101
                    $this->subPanelParentModule = new $class ( ) ;
102
                }
103
            }
104
        }
105
        
106
        $this->language_module = $this->panel->template_instance->module_dir ;
107
    }
108
    
109
    /**
110
     * Return a list of the fields that will be displayed in the subpanel
111
     */
112
    function getDefaultFields ()
113
    {
114
        $this->defaults = array ( ) ;
115
        foreach ( $this->listViewDefs as $key => $def )
0 ignored issues
show
The expression $this->listViewDefs of type boolean is not traversable.
Loading history...
116
        {
117
            if (! empty ( $def [ 'usage' ] ) && strcmp ( $def [ 'usage' ], 'query_only' ) == 0)
118
                continue ;
119
            if (! empty ( $def [ 'vname' ] ))
120
                $def [ 'label' ] = $def [ 'vname' ] ;
121
            $this->defaults [ $key ] = $def ;
122
        }
123
        return $this->defaults ;
124
    }
125
    
126
    /**
127
     * Return a list of fields that are not currently included in the subpanel but that are available for use
128
     */
129
    function getAvailableFields ()
130
    {
131
        $this->availableFields = array ( ) ;
132
        if ($this->subPanelParentModule != null)
133
        {
134
            $lowerFieldList = array_change_key_case ( $this->listViewDefs ) ;
135
            foreach ( $this->originalListViewDefs as $key => $def )
136
            {
137
                $key = strtolower ( $key ) ;
138
                if (! isset ( $lowerFieldList [ $key ] ))
139
                {
140
                    $this->availableFields [ $key ] = $def ;
141
                }
142
            }
143
            $GLOBALS [ 'log' ]->debug ( 'parser.modifylistview.php->getAvailableFields(): field_defs=' . print_r ( $this->availableFields, true ) ) ;
144
            foreach ( $this->subPanelParentModule->field_defs as $key => $fieldDefinition )
145
            {
146
                $fieldName = strtolower ( $key ) ;
147
                if (! isset ( $lowerFieldList [ $fieldName ] )) // bug 16728 - check this first, so that other conditions (e.g., studio == visible) can't override and add duplicate entries
148
                {
149
                    if ((empty ( $fieldDefinition [ 'source' ] ) || $fieldDefinition [ 'source' ] == 'db' || $fieldDefinition [ 'source' ] == 'custom_fields') && $fieldDefinition [ 'type' ] != 'id' && strcmp ( $fieldName, 'deleted' ) != 0 || (isset ( $def [ 'name' ] ) && strpos ( $def [ 'name' ], "_name" ) != false) || ! empty ( $def [ 'custom_type' ] ) && (empty ( $fieldDefinition [ 'dbType' ] ) || $fieldDefinition [ 'dbType' ] != 'id') && (empty ( $fieldDefinition [ 'dbtype' ] ) || $fieldDefinition [ 'dbtype' ] != 'id') || (! empty ( $fieldDefinition [ 'studio' ] ) && $fieldDefinition [ 'studio' ] == 'visible'))
0 ignored issues
show
The variable $def seems to be defined by a foreach iteration on line 135. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($def['name'], '_name') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
150
                    {
151
                        $label = (isset ( $fieldDefinition [ 'vname' ] )) ? $fieldDefinition [ 'vname' ] : (isset ( $fieldDefinition [ 'label' ] ) ? $fieldDefinition [ 'label' ] : $fieldDefinition [ 'name' ]) ;
152
                        $this->availableFields [ $fieldName ] = array ( 'width' => '10' , 'label' => $label ) ;
153
                    }
154
                }
155
            }
156
        }
157
        
158
        return $this->availableFields ;
159
    }
160
    
161
    function getField ($fieldName)
162
    {
163
        foreach ( $this->listViewDefs as $key => $def )
0 ignored issues
show
The expression $this->listViewDefs of type boolean is not traversable.
Loading history...
164
        {
165
            $key = strtolower ( $key ) ;
166
            if ($key == $fieldName)
167
            {
168
                return $def ;
169
            }
170
        }
171
        foreach ( $this->originalListViewDefs as $key => $def )
172
        {
173
            $key = strtolower ( $key ) ;
174
            if ($key == $fieldName)
175
            {
176
                return $def ;
177
            }
178
        }
179
        foreach ( $this->panel->template_instance->field_defs as $key => $def )
180
        {
181
            $key = strtolower ( $key ) ;
182
            if ($key == $fieldName)
183
            {
184
                return $def ;
185
            }
186
        }
187
        return array ( ) ;
188
    }
189
    
190
    /*
191
     * Save the modified definitions for a subpanel
192
     * Obtains the field definitions from a _REQUEST array, and merges them with the other fields from the original definitions
193
     * Uses the subpanel override mechanism from SubPanel to save them 
194
     */
195
    function handleSave ()
196
    {
197
        $GLOBALS [ 'log' ]->debug ( "in ParserModifySubPanel->handleSave()" ) ;
198
        require_once ('include/SubPanel/SubPanel.php') ;
199
        $subpanel = new SubPanel ( $this->moduleName, 'fab4', $this->subPanelName, $this->panel ) ;
200
        
201
        $newFields = array ( ) ;
202
        foreach ( $this->listViewDefs as $name => $field )
0 ignored issues
show
The expression $this->listViewDefs of type boolean is not traversable.
Loading history...
203
        {
204
            if (! isset ( $field [ 'usage' ] ) || $field [ 'usage' ] != 'query_only')
205
            {
206
                $existingFields [ $name ] = $field ;
207
            
208
            } else
209
            {
210
                $newFields [ $name ] = $field ;
211
            }
212
        }
213
        
214
        // Loop through all of the fields defined in the 'Default' group of the ListView data in $_REQUEST
215
        // Replace the field specification in the originalListViewDef with this new updated specification
216
        foreach ( $_REQUEST [ 'group_0' ] as $field )
217
        {
218
            if (! empty ( $this->originalListViewDefs [ $field ] ))
219
            {
220
                $newFields [ $field ] = $this->originalListViewDefs [ $field ] ;
221
            } else
222
            {
223
                
224
                $vname = '' ;
225
                if (isset ( $this->panel->template_instance->field_defs [ $field ] ))
226
                {
227
                    $vname = $this->panel->template_instance->field_defs [ $field ] [ 'vname' ] ;
228
                }
229
                if (($this->subPanelParentModule != null) && (isset ( $this->subPanelParentModule->field_name_map [ $field ] ) && ($this->subPanelParentModule->field_name_map [ $field ] [ 'type' ] == 'bool' || (isset ( $this->subPanelParentModule->field_name_map [ $field ] [ 'custom_type' ] ) && $this->subPanelParentModule->field_name_map [ $field ] [ 'custom_type' ] == 'bool'))))
230
                {
231
                    $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname , 'widget_type' => 'checkbox' ) ;
232
                } else
233
                {
234
                    $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname ) ;
235
                }
236
            }
237
            
238
            // Now set the field width if specified in the $_REQUEST data
239
            if (isset ( $_REQUEST [ strtolower ( $field ) . 'width' ] ))
240
            {
241
                $width = substr ( $_REQUEST [ strtolower ( $field ) . 'width' ], 6, 3 ) ;
242
                if (strpos ( $width, "%" ) != false)
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($width, '%') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
243
                {
244
                    $width = substr ( $width, 0, 2 ) ;
245
                }
246
                if ($width < 101 && $width > 0)
247
                {
248
                    $newFields [ $field ] [ 'width' ] = $width ;
249
                }
250
            } else if (isset ( $this->listViewDefs [ $field ] [ 'width' ] ))
251
            {
252
                $newFields [ $field ] [ 'width' ] = $this->listViewDefs [ $field ] [ 'width' ] ;
253
            }
254
        }
255
        $subpanel->saveSubPanelDefOverride ( $this->panel, 'list_fields', $newFields ) ;
256
    
257
    }
258
259
}
260
?>
261