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/externalAPI/Base/ExternalAPIBase.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
/*********************************************************************************
3
 * SugarCRM Community Edition is a customer relationship management program developed by
4
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5
6
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
7
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
8
 *
9
 * This program is free software; you can redistribute it and/or modify it under
10
 * the terms of the GNU Affero General Public License version 3 as published by the
11
 * Free Software Foundation with the addition of the following permission added
12
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15
 *
16
 * This program is distributed in the hope that it will be useful, but WITHOUT
17
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19
 * details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License along with
22
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
23
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
 * 02110-1301 USA.
25
 *
26
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
28
 *
29
 * The interactive user interfaces in modified source and object code versions
30
 * of this program must display Appropriate Legal Notices, as required under
31
 * Section 5 of the GNU Affero General Public License version 3.
32
 *
33
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34
 * these Appropriate Legal Notices must retain the display of the "Powered by
35
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
36
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
37
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
38
 ********************************************************************************/
39
40
41
require_once ('include/externalAPI/Base/ExternalAPIPlugin.php');
42
require_once ('include/externalAPI/Base/ExternalOAuthAPIPlugin.php');
43
require_once('include/connectors/sources/SourceFactory.php');
44
45
/**
46
 * Base implementation for external API
47
 * @api
48
 */
49
abstract class ExternalAPIBase implements ExternalAPIPlugin
50
{
51
    public $account_name;
52
    public $account_password;
53
    public $authMethod = 'password';
54
    public $useAuth = true;
55
    public $requireAuth = true;
56
57
    const APP_STRING_ERROR_PREFIX = 'ERR_EXTERNAL_API_';
58
    protected $_appStringErrorPrefix = self::APP_STRING_ERROR_PREFIX;
59
60
    /**
61
     * Authorization data
62
     * @var EAPM
63
     */
64
    protected $authData;
65
66
    /**
67
     * Load authorization data
68
     * @param EAPM $eapmBean
69
     * @see ExternalAPIPlugin::loadEAPM()
70
     */
71
    public function loadEAPM($eapmBean)
72
    {
73
        // FIXME: check if the bean is validated, if not, refuse it?
74
        $this->eapmBean = $eapmBean;
75
        if ($this->authMethod == 'password') {
76
            $this->account_name = $eapmBean->name;
77
            $this->account_password = $eapmBean->password;
78
        }
79
        return true;
80
    }
81
82
    /**
83
     * Check login
84
     * @param EAPM $eapmBean
85
     * @see ExternalAPIPlugin::checkLogin()
86
     */
87
    public function checkLogin($eapmBean = null)
88
    {
89
        if(!empty($eapmBean)) {
90
            $this->loadEAPM($eapmBean);
91
        }
92
93
        if ( !isset($this->eapmBean) ) {
94
            return array('success' => false);
95
        }
96
97
        return array('success' => true);
98
    }
99
100
    public function quickCheckLogin()
101
    {
102
        if ( !isset($this->eapmBean) ) {
103
            return array('success' => false, 'errorMessage' => translate('LBL_ERR_NO_AUTHINFO','EAPM'));
104
        }
105
106
        if ( $this->eapmBean->validated==0 ) {
107
            return array('success' => false, 'errorMessage' => translate('LBL_ERR_NO_AUTHINFO','EAPM'));
108
        }
109
110
        return array('success' => true);
111
    }
112
113
    protected function getValue($value)
114
    {
115
        if(!empty($this->$value)) {
116
            return $this->$value;
117
        }
118
        return null;
119
    }
120
121
    public function logOff()
122
    {
123
        // Not sure if we should do anything.
124
        return true;
125
    }
126
127
    /**
128
     * Does API support this method?
129
     * @see ExternalAPIPlugin::supports()
130
     */
131
    public function supports($method = '')
132
	{
133
        return $method==$this->authMethod;
134
	}
135
136
	protected function postData($url, $postfields, $headers)
137
	{
138
        $ch = curl_init($url);
139
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
140
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
141
        
142
        $proxy_config = SugarModule::get('Administration')->loadBean();
143
        $proxy_config->retrieveSettings('proxy');
144
        
145
        if( !empty($proxy_config) && 
146
            !empty($proxy_config->settings['proxy_on']) &&
147
            $proxy_config->settings['proxy_on'] == 1) {
148
149
            curl_setopt($ch, CURLOPT_PROXY, $proxy_config->settings['proxy_host']);
150
            curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_config->settings['proxy_port']);
151
            if (!empty($proxy_settings['proxy_auth'])) {
0 ignored issues
show
The variable $proxy_settings seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
152
                curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_settings['proxy_username'] . ':' . $proxy_settings['proxy_password']);
153
            }
154
        }   
