Issues (14)

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.

Repository/DbRepository.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 SfCod\EmailEngineBundle\Repository;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use SfCod\EmailEngineBundle\Entity\EmailEntityInterface;
7
use SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException;
8
use SfCod\EmailEngineBundle\Template\TemplateInterface;
9
use Twig_Environment;
10
11
/**
12
 * Class DbRepository
13
 *
14
 * @author Virchenko Maksim <[email protected]>
15
 *
16
 * @package SfCod\EmailEngineBundle\Repository
17
 */
18
class DbRepository implements RepositoryInterface
19
{
20
    /**
21
     * @var EmailEntityInterface
22
     */
23
    protected $email;
24
25
    /**
26
     * @var EntityManagerInterface
27
     */
28
    protected $em;
29
30
    /**
31
     * @var Twig_Environment
32
     */
33
    protected $twig;
34
35
    /**
36
     * DbRepository constructor.
37
     *
38
     * @param EntityManagerInterface $em
39
     * @param Twig_Environment $twig
40
     */
41
    public function __construct(EntityManagerInterface $em, Twig_Environment $twig)
42
    {
43
        $this->em = $em;
44
        $this->twig = $twig;
45
    }
46
47
    /**
48
     * Repository initialize
49
     *
50
     * @param TemplateInterface $template
51
     * @param array $arguments
52
     *
53
     * @throws RepositoryUnavailableException
54
     */
55
    public function connect(TemplateInterface $template, array $arguments = [])
56
    {
57
        if (false === isset($arguments['entity'], $arguments['attribute'])) {
58
            throw new RepositoryUnavailableException('DbRepository configuration incorrect, "entity" and "attribute" must be configured.');
59
        }
60
61
        $this->email = $this->em
62
            ->getRepository($arguments['entity'])
63
            ->findOneBy([$arguments['attribute'] => get_class($template)::getSlug()]);
0 ignored issues
show
The method getSlug cannot be called on get_class($template) (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
64
65
        if (is_null($this->email)) {
66
            throw new RepositoryUnavailableException(sprintf('Record with slug "%s" does not exists.', get_class($template)::getSlug()));
0 ignored issues
show
The method getSlug cannot be called on get_class($template) (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
67
        }
68
    }
69
70
    /**
71
     * Get subject template
72
     *
73
     * @param array $data
74
     *
75
     * @return string
76
     *
77
     * @throws \Throwable
78
     */
79
    public function getSubjectTemplate(array $data): string
80
    {
81
        return $this->applyArguments($this->email->getTitle(), $data);
82
    }
83
84
    /**
85
     * Get body template
86
     *
87
     * @param array $data
88
     *
89
     * @return string
90
     *
91
     * @throws \Throwable
92
     */
93
    public function getBodyTemplate(array $data): string
94
    {
95
        return $this->applyArguments($this->email->getBody(), $data);
96
    }
97
98
    /**
99
     * Get sender name template
100
     *
101
     * @param array $data
102
     *
103
     * @return string
104
     */
105
    public function getSenderNameTemplate(array $data): string
106
    {
107
        return getenv('SENDER_NAME');
108
    }
109
110
    /**
111
     * Get sender email template
112
     *
113
     * @param array $data
114
     *
115
     * @return string
116
     */
117
    public function getSenderEmailTemplate(array $data): string
118
    {
119
        return getenv('SENDER_EMAIL');
120
    }
121
122
    /**
123
     * Apply arguments to string
124
     *
125
     * @param string $str
126
     * @param array $args
127
     *
128
     * @return string
129
     *
130
     * @throws \Throwable
131
     */
132
    protected function applyArguments(string $str, array $args): string
133
    {
134
        try {
135
            return $this->twig
136
                ->createTemplate('{% autoescape false %}' . $str . '{% endautoescape %}')
137
                ->render($args);
138
        } catch (\Throwable $e) {
139
            throw new RepositoryUnavailableException($e->getMessage());
140
        }
141
    }
142
}
143