Issues (4)

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.

src/Dumper/FlysystemXliffDumper.php (3 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
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\PlatformAdapter\Flysystem\Dumper;
13
14
use Symfony\Component\Translation\Dumper\XliffFileDumper;
15
use Symfony\Component\Translation\MessageCatalogue;
16
use Symfony\Component\Translation\Exception\InvalidArgumentException;
17
use League\Flysystem\Filesystem;
18
use Symfony\Component\Translation\Exception\RuntimeException;
19
20
/**
21
 * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s).
22
 * Performs backup of already existing files.
23
 *
24
 * Options:
25
 * - path (mandatory): the directory where the files should be saved
26
 *
27
 * @author Michel Salib <[email protected]>
28
 * @author Tobias Nyholm <[email protected]>
29
 */
30
final class FlysystemXliffDumper extends XliffFileDumper
31
{
32
    /**
33
     * @var Filesystem
34
     */
35
    private $filesystem;
36
37
    /**
38
     * A template for the relative paths to files.
39
     *
40
     * @var string
41
     */
42
    protected $relativePathTemplate = '%domain%.%locale%.%extension%';
43
44
    /**
45
     * Make file backup before the dump.
46
     *
47
     * @var bool
48
     */
49
    private $backup = true;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
50
51
    /**
52
     * @param Filesystem $filesystem
53
     */
54 1
    public function setFilesystem($filesystem)
55
    {
56 1
        $this->filesystem = $filesystem;
57 1
    }
58
59
    /**
60
     * Sets the template for the relative paths to files.
61
     *
62
     * @param string $relativePathTemplate A template for the relative paths to files
63
     */
64
    public function setRelativePathTemplate($relativePathTemplate)
65
    {
66
        $this->relativePathTemplate = $relativePathTemplate;
67
    }
68
69
    /**
70
     * Sets backup flag.
71
     *
72
     * @param bool
73
     */
74
    public function setBackup($backup)
75
    {
76
        $this->backup = $backup;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function dump(MessageCatalogue $messages, $options = [])
83
    {
84
        if (!array_key_exists('path', $options)) {
85
            throw new InvalidArgumentException('The file dumper needs a path option.');
86
        }
87
88
        // save a file for each domain
89
        foreach ($messages->getDomains() as $domain) {
90
            // backup
91
            $fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale());
92
            if ($this->filesystem->has($fullpath)) {
93
                if ($this->backup) {
94
                    @trigger_error('Creating a backup while dumping a message catalogue is deprecated since version 3.1 and will be removed in 4.0. Use TranslationWriter::disableBackup() to disable the backup.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
95
                    $this->filesystem->copy($fullpath, $fullpath.'~');
96
                }
97
            } else {
98
                $directory = dirname($fullpath);
99
                if (!$this->filesystem->has($directory) && !@mkdir($directory, 0777, true)) {
100
                    try {
101
                        $this->filesystem->createDir($directory);
102
                    } catch (\Exception $e) {
103
                        throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory), 0, $e);
104
                    }
105
                }
106
            }
107
            // save file
108
            $this->filesystem->write($fullpath, $this->formatCatalogue($messages, $domain, $options));
109
        }
110
    }
111
112
    /**
113
     * Gets the relative file path using the template.
114
     *
115
     * @param string $domain The domain
116
     * @param string $locale The locale
117
     *
118
     * @return string The relative file path
119
     */
120
    private function getRelativePath($domain, $locale)
0 ignored issues
show
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
121
    {
122
        return strtr($this->relativePathTemplate, [
123
            '%domain%' => $domain,
124
            '%locale%' => $locale,
125
            '%extension%' => $this->getExtension(),
126
        ]);
127
    }
128
}
129