Issues (15)

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.

src/Translation/FilesystemUpdater.php (1 issue)

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 Happyr\TranslationBundle\Translation;
4
5
use Happyr\TranslationBundle\Model\Message;
6
use Symfony\Component\EventDispatcher\Event;
7
use Symfony\Component\Translation\Dumper\DumperInterface;
8
use Symfony\Component\Translation\Exception\NotFoundResourceException;
9
use Symfony\Component\Translation\Loader\LoaderInterface;
10
use Symfony\Component\Translation\MessageCatalogue;
11
12
/**
13
 * @author Tobias Nyholm, Damien Harper
14
 *
15
 * Update the locale file system with changes in the catalogue
16
 */
17
class FilesystemUpdater
18
{
19
    /**
20
     * @var LoaderInterface loader
21
     */
22
    private $loader;
23
24
    /**
25
     * @var DumperInterface dumper
26
     */
27
    private $dumper;
28
29
    /**
30
     * @var string targetDir
31
     */
32
    private $targetDir;
33
34
    /**
35
     * @var string fileExtension
36
     */
37
    private $fileExtension;
38
39
    /**
40
     * @var Message[] messages
41
     */
42
    private $messages;
43
44
    /**
45
     * @var bool
46
     */
47
    private $syncEmptyTranslations;
48
49
    /**
50
     * Filesystem constructor.
51
     *
52
     * @param LoaderInterface $loader
53
     * @param DumperInterface $dumper
54
     * @param string          $targetDir
55
     * @param string          $fileExtension
56
     * @param bool            $syncEmptyTranslations
57
     */
58 1
    public function __construct(LoaderInterface $loader, DumperInterface $dumper, $targetDir, $fileExtension, $syncEmptyTranslations = true)
59
    {
60 1
        $this->loader = $loader;
61 1
        $this->dumper = $dumper;
62 1
        $this->targetDir = $targetDir;
63 1
        $this->messages = array();
64 1
        $this->fileExtension = $fileExtension;
65 1
        $this->syncEmptyTranslations = $syncEmptyTranslations;
66 1
    }
67
68
    /**
69
     * Returns translation file type.
70
     *
71
     * @return string
72
     */
73
    public function getFileExtension()
74
    {
75
        return $this->fileExtension;
76
    }
77
78
    /**
79
     * @param string $fileName
80
     * @param string $data     the file contents
81
     */
82
    public function writeToFile($fileName, $data)
83
    {
84
        if (!is_dir($this->targetDir)) {
85
            mkdir($this->targetDir, 0777, true);
86
        }
87
88
        file_put_contents(sprintf('%s/%s', $this->targetDir, $fileName), $data);
89
    }
90
91
    /**
92
     * Update message catalogues.
93
     *
94
     * @param Message[] $messages
95
     */
96
    public function updateMessageCatalog(array $messages)
97
    {
98
        $this->messages = array_merge($messages, $this->messages);
99
    }
100
101
    /**
102
     * Update the file system after the Response has been sent back to the client.
103
     *
104
     * @param Event $event
105
     *
106
     * @throws \ErrorException
107
     * @throws \Exception
108
     */
109
    public function onTerminate(Event $event)
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
110
    {
111
        if (empty($this->messages)) {
112
            return;
113
        }
114
115
        /** @var MessageCatalogue[] $catalogues */
116
        $catalogues = array();
117
        foreach ($this->messages as $m) {
118
            $key = $m->getLocale().$m->getDomain();
119
            if (!isset($catalogues[$key])) {
120
                $file = sprintf('%s/%s.%s.%s', $this->targetDir, $m->getDomain(), $m->getLocale(), $this->getFileExtension());
121
                
122
                try {
123
                    $catalogues[$key] = $this->loader->load($file, $m->getLocale(), $m->getDomain());
124
                } catch (NotFoundResourceException $e) {
125
                    $catalogues[$key] = new MessageCatalogue($m->getLocale());
126
                }
127
            }
128
129
            $translation = $m->getTranslation();
130
            if (empty($translation)) {
131
                if ($this->syncEmptyTranslations) {
132
                    $translation = sprintf('[%s]', $m->getId());
133
                } else {
134
                    continue;
135
                }
136
            }
137
138
            $catalogues[$key]->set($m->getId(), $translation, $m->getDomain());
139
        }
140
141
        foreach ($catalogues as $catalogue) {
142
            try {
143
                $this->dumper->dump($catalogue, ['path' => $this->targetDir]);
144
            } catch (\ErrorException $e) {
145
                // Could not save file
146
                // TODO better error handling
147
                throw $e;
148
            }
149
        }
150
    }
151
152
    /**
153
     * @return string
154
     */
155
    public function getTargetDir()
156
    {
157
        return $this->targetDir;
158
    }
159
}
160