Issues (82)

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.

code/EmailUtils.php (5 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 LeKoala\Mailgun;
4
5
use Pelago\Emogrifier;
6
use Pelago\Emogrifier\CssInliner;
7
use Pelago\Emogrifier\HtmlProcessor\HtmlPruner;
8
use Pelago\Emogrifier\HtmlProcessor\CssToAttributeConverter;
9
10
class EmailUtils
11
{
12
13
    /**
14
     * Inline styles using Pelago Emogrifier
15
     *
16
     * This is much better than the functionnality provided by Mailgun anyway
17
     *
18
     * @param string $html
19
     * @return string
20
     */
21
    public static function inline_styles($html)
22
    {
23
        if (class_exists(CssInliner::class)) {
24
            // V3
25
            $cssInliner = CssInliner::fromHtml($html)->inlineCss('');
26
            $domDocument = $cssInliner->getDomDocument();
27
28
            // potentially, we could also remove classes
29
            // HtmlPruner::fromDomDocument($domDocument)->removeElementsWithDisplayNone()
30
            //     ->removeRedundantClassesAfterCssInlined($cssInliner);
31
32
            // disableInvisibleNodeRemoval
33
            HtmlPruner::fromDomDocument($domDocument)->removeElementsWithDisplayNone();
0 ignored issues
show
The method removeElementsWithDisplayNone() does not seem to exist on object<Pelago\Emogrifier...mlProcessor\HtmlPruner>.

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...
34
35
            // enableCssToHtmlMapping
36
            $html = CssToAttributeConverter::fromDomDocument($domDocument)
37
                ->convertCssToVisualAttributes()->render();
38
        } else {
39
            // V2
40
            $emogrifier = new Emogrifier();
41
            $emogrifier->disableInvisibleNodeRemoval();
0 ignored issues
show
Deprecated Code introduced by
The method Pelago\Emogrifier::disableInvisibleNodeRemoval() has been deprecated with message: will be removed in Emogrifier 3.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
42
            $emogrifier->enableCssToHtmlMapping();
0 ignored issues
show
Deprecated Code introduced by
The method Pelago\Emogrifier::enableCssToHtmlMapping() has been deprecated with message: will be removed in Emogrifier 3.0, use the CssToAttributeConverter instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
43
            $emogrifier->setHtml($html);
44
            $html = $emogrifier->emogrify();
45
        }
46
47
        return $html;
48
    }
49
50
51
    /**
52
     * Convert an html email to a text email while keeping formatting and links
53
     *
54
     * @param string $content
55
     * @return string
56
     */
57
    public static function convert_html_to_text($content)
58
    {
59
        // Prevent styles to be included
60
        $content = preg_replace('/<style.*>([\s\S]*)<\/style>/i', '', $content);
61
        // Convert html entities to strip them later on
62
        $content = html_entity_decode($content);
63
        // Bold
64
        $content = str_ireplace(['<strong>', '</strong>', '<b>', '</b>'], "*", $content);
65
        // Replace links to keep them accessible
66
        $content = preg_replace('/<a[\s\S]href="(.*?)"[\s\S]*?>(.*?)<\/a>/i', '$2 ($1)', $content);
67
        // Replace new lines
68
        $content = str_replace(['<br>', '<br/>', '<br />'], "\r\n", $content);
69
        // Remove html tags
70
        $content = strip_tags($content);
71
        // Avoid lots of spaces
72
        $content = preg_replace('/^[\s][\s]+(\S)/m', "\n$1", $content);
73
        // Trim content so that it's nice
74
        $content = trim($content);
75
        return $content;
76
    }
77
78
    /**
79
     * Match all words and whitespace, will be terminated by '<'
80
     *
81
     * Note: use /u to support utf8 strings
82
     *
83
     * @param string $rfc_email_string
84
     * @return string
85
     */
86
    public static function get_displayname_from_rfc_email($rfc_email_string)
87
    {
88
        $name = preg_match('/[\w\s-\.]+/u', $rfc_email_string, $matches);
0 ignored issues
show
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
89
        $matches[0] = trim($matches[0]);
90
        return $matches[0];
91
    }
92
93
    /**
94
     * Extract parts between brackets
95
     *
96
     * @param string $rfc_email_string
97
     * @return string
98
     */
99
    public static function get_email_from_rfc_email($rfc_email_string)
100
    {
101
        if (strpos($rfc_email_string, '<') === false) {
102
            return $rfc_email_string;
103
        }
104
        $mailAddress = preg_match('/(?:<)(.+)(?:>)$/', $rfc_email_string, $matches);
0 ignored issues
show
$mailAddress is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
105
        if (empty($matches)) {
106
            return $rfc_email_string;
107
        }
108
        return $matches[1];
109
    }
110
}
111