Issues (243)

Security Analysis    2 potential vulnerabilities

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 (2)
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/mail/Message.php (2 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 /** MicroMailMessage */
2
3
namespace Micro\Mail;
4
5
/**
6
 * Message class file.
7
 *
8
 * @author Oleg Lunegov <[email protected]>
9
 * @link https://github.com/linpax/microphp-framework
10
 * @copyright Copyright (c) 2013 Oleg Lunegov
11
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
12
 * @package Micro
13
 * @subpackage Mail
14
 * @version 1.0
15
 * @since 1.0
16
 * @final
17
 */
18
class Message implements IMessage
19
{
20
    /** @var string $to Recipient */
21
    private $to;
22
    /** @var string $type Doctype */
23
    private $type = 'text/html';
24
    /** @var string $encoding encoding */
25
    private $encoding = 'utf-8';
26
    /** @var string $subject Subject */
27
    private $subject;
28
    /** @var string $text Body */
29
    private $text;
30
    /** @var array $headers Headers */
31
    private $headers = [];
32
    /** @var array $params Parameters */
33
    private $params = [];
34
35
36
    /**
37
     * Message constructor
38
     *
39
     * @access public
40
     *
41
     * @param string $from
42
     * @param string $fromName
43
     *
44
     * @result void
45
     */
46
    public function __construct($from = '', $fromName = '')
47
    {
48
        if ($from) {
49
            $this->setHeaders('From', sprintf('=?utf-8?B?%s?= <%s>', base64_encode($fromName), $from));
50
        }
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function getTo()
57
    {
58
        return $this->to;
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function setTo($mail)
65
    {
66
        $this->to = $mail;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function getSubject()
73
    {
74
        return $this->subject;
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80
    public function setSubject($text)
81
    {
82
        $this->subject = '=?utf-8?B?'.base64_encode($text).'?=';
83
    }
84
85
    /**
86
     * @inheritdoc
87
     */
88
    public function getText()
89
    {
90
        return $this->text;
91
    }
92
93
    /**
94
     * @inheritdoc
95
     */
96
    public function setText($body, $type = 'text/plain', $encoding = 'utf-8')
97
    {
98
        $this->text = $body;
99
        $this->type = $type;
100
        $this->encoding = $encoding;
101
    }
102
103
    /**
104
     * @inheritdoc
105
     */
106
    public function getHeaders()
107
    {
108
        return sprintf("%s\r\nContent-type: %s; charset=%s\r\n",
109
            implode("\r\n", array_values($this->headers)),
110
            $this->type,
111
            $this->encoding
112
        );
113
    }
114
115
    /**
116
     * @inheritdoc
117
     */
118
    public function setHeaders($name, $value)
119
    {
120
        $this->headers[$name] = $name.': '.$value;
121
    }
122
123
    /**
124
     * @inheritdoc
125
     */
126
    public function getParams()
127
    {
128
        if (!$this->params) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->params of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
129
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type declared by the interface Micro\Mail\IMessage::getParams of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
130
        }
131
132
        return implode("\r\n", array_values($this->params))."\r\n";
133
    }
134
135
    /**
136
     * @inheritdoc
137
     */
138
    public function setParams($name, $value)
139
    {
140
        $this->params[$name] = $name.': '.$value;
141
    }
142
}
143