Issues (258)

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.

core/Generator/Commands/ContainerWebGenerator.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 Apiato\Core\Generator\Commands;
4
5
use Apiato\Core\Generator\GeneratorCommand;
6
use Apiato\Core\Generator\Interfaces\ComponentsGenerator;
7
use Illuminate\Support\Pluralizer;
8
use Illuminate\Support\Str;
9
use Symfony\Component\Console\Input\InputOption;
10
11
/**
12
 * Class ContainerWebGenerator
13
 *
14
 * @author  Johannes Schobel <[email protected]>
15
 */
16
class ContainerWebGenerator extends GeneratorCommand implements ComponentsGenerator
17
{
18
19
    /**
20
     * The console command name.
21
     *
22
     * @var string
23
     */
24
    protected $name = 'apiato:generate:container:web';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Create a Container for apiato from scratch (WEB Part)';
32
33
    /**
34
     * The type of class being generated.
35
     *
36
     * @var string
37
     */
38
    protected $fileType = 'Container';
39
40
    /**
41
     * The structure of the file path.
42
     *
43
     * @var  string
44
     */
45
    protected $pathStructure = '{container-name}/*';
46
47
    /**
48
     * The structure of the file name.
49
     *
50
     * @var  string
51
     */
52
    protected $nameStructure = '{file-name}';
53
54
    /**
55
     * The name of the stub file.
56
     *
57
     * @var  string
58
     */
59
    protected $stubName = 'composer.stub';
60
61
    /**
62
     * User required/optional inputs expected to be passed while calling the command.
63
     * This is a replacement of the `getArguments` function "which reads whenever it's called".
64
     *
65
     * @var  array
66
     */
67
    public $inputs = [
68
        ['url', null, InputOption::VALUE_OPTIONAL, 'The base URI of all endpoints (/stores, /cars, ...)'],
69
        ['transporters', null, InputOption::VALUE_OPTIONAL, 'Use specific Transporters or rely on the generic DataTransporter'],
70
    ];
71
72
    /**
73
     * @return array
74
     */
75
    public function getUserInputs()
76
    {
77
        $ui = 'web';
78
79
        $useTransporters = $this->checkParameterOrConfirm('transporters', 'Would you like to use specific Transporters?', true);
80
81
        // containername as inputted and lower
82
        $containerName = $this->containerName;
83
        $_containerName = Str::lower($this->containerName);
84
85
        // name of the model (singular and plural)
86
        $model = $this->containerName;
87
        $models = Pluralizer::plural($model);
88
89
        // add the README file
90
        $this->printInfoMessage('Generating README File');
91
        $this->call('apiato:generate:readme', [
92
            '--container'   => $containerName,
93
            '--file'        => 'README',
94
        ]);
95
96
        // create the configuration file
97
        $this->printInfoMessage('Generating Configuration File');
98
        $this->call('apiato:generate:configuration', [
99
            '--container'   => $containerName,
100
            '--file'        => $_containerName,
101
        ]);
102
103
        // create the MainServiceProvider for the container
104
        $this->printInfoMessage('Generating MainServiceProvider');
105
        $this->call('apiato:generate:serviceprovider', [
106
            '--container'   => $containerName,
107
            '--file'        => 'MainServiceProvider',
108
            '--stub'        => 'mainserviceprovider',
109
        ]);
110
111
        // create the model and repository for this container
112
        $this->printInfoMessage('Generating Model and Repository');
113
        $this->call('apiato:generate:model', [
114
            '--container'   => $containerName,
115
            '--file'        => $model,
116
            '--repository'  => true,
117
        ]);
118
119
        // create the migration file for the model
120
        $this->printInfoMessage('Generating a basic Migration file');
121
        $this->call('apiato:generate:migration', [
122
            '--container'   => $containerName,
123
            '--file'        => 'create_' . Str::lower($_containerName) . '_tables',
124
            '--tablename'   => $models,
125
        ]);
126
127
        // create the default routes for this container
128
        $this->printInfoMessage('Generating Default Routes');
129
        $version = 1;
130
        $doctype = 'private';
131
132
        // get the URI and remove the first trailing slash
133
        $url = Str::lower($this->checkParameterOrAsk('url', 'Enter the base URI for *all* WEB endpoints (foo/bar)', Str::lower($models)));
134
        $url = ltrim($url, '/');
135
136
        $this->printInfoMessage('Creating Requests for Routes');
137
        $this->printInfoMessage('Generating Default Actions');
138
        $this->printInfoMessage('Generating Default Tasks');
139
140
        $routes = [
141
            [
142
                'stub'        => 'GetAll',
143
                'name'        => 'GetAll' . $models,
144
                'operation'   => 'index',
145
                'verb'        => 'GET',
146
                'url'         => $url,
147
                'action'      => 'GetAll' . $models . 'Action',
148
                'request'     => 'GetAll' . $models . 'Request',
149
                'task'        => 'GetAll' . $models . 'Task',
150
                'transporter' => 'GetAll' . $models . 'Transporter',
151
            ],
152
            [
153
                'stub'        => 'Find',
154
                'name'        => 'Find' . $model . 'ById',
155
                'operation'   => 'show',
156
                'verb'        => 'GET',
157
                'url'         => $url . '/{id}',
158
                'action'      => 'Find' . $model . 'ById' . 'Action',
159
                'request'     => 'Find' . $model . 'ById' . 'Request',
160
                'task'        => 'Find' . $model . 'ById' . 'Task',
161
                'transporter' => 'Find' . $model . 'ById' . 'Transporter',
162
            ],
163
            [
164
                'stub'        => null,
165
                'name'        => 'Create' . $model,
166
                'operation'   => 'create',
167
                'verb'        => 'GET',
168
                'url'         => $url . '/create',
169
                'action'      => null,
170
                'request'     => 'Create' . $model . 'Request',
171
                'task'        => null,
172
                'transporter' => null,
173
            ],
174
            [
175
                'stub'        => 'Create',
176
                'name'        => 'Store' . $model,
177
                'operation'   => 'store',
178
                'verb'        => 'POST',
179
                'url'         => $url . '/store',
180
                'action'      => 'Create' . $model . 'Action',
181
                'request'     => 'Store' . $model . 'Request',
182
                'task'        => 'Create' . $model . 'Task',
183
                'transporter' => 'Create' . $model . 'Transporter'
184
            ],
185
            [
186
                'stub'        => null,
187
                'name'        => 'Edit' . $model,
188
                'operation'   => 'edit',
189
                'verb'        => 'GET',
190
                'url'         => $url . '/{id}/edit',
191
                'action'      => null,
192
                'request'     => 'Edit' . $model . 'Request',
193
                'task'        => null,
194
                'transporter' => null,
195
            ],
196
            [
197
                'stub'        => 'Update',
198
                'name'        => 'Update' . $model,
199
                'operation'   => 'update',
200
                'verb'        => 'PATCH',
201
                'url'         => $url . '/{id}',
202
                'action'      => 'Update' . $model . 'Action',
203
                'request'     => 'Update' . $model . 'Request',
204
                'task'        => 'Update' . $model . 'Task',
205
                'transporter' => 'Update' . $model . 'Transporter',
206
            ],
207
            [
208
                'stub'        => 'Delete',
209
                'name'        => 'Delete' . $model,
210
                'operation'   => 'delete',
211
                'verb'        => 'DELETE',
212
                'url'         => $url . '/{id}',
213
                'action'      => 'Delete' . $model . 'Action',
214
                'request'     => 'Delete' . $model . 'Request',
215
                'task'        => 'Delete' . $model . 'Task',
216
                'transporter' => 'Delete' . $model . 'Transporter',
217
            ],
218
        ];
219
220
        foreach ($routes as $route)
221
        {
222
            $this->call('apiato:generate:route', [
223
                '--container'   => $containerName,
224
                '--file'        => $route['name'],
225
                '--ui'          => $ui,
226
                '--operation'   => $route['operation'],
227
                '--doctype'     => $doctype,
228
                '--docversion'  => $version,
229
                '--url'         => $route['url'],
230
                '--verb'        => $route['verb'],
231
            ]);
232
233
            $enableTransporter = false;
234
            if ($useTransporters) {
235
                if ($route['transporter'] != null) {
236
                    $enableTransporter = true;
237
                }
238
            }
239
240
            $this->call('apiato:generate:request', [
241
                '--container'   => $containerName,
242
                '--file'        => $route['request'],
243
                '--ui'          => $ui,
244
                '--transporter' => $enableTransporter,
245
                '--transportername' => $route['transporter'],
246
            ]);
247
248 View Code Duplication
            if ($route['action'] != null || $route['stub'] != null) {
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...
249
                $this->call('apiato:generate:action', [
250
                    '--container' => $containerName,
251
                    '--file' => $route['action'],
252
                    '--model' => $model,
253
                    '--stub' => $route['stub'],
254
                ]);
255
            }
256
257 View Code Duplication
            if ($route['task'] != null || $route['stub'] != null) {
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...
258
                $this->call('apiato:generate:task', [
259
                    '--container' => $containerName,
260
                    '--file' => $route['task'],
261
                    '--model' => $model,
262
                    '--stub' => $route['stub'],
263
                ]);
264
            }
265
        }
266
267
        // finally generate the controller
268
        $this->printInfoMessage('Generating Controller to wire everything together');
269
        $this->call('apiato:generate:controller', [
270
            '--container'   => $containerName,
271
            '--file'        => 'Controller',
272
            '--ui'          => $ui,
273
            '--stub'        => 'crud.' . $ui,
274
        ]);
275
276
        $this->printInfoMessage('Generating Composer File');
277
        return [
278
            'path-parameters' => [
279
                'container-name' => $containerName,
280
            ],
281
            'stub-parameters' => [
282
                '_container-name' => $_containerName,
283
                'container-name' => $containerName,
284
                'class-name' => $this->fileName,
285
            ],
286
            'file-parameters' => [
287
                'file-name' => $this->fileName,
288
            ],
289
        ];
290
    }
291
292
    /**
293
     * Get the default file name for this component to be generated
294
     *
295
     * @return string
296
     */
297
    public function getDefaultFileName()
298
    {
299
        return 'composer';
300
    }
301
302
    public function getDefaultFileExtension()
303
    {
304
        return 'json';
305
    }
306
307
}
308