Issues (10)

Security Analysis    no request data  

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/Mailer.php (3 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
 * Mail.php
4
 *
5
 * PHP version 5.6+
6
 *
7
 * @author Philippe Gaultier <[email protected]>
8
 * @copyright 2010-2017 Philippe Gaultier
9
 * @license http://www.sweelix.net/license license
10
 * @version XXX
11
 * @link http://www.sweelix.net
12
 * @package sweelix\sendgrid
13
 */
14
15
namespace sweelix\sendgrid;
16
17
18
use SendGrid\Exception as SendGridException;
19
use SendGrid\Email as SendGridMail;
20
use SendGrid as SendGridClient;
21
use yii\base\InvalidConfigException;
22
use yii\base\InvalidParamException;
23
use yii\mail\BaseMailer;
24
25
/**
26
 * This component allow user to send an email
27
 *
28
 * @author Philippe Gaultier <[email protected]>
29
 * @copyright 2010-2017 Philippe Gaultier
30
 * @license http://www.sweelix.net/license license
31
 * @version XXX
32
 * @link http://www.sweelix.net
33
 * @package sweelix\sendgrid
34
 * @since XXX
35
 * @todo implement batch messages using API
36
 */
37
class Mailer extends BaseMailer
38
{
39
    /**
40
     * @var string Sendgrid API Key
41
     */
42
    public $token;
43
44
    /**
45
     * @var string Sendgrid login
46
     */
47
    public $user;
48
49
    /**
50
     * @var string Sendgrid password
51
     */
52
    public $password;
53
54
    /**
55
     * @var array options as defined in https://github.com/sendgrid/sendgrid-php#usage
56
     */
57
    public $options;
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public $messageClass = 'sweelix\sendgrid\Message';
63
    /**
64
     * @param Message $message
65
     * @since XXX
66
     * @throws InvalidConfigException
67
     */
68 2
    public function sendMessage($message)
69
    {
70
        try {
71 2
            if (($this->token === null) && ($this->user === null && $this->password === null)) {
72 2
                throw new InvalidConfigException('Token or login/password are missing');
73
            }
74
            $client = null;
75
            if ($this->token !== null) {
76
                $client = new SendGridClient($this->token, $this->options);
77
            } elseif(($this->user !== null) && ($this->password !== null)) {
78
                $client = new SendGridClient($this->user, $this->password, $this->options);
79
            }
80
            if ($client === null) {
81
                throw new InvalidParamException('Email transport must be configured');
82
            }
83
            $sendGridMail = new SendGridMail();
84
            $replyTo = $message->getReplyTo();
85
            if ($replyTo !== null) {
86
                $sendGridMail->setReplyTo($replyTo);
87
            }
88
            $sendGridMail->setFrom($message->getFrom());
89
            if ($message->getFromName() !== null) {
90
                $sendGridMail->setFromName($message->getFromName());
91
            }
92
            foreach($message->getTo() as $email => $name) {
0 ignored issues
show
The expression $message->getTo() of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
93
                $sendGridMail->addTo($email, $name);
94
            }
95
            foreach($message->getCc() as $email => $name) {
96
                $sendGridMail->addCc($email, $name);
97
            }
98
            foreach($message->getBcc() as $email => $name) {
99
                $sendGridMail->addBcc($email, $name);
100
            }
101
            $sendGridMail->setSubject($message->getSubject());
102
            foreach($message->getHeaders() as $header) {
0 ignored issues
show
The expression $message->getHeaders() of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
103
                list($key, $value) = each($header);
104
                $sendGridMail->addHeader($key, $value);
105
            }
106
            foreach($message->getAttachments() as $attachment) {
0 ignored issues
show
The expression $message->getAttachments() of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
107
                $cid = isset($attachment['ContentID']) ? $attachment['ContentID'] : null;
108
                $sendGridMail->addAttachment($attachment['File'], $attachment['Name'], $cid);
109
            }
110
111
            $templateId = $message->getTemplateId();
112
            if ($templateId === null) {
113
                $data = $message->getHtmlBody();
114
                if ($data !== null) {
115
                    $sendGridMail->setHtml($data);
116
                }
117
                $data = $message->getTextBody();
118
                if ($data !== null) {
119
                    $sendGridMail->setText($data);
120
                }
121
            } else {
122
                $sendGridMail->setTemplateId($templateId);
123
                // trigger html template
124
                $sendGridMail->setHtml(' ');
125
                // trigger text template
126
                $sendGridMail->setText(' ');
127
                $templateModel = $message->getTemplateModel();
128
                if (empty($templateModel) === false) {
129
                    $sendGridMail->setSubstitutions($message->getTemplateModel());
130
                }
131
            }
132
            $result = $client->send($sendGridMail);
133
            /* @var \SendGrid\Response $result */
134
            return $result->code == 200;
135 2
        } catch (SendGridException $e) {
136
            throw $e;
137
        }
138
    }
139
}