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/Email.php (2 issues)

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
namespace Fabrica\Helper;
4
5
use Fabrica\Tools\Config;
6
use Fabrica\Tools\Builder;
7
8
/**
9
 * Helper class for sending emails using email configuration.
10
 */
11
class Email
12
{
13
    const DEFAULT_FROM = 'PHP Censor <[email protected]>';
14
15
    protected $emailTo = [];
16
    protected $emailCc = [];
17
    protected $subject = 'Email from PHP Censor';
18
    protected $body    = '';
19
    protected $isHtml  = false;
20
    protected $config;
21
22
    /**
23
     * @param Config $config
24
     */
25
    public function __construct(Config $config)
26
    {
27
        $this->config = $config;
28
    }
29
30
    /**
31
     * Set the email's To: header.
32
     *
33
     * @param  string      $email
34
     * @param  string|null $name
35
     * @return $this
36
     */
37
    public function setEmailTo($email, $name = null)
38
    {
39
        $this->emailTo[$email] = $name;
40
41
        return $this;
42
    }
43
44
    /**
45
     * Add an address to the email's CC header.
46
     *
47
     * @param  string      $email
48
     * @param  string|null $name
49
     * @return $this
50
     */
51
    public function addCc($email, $name = null)
52
    {
53
        $this->emailCc[$email] = $name;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Set the email subject.
60
     *
61
     * @param  string $subject
62
     * @return $this
63
     */
64
    public function setSubject($subject)
65
    {
66
        $this->subject = $subject;
67
68
        return $this;
69
    }
70
71
    /**
72
     * Set the email body.
73
     *
74
     * @param  string $body
75
     * @return $this
76
     */
77
    public function setBody($body)
78
    {
79
        $this->body = $body;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Set whether or not the email body is HTML.
86
     *
87
     * @param  bool $isHtml
88
     * @return $this
89
     */
90
    public function setHtml($isHtml = false)
91
    {
92
        $this->isHtml = $isHtml;
93
94
        return $this;
95
    }
96
97
    /**
98
     * Get the from address to use for the email.
99
     *
100
     * @return array
101
     */
102
    public function getFrom()
103
    {
104
        $from = $this->config->get(
105
            'php-censor.email_settings.from_address',
106
            self::DEFAULT_FROM
107
        );
108
109
        if (strpos($from, '<') === false) {
110
            return [(string)trim($from) => 'PHP Censor'];
111
        }
112
113
        preg_match('#^(.*?)<(.*?)>$#ui', $from, $fromParts);
114
115
        return [trim($fromParts[2]) => trim($fromParts[1])];
116
    }
117
118
    /**
119
     * Send the email.
120
     *
121
     * @param Builder $builder
122
     *
123
     * @return int
124
     */
125
    public function send(Builder $builder = null)
126
    {
127
        $smtpServer = $this->config->get('php-censor.email_settings.smtp_address');
128
        if (null !== $builder) {
129
            $builder->logDebug(sprintf("SMTP: '%s'", !empty($smtpServer) ? 'true' : 'false'));
130
        }
131
132
        $factory = new MailerFactory($this->config->get('php-censor'));
133
        $mailer = $factory->getSwiftMailerFromConfig();
134
135
        $message = \Swift_Message::newInstance($this->subject)
0 ignored issues
show
The method newInstance() does not seem to exist on object<Swift_Message>.

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...
136
            ->setFrom($this->getFrom())
137
            ->setTo($this->emailTo)
138
            ->setBody($this->body);
139
140
        if ($this->isHtml) {
141
            $message->setContentType('text/html');
142
        }
143
144
        if (is_array($this->emailCc) && count($this->emailCc)) {
145
            $message->setCc($this->emailCc);
146
        }
147
148
        ob_start();
149
150
        $result = $mailer->send($message);
151
152
        $rawOutput = ob_get_clean();
153
154
        if ($rawOutput) {
155
            $builder->getBuildLogger()->logWarning($rawOutput);
0 ignored issues
show
It seems like $builder is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
156
        }
157
158
        return $result;
159
    }
160
}
161