Issues (51)

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.

secure/getuser/index-functions.php (3 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
3
/**
4
 * This file contains functions called by index.php. The index.php
5
 * file should include this file with the following statement at the top:
6
 *
7
 * require_once __DIR__ . '/index-functions.php';
8
 */
9
10
use CILogon\Service\Util;
11
use CILogon\Service\Content;
12
use CILogon\Service\DBService;
13
use CILogon\Service\MyProxy;
14
use CILogon\Service\Loggit;
15
16
/**
17
 * getUID
18
 *
19
 * This function takes all of the various required SAML attributes (as
20
 * set in the current Shibboleth session) and makes a call to the
21
 * database (via the dbservice) to get the userid assoicated with
22
 * those attributes.  It sets several PHP session variables such as the
23
 * status code returned by the dbservice, the uid (if found), the
24
 * username to be passed to MyProxy ('distinguished_name'), etc.  If
25
 * there is some kind of error with the database call, an email is
26
 * sent showing which SAML attributes were missing.
27
 *
28
 * All 'returned' variables are stored in various  PHP session variables
29
 * (e.g. 'user_uid', 'distinguished_name', 'status').
30
 */
31
function getUID()
32
{
33
    $shibarray = Util::getIdpList()->getShibInfo();
34
35
    // Don't allow Organization Name to be empty
36
    if (strlen(@$shibarray['Organization Name']) == 0) {
37
        $shibarray['Organization Name'] = 'Unspecified';
38
    }
39
40
    // Extract Silver Level of Assurance from Shib-AuthnContext-Class
41
    if (
42
        preg_match(
43
            '%http://id.incommon.org/assurance/silver%',
44
            Util::getServerVar('Shib-AuthnContext-Class')
45
        )
46
    ) {
47
        $shibarray['Level of Assurance'] =
48
            'http://incommonfederation.org/assurance/silver';
49
    }
50
51
    // Check for session var 'storeattributes' which indicates to
52
    // simply store the user attributes in the PHP session.
53
    // If not set, then by default save the user attributes to
54
    // the database (which also stores the user attributes in
55
    // the PHP session).
56
    $func = 'CILogon\Service\Util::saveUserToDataStore';
57
    if (!empty(Util::getSessionVar('storeattributes'))) {
58
        $func = 'CILogon\Service\Util::setUserAttributeSessionVars';
59
    }
60
61
    // CIL-793 - Calculate missing first/last name for OAuth1
62
    $first_name = @$shibarray['First Name'];
63
    $last_name = @$shibarray['Last Name'];
64
    $display_name = @$shibarray['Display Name'];
65
    $callbackuri = Util::getSessionVar('callbackuri'); // OAuth 1.0a
66
    if (
67
        (strlen($callbackuri) > 0) &&
68
        ((strlen($first_name) == 0) ||
69
         (strlen($last_name) == 0))
70
    ) {
71
        list($first, $last) = Util::getFirstAndLastName(
72
            $display_name,
73
            $first_name,
74
            $last_name
75
        );
76
        $first_name = $first;
77
        $last_name = $last;
78
    }
79
80
    $func(
81
        @$shibarray['User Identifier'],
82
        @$shibarray['Identity Provider'],
83
        @$shibarray['Organization Name'],
84
        $first_name,
85
        $last_name,
86
        $display_name,
87
        @$shibarray['Email Address'],
88
        @$shibarray['Level of Assurance'],
89
        @$shibarray['ePPN'],
90
        @$shibarray['ePTID'],
91
        '', // OpenID 2.0 ID
92
        '', // OpenID Connect ID
93
        @$shibarray['Subject ID'],
94
        @$shibarray['Pairwise ID'],
95
        @$shibarray['Affiliation'],
96
        @$shibarray['OU'],
97
        @$shibarray['Member'],
98
        @$shibarray['Authn Context'],
99
        '', // ORCID AMR
100
        @$shibarray['Entitlement'],
101
        @$shibarray['iTrustUIN']
102
    );
103
}
104
105
/**
106
 * getUserAndRespond
107
 *
108
 * This function gets the user's database UID puts several variables
109
 * in the current PHP session, and responds by redirecting to the
110
 * responseurl in the passed-in parameter.  If there are any issues
111
 * with the database call, an email is sent to the CILogon admins.
112
 *
113
 * @param string $responseurl The full URL to redirect to after getting
114
 *        the userid.
115
 */
116
function getUserAndRespond($responseurl)
0 ignored issues
show
The function getUserAndRespond() has been defined more than once; this definition is ignored, only the first definition in getuser/index-functions.php (L22-144) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
117
{
118
    getUID(); // Get the user's database user ID, put info in PHP session
119
120
    // Finally, redirect to the calling script.
121
    header('Location: ' . $responseurl);
122
    exit; // No further processing necessary
123
}
124
125
/**
126
 * getPKCS12
127
 *
128
 * This function is called when an ECP client wants to get a PKCS12
129
 * credential.  It first attempts to get the user's database UID. If
130
 * successful, it tries to create a PKCS12 file on disk by calling
131
 * MyProxy.  If successful, it returns the PKCS12 file by setting the
132
 * HTTP Content-type.  If there is an error, it returns a plain text
133
 * file and sets the HTTP response code to an error code.
134
 */
135
function getPKCS12()
136
{
137
    $log = new Loggit();
138
139
    getUID(); // Get the user's database user ID, put info in PHP session
140
141
    $skin = Util::getSkin();
142
    $skin->init(); // Check for forced skin
143
144
    // If 'status' is not STATUS_OK*, then return error message
145
    if (Util::getSessionVar('status') & 1) { // Bad status codes are odd
146
        $errstr = array_search(Util::getSessionVar('status'), DBService::$STATUS);
147
        $log->info('ECP PKCS12 error: ' . $errstr . '.');
148
        outputError($errstr);
149
        Util::unsetAllUserSessionVars();
150
        return; // ERROR means no further processing is necessary
151
    }
152
153
    // CIL-624 Check if X509 certs are disabled
154
    if ((defined('DISABLE_X509')) && (DISABLE_X509 === true)) {
155
        $log->info('ECP PKCS12 error: Downloading certificates is ' .
156
            'disabled due to DISABLE_X509.');
157
        outputError('Downloading certificates is disabled.');
158
        Util::unsetAllUserSessionVars();
159
        return; // ERROR means no further processing is necessary
160
    }
161
162
    // Verify myproxy-logon binary is configured
163
    $disabledbyconf = ((!defined('MYPROXY_LOGON')) || (empty(MYPROXY_LOGON)));
164
    if ($disabledbyconf) {
165
        $log->info('ECP PKCS12 error: Downloading certificates is ' .
166
            'disabled due to myproxy-logon not configured.');
167
        outputError('Downloading certificates is disabled.');
168
        Util::unsetAllUserSessionVars();
169
        return; // ERROR means no further processing is necessary
170
    }
171
172
    $shibarray = Util::getIdpList()->getShibInfo();
173
    if (Util::isEduGAINAndGetCert(@$shibarray['Identity Provider'], @$shibarray['Organization Name'])) {
174
        $log->info('ECP PKCS12 error: Failed to get cert due to eduGAIN IdP restriction.');
175
        outputError('Failed to get cert due to eduGAIN IdP restriction.');
176
        return; // ERROR means no further processing is necessary
177
    }
178
179
    $skin->setMyProxyInfo();
180
    Content::generateP12();  // Try to create the PKCS12 credential file on disk
181
182
    // Look for the p12error PHP session variable. If set, return it.
183
    $p12error = Util::getSessionVar('p12error');
184
    if (strlen($p12error) > 0) {
185
        $log->info('ECP PKCS12 error: ' . $p12error);
186
        outputError($p12error);
187
    } else { // Try to read the .p12 file from disk and return it
188
        $p12 = Util::getSessionVar('p12');
189
        $p12expire = '';
190
        $p12link = '';
191
        $p12file = '';
192
        if (preg_match('/([^\s]*)\s(.*)/', $p12, $match)) {
193
            $p12expire = $match[1];
194
            $p12link = $match[2];
195
        }
196
        if ((strlen($p12link) > 0) && (strlen($p12expire) > 0)) {
197
            $p12file = file_get_contents($p12link);
198
        }
199
200
        if (strlen($p12file) > 0) {
201
            $log->info('ECP PKCS12 success!');
202
            // CIL-507 Special log message for XSEDE
203
            $email = Util::getSessionVar('email');
204
            $log->info("USAGE email=\"$email\" client=\"ECP\"");
205
            Util::logXSEDEUsage('ECP', $email);
0 ignored issues
show
The method logXSEDEUsage() does not seem to exist on object<CILogon\Service\Util>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
206
207
            header('Content-type: application/x-pkcs12');
208
            echo $p12file;
209
        } else {
210
            $log->info('ECP PKCS12 error: Missing or empty PKCS12 file.');
211
            outputError('Missing or empty PKCS12 file.');
212
        }
213
    }
214
}
215
216
/**
217
 * getCert
218
 *
219
 * This function is called when an ECP client wants to get a PEM-
220
 * formatted X.509 certificate by inputting a certificate request
221
 * generated by 'openssl req'.  It first attempts to get the user's
222
 * database UID. If successful, it calls out to myproxy-logon to get
223
 * a certificate. If successful, it returns the certificate by setting
224
 * the HTTP Content-type to 'text/plain'.  If there is an error, it
225
 * returns a plain text file and sets the HTTP response code to an
226
 * error code.
227
 */
228
function getCert()
229
{
230
    $log = new Loggit();
231
232
    // Verify that a non-empty certreq <form> variable was posted
233
    $certreq = Util::getPostVar('certreq');
234
    if (strlen($certreq) == 0) {
235
        $log->info('ECP certreq error: Missing certificate request.');
236
        outputError('Missing certificate request.');
237
        return; // ERROR means no further processing is necessary
238
    }
239
240
    getUID(); // Get the user's database user ID, put info in PHP session
241
242
    $skin = Util::getSkin();
243
    $skin->init(); // Check for forced skin
244
245
    // If 'status' is not STATUS_OK*, then return error message
246
    if (Util::getSessionVar('status') & 1) { // Bad status codes are odd
247
        $errstr = array_search(Util::getSessionVar('status'), DBService::$STATUS);
248
        $log->info('ECP certreq error: ' . $errstr . '.');
249
        outputError($errstr);
250
        Util::unsetAllUserSessionVars();
251
        return; // ERROR means no further processing is necessary
252
    }
253
254
    // CIL-624 Check if X509 certs are disabled
255
    if ((defined('DISABLE_X509')) && (DISABLE_X509 === true)) {
256
        $log->info('ECP certreq error: Downloading certificates is ' .
257
            'disabled due to DISABLE_X509.');
258
        outputError('Downloading certificates is disabled.');
259
        Util::unsetAllUserSessionVars();
260
        return; // ERROR means no further processing is necessary
261
    }
262
263
    // Verify myproxy-logon binary is configured
264
    $disabledbyconf = ((!defined('MYPROXY_LOGON')) || (empty(MYPROXY_LOGON)));
265
    if ($disabledbyconf) {
266
        $log->info('ECP certreq error: Downloading certificates is ' .
267
            'disabled due to myproxy-logon not configured.');
268
        outputError('Downloading certificates is disabled.');
269
        Util::unsetAllUserSessionVars();
270
        return; // ERROR means no further processing is necessary
271
    }
272
273
    $shibarray = Util::getIdpList()->getShibInfo();
274
    if (Util::isEduGAINAndGetCert(@$shibarray['Identity Provider'], @$shibarray['Organization Name'])) {
275
        $log->info('ECP certreq error: Failed to get cert due to eduGAIN IdP restriction.');
276
        outputError('Failed to get cert due to eduGAIN IdP restriction.');
277
        return; // ERROR means no further processing is necessary
278
    }
279
280
    // Get the certificate lifetime. Set to a default value if not set.
281
    $certlifetime = (int)(Util::getPostVar('certlifetime'));
282
    if ($certlifetime == 0) {  // If not specified, set to default value
283
        $defaultlifetime = $skin->getConfigOption('ecp', 'defaultlifetime');
284
        if ((!is_null($defaultlifetime)) && ((int)$defaultlifetime > 0)) {
285
            $certlifetime = (int)$defaultlifetime;
286
        } else {
287
            $certlifetime = MyProxy::getDefaultLifetime();
288
        }
289
    }
290
291
    // Make sure lifetime is within acceptable range. 277 hrs = 1000000 secs.
292
    list($minlifetime, $maxlifetime) = Util::getMinMaxLifetimes('ecp', 277);
293
    if ($certlifetime < $minlifetime) {
294
        $certlifetime = $minlifetime;
295
    } elseif ($certlifetime > $maxlifetime) {
296
        $certlifetime = $maxlifetime;
297
    }
298
299
    // Make sure that the user's MyProxy username is available.
300
    $dn = Util::getSessionVar('distinguished_name');
301
    if (strlen($dn) > 0) {
302
        // Append extra info, such as 'skin', to be processed by MyProxy.
303
        $skin->setMyProxyInfo();
304
        $myproxyinfo = Util::getSessionVar('myproxyinfo');
305
        if (strlen($myproxyinfo) > 0) {
306
            $dn .= " $myproxyinfo";
307
        }
308
        // Attempt to fetch a credential from the MyProxy server
309
        $cert = MyProxy::getMyProxyCredential(
310
            $dn,
311
            '',
312
            MYPROXY_HOST,
313
            Util::getLOAPort(),
314
            $certlifetime,
315
            MYPROXY_CLIENT_CRED,
316
            '',
317
            $certreq
318
        );
319
320
        if (strlen($cert) > 0) { // Successfully got a certificate!
321
            $log->info('ECP getcert success!');
322
            // CIL-507 Special log message for XSEDE
323
            $email = Util::getSessionVar('email');
324
            $log->info("USAGE email=\"$email\" client=\"ECP\"");
325
            Util::logXSEDEUsage('ECP', $email);
0 ignored issues
show
The method logXSEDEUsage() does not seem to exist on object<CILogon\Service\Util>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
326
327
            header('Content-type: text/plain');
328
            echo $cert;
329
        } else { // The myproxy-logon command failed - shouldn't happen!
330
            $log->info('ECP certreq error: MyProxy unable to create certificate.');
331
            outputError('Error! MyProxy unable to create certificate.');
332
        }
333
    } else { // Couldn't find the 'distinguished_name' PHP session value
334
        $log->info('ECP certreq error: Missing \'distinguished_name\' session value.');
335
        outputError('Cannot create certificate due to missing attributes.');
336
    }
337
}
338
339
/**
340
 * outputError
341
 *
342
 * This function sets the HTTP return type to 'text/plain' and also
343
 * sets the HTTP return code to 400, meaning there was an error of
344
 * some kind.  If there is also a passed in errstr, that is output as
345
 * the body of the HTTP return.
346
 * @param string $errstr (Optional) The error string to print in the
347
 *        text/plain return body.
348
 */
349
function outputError($errstr = '')
350
{
351
    header('Content-type: text/plain', true, 400);
352
    if (strlen($errstr) > 0) {
353
        echo $errstr;
354
    }
355
}
356