Issues (180)

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.

code/model/LDAPUtil.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
/**
3
 * Class LDAPUtil
4
 *
5
 * Provides some commonly used functions for LDAP and SAML.
6
 */
7
class LDAPUtil
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * Checks if the string is a valid guid in the format of A98C5A1E-A742-4808-96FA-6F409E799937
11
     *
12
     * @param $guid
13
     * @return bool
14
     */
15
    public static function validGuid($guid)
16
    {
17
        if (preg_match('/^[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}?$/', $guid)) {
18
            return true;
19
        }
20
        return false;
21
    }
22
23
    public static function bin_to_str_guid($object_guid)
24
    {
25
        $hex_guid = bin2hex($object_guid);
26
        $hex_guid_to_guid_str = '';
27 View Code Duplication
        for ($k = 1; $k <= 4; ++$k) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
            $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
29
        }
30
        $hex_guid_to_guid_str .= '-';
31 View Code Duplication
        for ($k = 1; $k <= 2; ++$k) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
            $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
33
        }
34
        $hex_guid_to_guid_str .= '-';
35 View Code Duplication
        for ($k = 1; $k <= 2; ++$k) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
            $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
37
        }
38
        $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
39
        $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
40
41
        return strtoupper($hex_guid_to_guid_str);
42
    }
43
44
    public static function str_to_hex_guid($str_guid, $escape = false)
45
    {
46
        $str_guid = str_replace('-', '', $str_guid);
47
48
        $octet_str = substr($str_guid, 6, 2);
49
        $octet_str .= substr($str_guid, 4, 2);
50
        $octet_str .= substr($str_guid, 2, 2);
51
        $octet_str .= substr($str_guid, 0, 2);
52
        $octet_str .= substr($str_guid, 10, 2);
53
        $octet_str .= substr($str_guid, 8, 2);
54
        $octet_str .= substr($str_guid, 14, 2);
55
        $octet_str .= substr($str_guid, 12, 2);
56
        $octet_str .= substr($str_guid, 16, strlen($str_guid));
57
58
        if ($escape) {
59
            $escaped = '\\';
60
            for ($i = 0; $i < strlen($octet_str); $i+=2) {
61
                $escaped .= substr($octet_str, $i, 2);
62
                if ($i != strlen($octet_str) - 2) {
63
                    $escaped .= '\\';
64
                }
65
            }
66
            return $escaped;
67
        }
68
69
        return $octet_str;
70
    }
71
72
    public static function bin_to_str_sid($binsid)
73
    {
74
        $hex_sid = bin2hex($binsid);
75
        $rev = hexdec(substr($hex_sid, 0, 2));
76
        $subcount = hexdec(substr($hex_sid, 2, 2));
77
        $auth = hexdec(substr($hex_sid, 4, 12));
78
        $result = "$rev-$auth";
79
80
        for ($x=0;$x < $subcount; $x++) {
81
            $subauth[$x] = hexdec(self::little_endian(substr($hex_sid, 16 + ($x * 8), 8)));
0 ignored issues
show
Coding Style Comprehensibility introduced by
$subauth was never initialized. Although not strictly required by PHP, it is generally a good practice to add $subauth = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
82
            $result .= "-" . $subauth[$x];
0 ignored issues
show
The variable $subauth does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
83
        }
84
85
        // Cheat by tacking on the S-
86
        return 'S-' . $result;
87
    }
88
89
    // Converts a little-endian hex-number to one, that 'hexdec' can convert
90
    public static function little_endian($hex)
91
    {
92
        $result = '';
93
        for ($x = strlen($hex) - 2; $x >= 0; $x = $x - 2) {
94
            $result .= substr($hex, $x, 2);
95
        }
96
        return $result;
97
    }
98
}
99