Issues (1490)

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/Tools/Plugin/PhpTalLint.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
namespace Fabrica\Tools\Plugin;
4
5
use Fabrica\Tools;
6
use Fabrica\Tools\Builder;
7
use Fabrica\Models\Infra\Ci\Build;
8
use Fabrica\Tools\Plugin;
9
10
/**
11
 * PHPTAL Lint Plugin - Provides access to PHPTAL lint functionality.
12
 *
13
 * @author Stephen Ball <[email protected]>
14
 */
15
class PhpTalLint extends Plugin
16
{
17
    protected $recursive = true;
18
    protected $suffixes;
19
20
    /**
21
     * @return string
22
     */
23
    public static function pluginName()
24
    {
25
        return 'php_tal_lint';
26
    }
27
28
    /**
29
     * @var string The path to a file contain custom phptal_tales_ functions
30
     */
31
    protected $tales;
32
33
    /**
34
     * @var int
35
     */
36
    protected $allowedWarnings;
37
38
    /**
39
     * @var int
40
     */
41
    protected $allowedErrors;
42
43
    /**
44
     * @var array The results of the lint scan
45
     */
46
    protected $failedPaths = [];
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function __construct(Builder $builder, Build $build, array $options = [])
52
    {
53
        parent::__construct($builder, $build, $options);
54
55
        $this->suffixes = ['zpt'];
56
57
        $this->allowedWarnings = 0;
58
        $this->allowedErrors   = 0;
59
60
        if (isset($options['suffixes'])) {
61
            $this->suffixes = (array)$options['suffixes'];
62
        }
63
    }
64
65
    /**
66
     * Executes phptal lint
67
     */
68
    public function execute()
69
    {
70
        $this->lintDirectory($this->directory);
71
72
        $errors   = 0;
73
        $warnings = 0;
74
75
        foreach ($this->failedPaths as $path) {
76
            if ($path['type'] == 'error') {
77
                $errors++;
78
            } else {
79
                $warnings++;
80
            }
81
        }
82
83
        $this->build->storeMeta((self::pluginName() . '-warnings'), $warnings);
84
        $this->build->storeMeta((self::pluginName() . '-errors'), $errors);
85
        $this->build->storeMeta((self::pluginName() . '-data'), $this->failedPaths);
86
87
        $success = true;
88
89
        if ($this->allowedWarnings != -1 && $warnings > $this->allowedWarnings) {
90
            $success = false;
91
        }
92
93
        if ($this->allowedErrors != -1 && $errors > $this->allowedErrors) {
94
            $success = false;
95
        }
96
97
        return $success;
98
    }
99
100
    /**
101
     * Lint an item (file or directory) by calling the appropriate method.
102
     *
103
     * @param  $item
104
     * @param  $itemPath
105
     * @return bool
106
     */
107
    protected function lintItem($item, $itemPath)
108
    {
109
        $success = true;
110
111
        if ($item->isFile() && in_array(strtolower($item->getExtension()), $this->suffixes)) {
112
            if (!$this->lintFile($itemPath)) {
113
                $success = false;
114
            }
115 View Code Duplication
        } elseif ($item->isDir() && $this->recursive && !$this->lintDirectory($itemPath . '/')) {
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...
116
            $success = false;
117
        }
118
119
        return $success;
120
    }
121
122
    /**
123
     * Run phptal lint against a directory of files.
124
     *
125
     * @param  $path
126
     * @return bool
127
     */
128 View Code Duplication
    protected function lintDirectory($path)
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...
129
    {
130
        $success = true;
131
        $directory = new \DirectoryIterator($this->builder->buildPath . $path);
132
133
        foreach ($directory as $item) {
134
            if ($item->isDot()) {
135
                continue;
136
            }
137
138
            $itemPath = $path . $item->getFilename();
139
140
            if (in_array($itemPath, $this->ignore)) {
141
                continue;
142
            }
143
144
            if (!$this->lintItem($item, $itemPath)) {
145
                $success = false;
146
            }
147
        }
148
149
        return $success;
150
    }
151
152
    /**
153
     * Run phptal lint against a specific file.
154
     *
155
     * @param  $path
156
     * @return bool
157
     */
158
    protected function lintFile($path)
159
    {
160
        $success = true;
161
162
        list($suffixes, $tales) = $this->getFlags();
163
164
        $lint = __DIR__ . '/';
165
        $lint .= 'vendor/phptal/phptal/';
166
        $lint .= 'tools/phptal_lint.php';
167
        $cmd  = 'php ' . $lint . ' %s %s "%s"';
168
169
        $this->builder->executeCommand($cmd, $suffixes, $tales, $this->builder->buildPath . $path);
170
171
        $output = $this->builder->getLastOutput();
172
173
        if (preg_match('/Found (.+?) (error|warning)/i', $output, $matches)) {
174
            $rows = explode(PHP_EOL, $output);
175
176
            unset($rows[0]);
177
            unset($rows[1]);
178
            unset($rows[2]);
179
            unset($rows[3]);
180
181
            foreach ($rows as $row) {
182
                $name = basename($path);
183
184
                $row = str_replace('(use -i to include your custom modifier functions)', '', $row);
185
                $message = str_replace($name . ': ', '', $row);
186
187
                $parts = explode(' (line ', $message);
188
189
                $message = trim($parts[0]);
190
                $line = str_replace(')', '', $parts[1]);
191
192
                $this->failedPaths[] = [
193
                    'file'    => $path,
194
                    'line'    => $line,
195
                    'type'    => $matches[2],
196
                    'message' => $message
197
                ];
198
            }
199
200
            $success = false;
201
        }
202
203
        return $success;
204
    }
205
206
    /**
207
     * Process options and produce an arguments string for PHPTAL Lint.
208
     *
209
     * @return array
210
     */
211
    protected function getFlags()
212
    {
213
        $tales = '';
214
        if (!empty($this->tales)) {
215
            $tales = ' -i ' . $this->builder->buildPath . $this->tales;
216
        }
217
218
        $suffixes = '';
219 View Code Duplication
        if (is_array($this->suffixes) && count($this->suffixes) > 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...
220
            $suffixes = ' -e ' . implode(',', $this->suffixes);
221
        }
222
223
        return [$suffixes, $tales];
224
    }
225
}
226