155
        
156
        if ( ( is_array($postfields) && count($postfields) == 0 ) ||
157
             empty($postfields) ) {
158
            curl_setopt($ch, CURLOPT_POST, false);
159
        } else {
160
            curl_setopt($ch, CURLOPT_POST, true);
161
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
162
        }
163
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
164
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
165
166
        $GLOBALS['log']->debug("ExternalAPIBase->postData Where: ".$url);
167
        $GLOBALS['log']->debug("Headers:\n".print_r($headers,true));
168
        // $GLOBALS['log']->debug("Postfields:\n".print_r($postfields,true));
169
        $rawResponse = curl_exec($ch);
170
        $GLOBALS['log']->debug("Got:\n".print_r($rawResponse,true));
171
172
        return $rawResponse;
173
	}
174
175
	/**
176
	 * Get connector for this API
177
	 * @return source|null
178
	 */
179
	public function getConnector()
180
	{
181
	    if(isset($this->connector)) {
182
	        if(empty($this->connector_source)) {
183
	            $this->connector_source = SourceFactory::getSource($this->connector, false);
184
                $this->connector_source->setEAPM($this);
185
	        }
186
	        return $this->connector_source;
187
	    }
188
	    return null;
189
	}
190
191
	/**
192
	 * Get parameter from source
193
	 * @param string $name
194
	 * @return mixed
195
	 */
196
	public function getConnectorParam($name)
197
	{
198
        $connector =  $this->getConnector();
199
        if(empty($connector)) return null;
200
        return $connector->getProperty($name);
201
	}
202
203
204
	/**
205
	 * formatCallbackURL
206
	 *
207
	 * This function takes a callback_url and checks the $_REQUEST variable to see if
208
	 * additional parameters should be appended to the callback_url value.  The $_REQUEST variables
209
	 * that are being checked deal with handling the behavior of closing/hiding windows/tabs that
210
	 * are displayed when prompting for OAUTH validation
211
	 *
212
	 * @param $callback_url String value of callback URL
213
	 * @return String value of URL with applicable formatting
214
	 */
215
	protected function formatCallbackURL($callback_url)
216
	{
217
		 // This is a tweak so that we can automatically close windows if requested by the external account system
218
	     if (isset($_REQUEST['closeWhenDone']) && $_REQUEST['closeWhenDone'] == 1 ) {
219
             $callback_url .= '&closeWhenDone=1';
220
         }
221
222
         //Pass back the callbackFunction to call on the window.opener object
223
         if (!empty($_REQUEST['callbackFunction']))
224
         {
225
             $callback_url .= '&callbackFunction=' . $_REQUEST['callbackFunction'];
226
         }
227
228
         //Pass back the id of the application that triggered this oauth login
229
         if (!empty($_REQUEST['application']))
230
         {
231
             $callback_url .= '&application=' . $_REQUEST['application'];
232
         }
233
234
	     //Pass back the id of the application that triggered this oauth login
235
         if (!empty($_REQUEST['refreshParentWindow']))
236
         {
237
             $callback_url .= '&refreshParentWindow=' . $_REQUEST['refreshParentWindow'];
238
         }
239
240
         return $callback_url;
241
	}
242
243
	/**
244
	 * Allow API clients to provide translated language strings for a given error code
245
	 *
246
	 * @param unknown_type $error_numb
247
	 */
248
	protected function getErrorStringFromCode($error_numb)
249
	{
250
	    $language_key = $this->_appStringErrorPrefix . $error_numb;
251
	    if( isset($GLOBALS['app_strings'][$language_key]) )
252
	       return $GLOBALS['app_strings'][$language_key];
253
	    else
254
	       return $GLOBALS['app_strings']['ERR_EXTERNAL_API_SAVE_FAIL'];
255
	}
256
257
    /**
258
     * Determine if mime detection extensions are available.
259
     *
260
     * @return bool
261
     */
262
    public function isMimeDetectionAvailable()
263
	{
264
	    return ( function_exists('mime_content_type') || function_exists( 'ext2mime' ) );
265
	}
266
}
267