Issues (1919)

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.

lib/Ajde/Mailer.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
2
3
require_once 'Mailer'.DS.'class.phpmailer.php';
4
require_once 'Mailer'.DS.'class.smtp.php';
5
require_once 'Mailer'.DS.'class.pop3.php';
6
7
class Ajde_Mailer extends PHPMailer
8
{
9
    public function __construct($exceptions = false)
10
    {
11
        parent::__construct($exceptions);
12
        if (config('mail.mailer') == 'smtp') {
13
            $this->isSMTP();
14
            $configs = config('mail.config');
15
            foreach ($configs as $k => $v) {
16
                $this->$k = $v;
17
            }
18
        } else {
19
            $this->isMail();
20
        }
21
    }
22
23
    public function sendUsingModel($identifier, $toEmail, $toName = '', $data = [])
24
    {
25
        $email = new EmailModel();
26
        if ($email->loadByField('identifier', $identifier)) {
27
            $template = $email->getTemplate();
28
29
            $fromName = $email->getFromName();
30
            $fromEmail = $email->getFromEmail();
31
            $subject = $this->replaceData($template->getSubject(), $data);
32
33
            $markup = $this->rel2abs($this->replaceData($template->getMarkup(), $data));
0 ignored issues
show
Documentation Bug introduced by
The method getMarkup does not exist on object<TemplateModel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
34
            $body = PHP_EOL.$this->rel2abs($this->replaceData($template->getContent($markup), $data));
35
36
            // reset recipients
37
            $this->clearAllRecipients();
38
39
            // to
40
            $this->addAddress($toEmail, $toName);
41
42
            // from
43
            $this->From = $fromEmail;
44
45
            // fromName
46
            $this->FromName = $fromName;
47
48
            // subject
49
            $this->Subject = $subject;
50
51
            // utf8 please
52
            $this->CharSet = 'utf-8';
53
54
            // body
55
            $this->msgHTML($body);
56
57
            // send!
58
            $status = $this->send();
59
60
            // log
61 View Code Duplication
            if (class_exists('MailerlogModel')) {
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...
62
                MailerlogModel::log($fromEmail, $fromName, $toEmail, $toName, $subject, $body, $status ? 1 : 0);
63
            }
64
65
            return $status;
66
        } else {
67
            throw new Ajde_Exception('Email with identifier '.$identifier.' not found');
68
        }
69
    }
70
71
    private function rel2abs($text)
72
    {
73
        $base = config('app.rootUrl');
74
        $replace = '$1'.$base.'$2$3';
75
76
        // Look for images
77
        $pattern = "#(<\s*?img\s*?[^>]*src\s*?=[\"'])(?!http)([^\"'>]+)([\"'>]+)#";
78
        $text = preg_replace($pattern, $replace, $text);
79
80
        // Look for links
81
        $pattern = "#(<\s*?a\s*?[^>]*href\s*?=[\"'])(?!http)([^\"'>]+)([\"'>]+)#";
82
        $text = preg_replace($pattern, $replace, $text);
83
84
        return $text;
85
    }
86
87
    private function mergeData($data)
88
    {
89
        $defaultData = [
90
            'sitename' => config('app.title'),
91
        ];
92
93
        return array_merge($defaultData, $data);
94
    }
95
96
    private function replaceData($string, $data)
97
    {
98
        $data = $this->mergeData($data);
99
100
        foreach ($data as $key => $value) {
101
            $string = str_replace('%'.$key.'%', $value, $string);
102
        }
103
104
        return $string;
105
    }
106
107
    public function SendQuickMail($to, $from, $fromName, $subject, $body, $toName = '')
108
    {
109
        // set class to use PHP mail function
110
        // $this->IsMail();
111
112
        // reset recipients
113
        $this->clearAllRecipients();
114
115
        // to
116
        $this->addAddress($to, $toName);
117
118
        // from
119
        $this->From = $from;
120
121
        // fromName
122
        $this->FromName = $fromName;
123
124
        // subject
125
        $this->Subject = $subject;
126
127
        // body
128
        $this->Body = $body;
129
130
        // alt body
131
        $this->AltBody = strip_tags($body);
132
133
        // set html content type
134
        $this->isHTML(true);
135
136
        // send!
137
        $status = $this->send();
138
139
        // log
140 View Code Duplication
        if (class_exists('MailerlogModel')) {
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...
141
            MailerlogModel::log($from, $fromName, $to, $toName, $subject, $body, $status ? 1 : 0);
142
        }
143
144
        return $status;
145
    }
146
147
    public function addAddress($address, $name = '')
148
    {
149
        if (config('mail.debug') === true) {
150
            $address = config('app.email');
151
        }
152
153
        return parent::addAnAddress('to', $address, $name);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (addAnAddress() instead of addAddress()). Are you sure this is correct? If so, you might want to change this to $this->addAnAddress().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
154
    }
155
}
156