Issues (1490)

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/Helper/MailerFactory.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
namespace Fabrica\Helper;
4
5
/**
6
 * Class MailerFactory helps to set up and configure a SwiftMailer object.
7
 */
8
class MailerFactory
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $emailConfig;
14
15
    /**
16
     * Set the mailer factory configuration.
17
     *
18
     * @param array $config
19
     */
20
    public function __construct($config = [])
21
    {
22
        if (!is_array($config)) {
23
            $config = [];
24
        }
25
26
        $this->emailConfig  = isset($config['email_settings']) ? $config['email_settings'] : [];
27
    }
28
29
    /**
30
     * Returns an instance of Swift_Mailer based on the config.s
31
     *
32
     * @return \Swift_Mailer
33
     */
34
    public function getSwiftMailerFromConfig()
35
    {
36
        if ($this->getMailConfig('smtp_address')) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getMailConfig('smtp_address') of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
37
            $encryptionType = $this->getMailConfig('smtp_encryption');
38
39
            // Workaround issue where smtp_encryption could == 1 in the past by
40
            // checking it is a valid transport
41
            if ($encryptionType && !in_array($encryptionType, stream_get_transports())) {
42
                $encryptionType = null;
43
            }
44
45
            /**
46
 * @var \Swift_SmtpTransport $transport 
47
*/
48
            $transport = \Swift_SmtpTransport::newInstance(
0 ignored issues
show
The method newInstance() does not seem to exist on object<Swift_SmtpTransport>.

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...
49
                $this->getMailConfig('smtp_address'),
50
                $this->getMailConfig('smtp_port'),
51
                $encryptionType
52
            );
53
54
            $transport->setUsername($this->getMailConfig('smtp_username'));
55
            $transport->setPassword($this->getMailConfig('smtp_password'));
56
        } else {
57
            $transport = \Swift_MailTransport::newInstance(null);
58
        }
59
60
        return \Swift_Mailer::newInstance($transport);
0 ignored issues
show
The method newInstance() does not seem to exist on object<Swift_Mailer>.

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...
61
    }
62
63
    /**
64
     * Return a specific configuration value by key.
65
     *
66
     * @param  $configName
67
     * @return null|string
68
     */
69
    public function getMailConfig($configName)
70
    {
71
        if (isset($this->emailConfig[$configName]) && $this->emailConfig[$configName] != "") {
72
            return $this->emailConfig[$configName];
73
        } else {
74
            // Check defaults
75
76
            switch ($configName) {
77
            case 'smtp_address':
78
                return "";
79
            case 'default_mailto_address':
80
                return null;
81
            case 'smtp_port':
82
                return '25';
83
            case 'smtp_encryption':
84
                return null;
85
            default:
86
                return "";
87
            }
88
        }
89
    }
90
}
91