Issues (40)

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/PhpCode.php (1 issue)

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 Exception;
6
use Gettext\Translations;
7
use Gettext\Utils\FunctionsScanner;
8
9
/**
10
 * Class to get gettext strings from php files returning arrays.
11
 */
12
class PhpCode extends Extractor implements ExtractorInterface, ExtractorMultiInterface
13
{
14
    public static $options = [
15
        // - false: to not extract comments
16
        // - empty string: to extract all comments
17
        // - non-empty string: to extract comments that start with that string
18
        // - array with strings to extract comments format.
19
        'extractComments' => false,
20
21
        'constants' => [],
22
23
        'functions' => [
24
            'gettext' => 'gettext',
25
            '__' => 'gettext',
26
            'ngettext' => 'ngettext',
27
            'n__' => 'ngettext',
28
            'pgettext' => 'pgettext',
29
            'p__' => 'pgettext',
30
            'dgettext' => 'dgettext',
31
            'd__' => 'dgettext',
32
            'dngettext' => 'dngettext',
33
            'dn__' => 'dngettext',
34
            'dpgettext' => 'dpgettext',
35
            'dp__' => 'dpgettext',
36
            'npgettext' => 'npgettext',
37
            'np__' => 'npgettext',
38
            'dnpgettext' => 'dnpgettext',
39
            'dnp__' => 'dnpgettext',
40
            'noop' => 'noop',
41
            'noop__' => 'noop',
42
        ],
43
    ];
44
45
    protected static $functionsScannerClass = 'Gettext\Utils\PhpFunctionsScanner';
46
47
    /**
48
     * {@inheritdoc}
49
     * @throws Exception
50
     */
51
    public static function fromString($string, Translations $translations, array $options = [])
52
    {
53
        static::fromStringMultiple($string, [$translations], $options);
54
    }
55
56
    /**
57
     * @inheritDoc
58
     * @throws Exception
59
     */
60
    public static function fromStringMultiple($string, array $translations, array $options = [])
61
    {
62
        $options += static::$options;
63
64
        /** @var FunctionsScanner $functions */
65
        $functions = new static::$functionsScannerClass($string);
66
67
        if ($options['extractComments'] !== false) {
68
            $functions->enableCommentsExtraction($options['extractComments']);
69
        }
70
71
        $functions->saveGettextFunctions($translations, $options);
72
    }
73
74
    /**
75
     * @inheritDoc
76
     */
77 View Code Duplication
    public static function fromFileMultiple($file, array $translations, array $options = [])
0 ignored issues
show
This method seems to be duplicated in 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...
78
    {
79
        foreach (static::getFiles($file) as $file) {
80
            $options['file'] = $file;
81
            static::fromStringMultiple(static::readFile($file), $translations, $options);
82
        }
83
    }
84
85
86
    /**
87
     * Decodes a T_CONSTANT_ENCAPSED_STRING string.
88
     *
89
     * @param string $value
90
     *
91
     * @return string
92
     */
93
    public static function convertString($value)
94
    {
95
        if (strpos($value, '\\') === false) {
96
            return substr($value, 1, -1);
97
        }
98
99
        if ($value[0] === "'") {
100
            return strtr(substr($value, 1, -1), ['\\\\' => '\\', '\\\'' => '\'']);
101
        }
102
103
        $value = substr($value, 1, -1);
104
105
        return preg_replace_callback(
106
            '/\\\(n|r|t|v|e|f|\$|"|\\\|x[0-9A-Fa-f]{1,2}|u{[0-9a-f]{1,6}}|[0-7]{1,3})/',
107
            function ($match) {
108
                switch ($match[1][0]) {
109
                    case 'n':
110
                        return "\n";
111
                    case 'r':
112
                        return "\r";
113
                    case 't':
114
                        return "\t";
115
                    case 'v':
116
                        return "\v";
117
                    case 'e':
118
                        return "\e";
119
                    case 'f':
120
                        return "\f";
121
                    case '$':
122
                        return '$';
123
                    case '"':
124
                        return '"';
125
                    case '\\':
126
                        return '\\';
127
                    case 'x':
128
                        return chr(hexdec(substr($match[1], 1)));
129
                    case 'u':
130
                        return static::unicodeChar(hexdec(substr($match[1], 1)));
131
                    default:
132
                        return chr(octdec($match[1]));
133
                }
134
            },
135
            $value
136
        );
137
    }
138
139
    /**
140
     * @param $dec
141
     * @return string|null
142
     * @see http://php.net/manual/en/function.chr.php#118804
143
     */
144
    protected static function unicodeChar($dec)
145
    {
146
        if ($dec < 0x80) {
147
            return chr($dec);
148
        }
149
150
        if ($dec < 0x0800) {
151
            return chr(0xC0 + ($dec >> 6))
152
                . chr(0x80 + ($dec & 0x3f));
153
        }
154
155
        if ($dec < 0x010000) {
156
            return chr(0xE0 + ($dec >> 12))
157
                . chr(0x80 + (($dec >> 6) & 0x3f))
158
                . chr(0x80 + ($dec & 0x3f));
159
        }
160
161
        if ($dec < 0x200000) {
162
            return chr(0xF0 + ($dec >> 18))
163
                . chr(0x80 + (($dec >> 12) & 0x3f))
164
                . chr(0x80 + (($dec >> 6) & 0x3f))
165
                . chr(0x80 + ($dec & 0x3f));
166
        }
167
168
        return null;
169
    }
170
}
171