Issues (1240)

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.

system/libraries/Encrypt.php (4 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 defined('SYSPATH') or die('No direct access allowed.');
2
/**
3
 * The Encrypt library provides two-way encryption of text and binary strings
4
 * using the MCrypt extension.
5
 * @see http://php.net/mcrypt
6
 *
7
 * $Id: Encrypt.php 4072 2009-03-13 17:20:38Z jheathco $
8
 *
9
 * @package    Core
10
 * @author     Kohana Team
11
 * @copyright  (c) 2007-2008 Kohana Team
12
 * @license    http://kohanaphp.com/license.html
13
 */
14
class Encrypt_Core
15
{
16
17
    // OS-dependant RAND type to use
18
    protected static $rand;
19
20
    // Configuration
21
    protected $config;
22
23
    /**
24
     * Returns a singleton instance of Encrypt.
25
     *
26
     * @param   array  configuration options
27
     * @return  Encrypt_Core
0 ignored issues
show
Should the return type not be Encrypt?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
28
     */
29
    public static function instance($config = null)
30
    {
31
        static $instance;
32
33
        // Create the singleton
34
        empty($instance) and $instance = new Encrypt((array) $config);
35
36
        return $instance;
37
    }
38
39
    /**
40
     * Loads encryption configuration and validates the data.
41
     *
42
     * @param   array|string      custom configuration or config group name
43
     * @throws  Kohana_Exception
44
     */
45
    public function __construct($config = false)
46
    {
47
        if (! defined('MCRYPT_ENCRYPT')) {
48
            throw new Kohana_Exception('encrypt.requires_mcrypt');
49
        }
50
51 View Code Duplication
        if (is_string($config)) {
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...
52
            $name = $config;
53
54
            // Test the config group name
55
            if (($config = Kohana::config('encryption.'.$config)) === null) {
56
                throw new Kohana_Exception('encrypt.undefined_group', $name);
57
            }
58
        }
59
60
        if (is_array($config)) {
61
            // Append the default configuration options
62
            $config += Kohana::config('encryption.default');
63
        } else {
64
            // Load the default group
65
            $config = Kohana::config('encryption.default');
66
        }
67
68
        if (empty($config['key'])) {
69
            throw new Kohana_Exception('encrypt.no_encryption_key');
70
        }
71
72
        // Find the max length of the key, based on cipher and mode
73
        $size = mcrypt_get_key_size($config['cipher'], $config['mode']);
74
75
        if (strlen($config['key']) > $size) {
76
            // Shorten the key to the maximum size
77
            $config['key'] = substr($config['key'], 0, $size);
78
        }
79
80
        // Find the initialization vector size
81
        $config['iv_size'] = mcrypt_get_iv_size($config['cipher'], $config['mode']);
82
83
        // Cache the config in the object
84
        $this->config = $config;
85
86
        Kohana::log('debug', 'Encrypt Library initialized');
87
    }
88
89
    /**
90
     * Encrypts a string and returns an encrypted string that can be decoded.
91
     *
92
     * @param   string  data to be encrypted
93
     * @return  string  encrypted data
94
     */
95
    public function encode($data)
96
    {
97
        // Set the rand type if it has not already been set
98
        if (Encrypt::$rand === null) {
99
            if (KOHANA_IS_WIN) {
100
                // Windows only supports the system random number generator
101
                Encrypt::$rand = MCRYPT_RAND;
102
            } else {
103
                if (defined('MCRYPT_DEV_URANDOM')) {
104
                    // Use /dev/urandom
105
                    Encrypt::$rand = MCRYPT_DEV_URANDOM;
106
                } elseif (defined('MCRYPT_DEV_RANDOM')) {
107
                    // Use /dev/random
108
                    Encrypt::$rand = MCRYPT_DEV_RANDOM;
109
                } else {
110
                    // Use the system random number generator
111
                    Encrypt::$rand = MCRYPT_RAND;
112
                }
113
            }
114
        }
115
116
        if (Encrypt::$rand === MCRYPT_RAND) {
117
            // The system random number generator must always be seeded each
118
            // time it is used, or it will not produce true random results
119
            mt_srand();
120
        }
121
122
        // Create a random initialization vector of the proper size for the current cipher
123
        $iv = mcrypt_create_iv($this->config['iv_size'], Encrypt::$rand);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $iv. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
124
125
        // Encrypt the data using the configured options and generated iv
126
        $data = mcrypt_encrypt($this->config['cipher'], $this->config['key'], $data, $this->config['mode'], $iv);
127
128
        // Use base64 encoding to convert to a string
129
        return base64_encode($iv.$data);
130
    }
131
132
    /**
133
     * Decrypts an encoded string back to its original value.
134
     *
135
     * @param   string  encoded string to be decrypted
136
     * @return  string  decrypted data
137
     */
138
    public function decode($data)
139
    {
140
        // Convert the data back to binary
141
        $data = base64_decode($data);
142
143
        // Extract the initialization vector from the data
144
        $iv = substr($data, 0, $this->config['iv_size']);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $iv. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
145
146
        // Remove the iv from the data
147
        $data = substr($data, $this->config['iv_size']);
148
149
        // Return the decrypted data, trimming the \0 padding bytes from the end of the data
150
        return rtrim(mcrypt_decrypt($this->config['cipher'], $this->config['key'], $data, $this->config['mode'], $iv), "\0");
151
    }
152
} // End Encrypt
153