Issues (11)

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/Loader/TranslationLoader.php (4 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\Converter\Loader;
13
14
use Symfony\Component\Finder\Finder;
15
use Symfony\Component\Translation\Loader\LoaderInterface;
16
use Symfony\Component\Translation\MessageCatalogue;
17
use Translation\SymfonyStorage\TranslationLoader as TranslationLoaderInterface;
18
19
class TranslationLoader implements TranslationLoaderInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Translation\SymfonyStorage\TranslationLoader has been deprecated with message: Will be removed in 2.0. Please use Symfony\Component\Translation\Reader\TranslationReaderInterface.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
20
{
21
    /**
22
     * @var LoaderInterface
23
     */
24
    private $loader;
25
26
    /**
27
     * @var string
28
     */
29
    private $format;
30
31
    /**
32
     * @param LoaderInterface $loader
33
     * @param string|string[] $format
34
     */
35 2
    public function __construct(LoaderInterface $loader, $format)
36
    {
37 2
        $this->loader = $loader;
38 2
        $this->format = $format;
0 ignored issues
show
Documentation Bug introduced by
It seems like $format can also be of type array<integer,string>. However, the property $format is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
39 2
    }
40
41
    /**
42
     * Loads translation messages from a directory to the catalogue.
43
     *
44
     * @param string           $directory the directory to look into
45
     * @param MessageCatalogue $catalogue the catalogue
46
     *
47 2
     * @deprecated Use read instead.
48
     */
49 2
    public function loadMessages($directory, MessageCatalogue $catalogue)
50
    {
51
        return $this->read($directory, $catalogue);
52
    }
53
54 2
    /**
55 2
     * Loads translation messages from a directory to the catalogue.
56 2
     *
57 2
     * @param string           $directory the directory to look into
58 2
     * @param MessageCatalogue $catalogue the catalogue
59 2
     */
60 2
    public function read($directory, MessageCatalogue $catalogue)
61 2
    {
62
        if (!is_dir($directory)) {
63
            return;
64
        }
65
66
        // load any existing translation files
67
        $patterns = $this->getTranslationFilePatterns($catalogue);
68
        $files = $this->getTranslationFiles($directory, $patterns);
69
        foreach ($files as $file) {
70
            $domain = $this->getDomainFromFilename($file->getFilename(), $patterns);
71
            $catalogue->addCatalogue($this->loader->load($file->getPathname(), $catalogue->getLocale(), $domain));
72
        }
73
    }
74
75
    protected function getTranslationFiles($directory, $patterns)
76
    {
77
        $finder = new Finder();
78
        foreach ($patterns as $pattern) {
79
            $finder->name($pattern);
80
        }
81
82
        return $finder
83
            ->files()
84
            ->in($directory);
85
    }
86
87
    protected function getDomainFromFilename($filename, $patterns)
88
    {
89
        foreach ($patterns as $pattern) {
90
            $extension = str_replace('*.', '', $pattern);
91
            $length = strlen($extension);
92
            if (substr($filename, -$length) === $extension) {
93
                return substr($filename, 0, -1 * $length - 1);
94
            }
95
        }
96
97
        return $filename;
98
    }
99
100
    protected function getTranslationFilePatterns(MessageCatalogue $catalogue)
101
    {
102
        if ($this->format && !is_array($this->format)) {
103
            $this->format = [$this->format];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($this->format) of type array<integer,string,{"0":"string"}> is incompatible with the declared type string of property $format.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
104
        }
105
106
        $patterns = [];
107
        foreach ($this->format as $ext) {
0 ignored issues
show
The expression $this->format of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
108
            $patterns[] = sprintf('*.%s.%s', $catalogue->getLocale(), $ext);
109
        }
110
111
        return $patterns;
112
    }
113
}
114