Issues (48)

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.

src/Password/DjangoPassword.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
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2014 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Garden\Password;
9
10
/**
11
 * Implements tha password hashing algorithm from the Django framework.
12
 */
13
class DjangoPassword implements IPassword {
14
    /**
15
     * @var string The hash method to use when hashing passwords.
16
     */
17
    public $hashMethod;
18
19
    /**
20
     * Initiailize an instance of the {@link DjangoPassword} class.
21
     *
22
     * @param string $hashMethod The hasm method used to hash the passwords.
23
     */
24 5
    public function __construct($hashMethod = 'crypt') {
25 5
        $this->hashMethod = $hashMethod;
26 5
    }
27
28
    /**
29
     * Generate a random salt that is compatible with {@link crypt()}.
30
     *
31
     * @return string|null Returns the salt as a string or **null** if the crypt algorithm isn't known.
32
     */
33 4
    protected function generateCryptSalt() {
34 4
        if (CRYPT_BLOWFISH === 1) {
35 4
            $salt = str_replace('+', '/', base64_encode(openssl_random_pseudo_bytes(12)));
36 4
        } elseif (CRYPT_EXT_DES) {
37
            $count_log2 = 24; //min($this->iteration_count_log2 + 8, 24);
38
            # This should be odd to not reveal weak DES keys, and the
39
            # maximum valid value is (2**24 - 1) which is odd anyway.
40
            $count = (1 << $count_log2) - 1;
41
42
            $salt = '_';
43
            $salt .= $this->itoa64[$count & 0x3f];
0 ignored issues
show
The property itoa64 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
            $salt .= $this->itoa64[($count >> 6) & 0x3f];
45
            $salt .= $this->itoa64[($count >> 12) & 0x3f];
46
            $salt .= $this->itoa64[($count >> 18) & 0x3f];
47
48
            $salt .= substr(base64_encode(openssl_random_pseudo_bytes(3), 0, 3));
49
        } else {
50
            $salt = null;
51
        }
52 4
        return $salt;
53
    }
54
55
    /**
56
     * Hashes a plaintext password.
57
     *
58
     * @param string $password The password to hash.
59
     * @return string Returns the hashed password.
60
     * @throws \Exception Throws an exception when the hash method is invalid.
61
     */
62 8
    public function hash($password) {
63 8
        if ($this->hashMethod === 'crypt') {
64 4
            $salt = $this->generateCryptSalt();
65
            try {
66 4
                $hash = crypt($password, $salt);
67 4
            } catch (\Exception $ex) {
68
                throw new \Exception("$salt is an invalid salt.", $ex);
69
            }
70 8
        } elseif (in_array($this->hashMethod, hash_algos())) {
71 4
            $salt = base64_encode(openssl_random_pseudo_bytes(12));
72 4
            $hash = hash($this->hashMethod, $salt.$password);
73 4
        } else {
74 1
            throw new \Exception("The {$this->hashMethod} hash method is invalid.", 500);
75
        }
76
77 8
        $result = $this->hashMethod.'$'.$salt.'$'.$hash;
78 8
        return $result;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 6
    public function needsRehash($hash) {
85 6
        if (strpos($hash, '$') === false) {
86 1
            return true;
87
        } else {
88 6
            list($method,,) = explode('$', $hash, 3);
89 6
            switch (strtolower($method)) {
90 6
                case 'crypt':
91 6
                case 'sha256':
92 3
                    return false;
93 3
                default:
94 3
                    return true;
95 3
            }
96
        }
97
    }
98
99
    /**
100
     * Check to make sure a password matches its stored hash.
101
     *
102
     * @param string $password The password to verify.
103
     * @param string $hash The stored password hash.
104
     * @return bool Returns `true` if the password matches the stored hash.
105
     */
106 8
    public function verify($password, $hash) {
107 8
        if (strpos($hash, '$') === false) {
108 5
            return md5($password) == $hash;
109
        } else {
110 7
            list($method, $salt, $rawHash) = explode('$', $hash);
111
112 7
            if ($method === 'crypt') {
113 3
                return crypt($password, $salt) === $rawHash;
114 4
            } elseif (in_array($method, hash_algos())) {
115 3
                return hash($method, $salt.$password) === $rawHash;
116
            } else {
117 1
                return false;
118
            }
119
        }
120
    }
121
}
122