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/helpers/email.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 defined('SYSPATH') or die('No direct access allowed.');
2
/**
3
 * Email helper class.
4
 *
5
 * $Id: email.php 3769 2008-12-15 00:48:56Z zombor $
6
 *
7
 * @package    Core
8
 * @author     Kohana Team
9
 * @copyright  (c) 2007-2008 Kohana Team
10
 * @license    http://kohanaphp.com/license.html
11
 */
12
class email_Core
13
{
14
15
    // SwiftMailer instance
16
    protected static $mail;
17
18
    /**
19
     * Creates a SwiftMailer instance.
20
     *
21
     * @param   string  DSN connection string
22
     * @return  Swift  Swift object
23
     */
24
    public static function connect($config = null)
25
    {
26
        if (! class_exists('Swift', false)) {
27
            // Load SwiftMailer
28
            require Kohana::find_file('vendor', 'swift/Swift');
29
30
            // Register the Swift ClassLoader as an autoload
31
            spl_autoload_register(array('Swift_ClassLoader', 'load'));
32
        }
33
34
        // Load default configuration
35
        ($config === null) and $config = Kohana::config('email');
36
37
        switch ($config['driver']) {
38
            case 'smtp':
39
                // Set port
40
                $port = empty($config['options']['port']) ? null : (int) $config['options']['port'];
41
42
                if (empty($config['options']['encryption'])) {
43
                    // No encryption
44
                    $encryption = Swift_Connection_SMTP::ENC_OFF;
45
                } else {
46
                    // Set encryption
47
                    switch (strtolower($config['options']['encryption'])) {
48
                        case 'tls': $encryption = Swift_Connection_SMTP::ENC_TLS; break;
49
                        case 'ssl': $encryption = Swift_Connection_SMTP::ENC_SSL; break;
50
                    }
51
                }
52
53
                // Create a SMTP connection
54
                $connection = new Swift_Connection_SMTP($config['options']['hostname'], $port, $encryption);
0 ignored issues
show
The variable $encryption 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...
55
56
                // Do authentication, if part of the DSN
57
                empty($config['options']['username']) or $connection->setUsername($config['options']['username']);
58
                empty($config['options']['password']) or $connection->setPassword($config['options']['password']);
59
60
                if (! empty($config['options']['auth'])) {
61
                    // Get the class name and params
62
                    list($class, $params) = arr::callback_string($config['options']['auth']);
63
64
                    if ($class === 'PopB4Smtp') {
65
                        // Load the PopB4Smtp class manually, due to its odd filename
66
                        require Kohana::find_file('vendor', 'swift/Swift/Authenticator/$PopB4Smtp$');
67
                    }
68
69
                    // Prepare the class name for auto-loading
70
                    $class = 'Swift_Authenticator_'.$class;
71
72
                    // Attach the authenticator
73
                    $connection->attachAuthenticator(($params === null) ? new $class : new $class($params[0]));
74
                }
75
76
                // Set the timeout to 5 seconds
77
                $connection->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
78
            break;
79
            case 'sendmail':
80
                // Create a sendmail connection
81
                $connection = new Swift_Connection_Sendmail(
82
                    empty($config['options']) ? Swift_Connection_Sendmail::AUTO_DETECT : $config['options']
83
                );
84
85
                // Set the timeout to 5 seconds
86
                $connection->setTimeout(5);
87
            break;
88
            default:
89
                // Use the native connection
90
                $connection = new Swift_Connection_NativeMail($config['options']);
91
            break;
92
        }
93
94
        // Create the SwiftMailer instance
95
        return email::$mail = new Swift($connection);
96
    }
97
98
    /**
99
     * Send an email message.
100
     *
101
     * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
102
     * @param   string|array  sender email (and name)
103
     * @param   string        message subject
104
     * @param   string        message body
105
     * @param   boolean       send email as HTML
106
     * @return  integer       number of emails sent
107
     */
108
    public static function send($to, $from, $subject, $message, $html = false)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $to. 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...
109
    {
110
        // Connect to SwiftMailer
111
        (email::$mail === null) and email::connect();
112
113
        // Determine the message type
114
        $html = ($html === true) ? 'text/html' : 'text/plain';
115
116
        // Create the message
117
        $message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8');
118
119
        if (is_string($to)) {
120
            // Single recipient
121
            $recipients = new Swift_Address($to);
122
        } elseif (is_array($to)) {
123
            if (isset($to[0]) and isset($to[1])) {
124
                // Create To: address set
125
                $to = array('to' => $to);
126
            }
127
128
            // Create a list of recipients
129
            $recipients = new Swift_RecipientList;
130
131
            foreach ($to as $method => $set) {
132
                if (! in_array($method, array('to', 'cc', 'bcc'))) {
133
                    // Use To: by default
134
                    $method = 'to';
135
                }
136
137
                // Create method name
138
                $method = 'add'.ucfirst($method);
139
140
                if (is_array($set)) {
141
                    // Add a recipient with name
142
                    $recipients->$method($set[0], $set[1]);
143
                } else {
144
                    // Add a recipient without name
145
                    $recipients->$method($set);
146
                }
147
            }
148
        }
149
150
        if (is_string($from)) {
151
            // From without a name
152
            $from = new Swift_Address($from);
153
        } elseif (is_array($from)) {
154
            // From with a name
155
            $from = new Swift_Address($from[0], $from[1]);
156
        }
157
158
        return email::$mail->send($message, $recipients, $from);
0 ignored issues
show
The variable $recipients 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...
159
    }
160
} // End email
161