Issues (27)

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/Extractors/Po.php (2 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 Gettext\Extractors;
4
5
use Gettext\Translations;
6
use Gettext\Translation;
7
use Gettext\Utils\HeadersExtractorTrait;
8
9
/**
10
 * Class to get gettext strings from php files returning arrays.
11
 */
12
class Po extends Extractor implements ExtractorInterface
13
{
14
    use HeadersExtractorTrait;
15
16
    /**
17
     * Parses a .po file and append the translations found in the Translations instance.
18
     *
19
     * {@inheritdoc}
20
     */
21
    public static function fromString($string, Translations $translations, array $options = [])
22
    {
23
        $lines = explode("\n", $string);
24
        $i = 0;
25
26
        $translation = new Translation('', '');
27
28
        for ($n = count($lines); $i < $n; ++$i) {
29
            $line = trim($lines[$i]);
30
            $line = self::fixMultiLines($line, $lines, $i);
31
32
            if ($line === '') {
33
                if ($translation->is('', '')) {
34
                    self::extractHeaders($translation->getTranslation(), $translations);
35
                } elseif ($translation->hasOriginal()) {
36
                    $translations[] = $translation;
37
                }
38
39
                $translation = new Translation('', '');
40
                continue;
41
            }
42
43
            $splitLine = preg_split('/\s+/', $line, 2);
44
            $key = $splitLine[0];
45
            $data = isset($splitLine[1]) ? $splitLine[1] : '';
46
47
            switch ($key) {
48
                case '#':
49
                    $translation->addComment($data);
50
                    $append = null;
51
                    break;
52
53
                case '#.':
54
                    $translation->addExtractedComment($data);
55
                    $append = null;
56
                    break;
57
58
                case '#,':
59
                    foreach (array_map('trim', explode(',', trim($data))) as $value) {
60
                        $translation->addFlag($value);
61
                    }
62
                    $append = null;
63
                    break;
64
65
                case '#:':
66
                    foreach (preg_split('/\s+/', trim($data)) as $value) {
67
                        if (preg_match('/^(.+)(:(\d*))?$/U', $value, $matches)) {
68
                            $translation->addReference($matches[1], isset($matches[3]) ? $matches[3] : null);
69
                        }
70
                    }
71
                    $append = null;
72
                    break;
73
74
                case 'msgctxt':
75
                    $translation = $translation->getClone(self::convertString($data));
76
                    $append = 'Context';
77
                    break;
78
79
                case 'msgid':
80
                    $translation = $translation->getClone(null, self::convertString($data));
81
                    $append = 'Original';
82
                    break;
83
84
                case 'msgid_plural':
85
                    $translation->setPlural(self::convertString($data));
86
                    $append = 'Plural';
87
                    break;
88
89
                case 'msgstr':
90
                case 'msgstr[0]':
91
                    $translation->setTranslation(self::convertString($data));
92
                    $append = 'Translation';
93
                    break;
94
95
                case 'msgstr[1]':
96
                    $translation->setPluralTranslations([self::convertString($data)]);
97
                    $append = 'PluralTranslation';
98
                    break;
99
100
                default:
101 View Code Duplication
                    if (strpos($key, 'msgstr[') === 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
                        $p = $translation->getPluralTranslations();
103
                        $p[] = self::convertString($data);
104
105
                        $translation->setPluralTranslations($p);
106
                        $append = 'PluralTranslation';
107
                        break;
108
                    }
109
110
                    if (isset($append)) {
111
                        if ($append === 'Context') {
112
                            $translation = $translation->getClone($translation->getContext()
113
                                ."\n"
114
                                .self::convertString($data));
115
                            break;
116
                        }
117
118
                        if ($append === 'Original') {
119
                            $translation = $translation->getClone(null, $translation->getOriginal()
120
                                ."\n"
121
                                .self::convertString($data));
122
                            break;
123
                        }
124
125 View Code Duplication
                        if ($append === 'PluralTranslation') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
                            $p = $translation->getPluralTranslations();
127
                            $p[] = array_pop($p)."\n".self::convertString($data);
128
                            $translation->setPluralTranslations($p);
129
                            break;
130
                        }
131
132
                        $getMethod = 'get'.$append;
133
                        $setMethod = 'set'.$append;
134
                        $translation->$setMethod($translation->$getMethod()."\n".self::convertString($data));
135
                    }
136
                    break;
137
            }
138
        }
139
140
        if ($translation->hasOriginal() && !in_array($translation, iterator_to_array($translations))) {
141
            $translations[] = $translation;
142
        }
143
    }
144
145
    /**
146
     * Gets one string from multiline strings.
147
     *
148
     * @param string $line
149
     * @param array  $lines
150
     * @param int    &$i
151
     *
152
     * @return string
153
     */
154
    private static function fixMultiLines($line, array $lines, &$i)
155
    {
156
        for ($j = $i, $t = count($lines); $j < $t; ++$j) {
157
            if (substr($line, -1, 1) == '"'
158
                && isset($lines[$j + 1])
159
                && substr(trim($lines[$j + 1]), 0, 1) == '"'
160
            ) {
161
                $line = substr($line, 0, -1).substr(trim($lines[$j + 1]), 1);
162
            } else {
163
                $i = $j;
164
                break;
165
            }
166
        }
167
168
        return $line;
169
    }
170
171
    /**
172
     * Convert a string from its PO representation.
173
     *
174
     * @param string $value
175
     *
176
     * @return string
177
     */
178
    public static function convertString($value)
179
    {
180
        if (!$value) {
181
            return '';
182
        }
183
184
        if ($value[0] === '"') {
185
            $value = substr($value, 1, -1);
186
        }
187
188
        return strtr(
189
            $value,
190
            [
191
                '\\\\' => '\\',
192
                '\\a' => "\x07",
193
                '\\b' => "\x08",
194
                '\\t' => "\t",
195
                '\\n' => "\n",
196
                '\\v' => "\x0b",
197
                '\\f' => "\x0c",
198
                '\\r' => "\r",
199
                '\\"' => '"',
200
            ]
201
        );
202
    }
203
}
204