Issues (91)

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/Command/GenerateCommand.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 Joli\Jane\OpenApi\Command;
4
5
use Joli\Jane\OpenApi\JaneOpenApi;
6
use Joli\Jane\Registry;
7
use Joli\Jane\Schema;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
15
class GenerateCommand extends Command
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 13
    public function configure()
21
    {
22 13
        $this->setName('generate');
23 13
        $this->setDescription('Generate an api client: class, normalizers and resources given a specific Json OpenApi file');
24 13
        $this->addOption('config-file', 'c', InputOption::VALUE_OPTIONAL, 'File to use for Jane OpenAPI configuration');
25 13
        $this->addOption('reference', null, InputOption::VALUE_NONE, 'Use the JSON Reference specification in your generated library');
26 13
        $this->addOption('date-format', 'd', InputOption::VALUE_OPTIONAL, 'Date time format to use for date time field');
27 13
        $this->addArgument('openapi-file', InputArgument::OPTIONAL, 'Location of the OpenApi (Swagger) Schema file');
28 13
        $this->addArgument('namespace', InputArgument::OPTIONAL, 'Namespace prefix to use for generated files');
29 13
        $this->addArgument('directory', InputArgument::OPTIONAL, 'Directory where to generate files');
30 13
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 13
    public function execute(InputInterface $input, OutputInterface $output)
36
    {
37 13
        $options = [];
38
39 13
        $configFile = null;
40
41 13
        if (!$input->hasOption('config-file') && file_exists('.jane-openapi')) {
42
            $configFile = '.jane-openapi';
43 13
        } elseif($input->hasOption('config-file') && null !== $input->getOption('config-file')) {
44 13
            $configFile = $input->getOption('config-file');
45
        }
46
47 13
        if ($configFile) {
48 13
            $configFile = $input->getOption('config-file');
49
50 13
            if (!file_exists($configFile)) {
51
                throw new \RuntimeException(sprintf('Config file %s does not exist', $configFile));
52
            }
53
54 13
            $options = require $configFile;
55
56 13
            if (!is_array($options)) {
57 13
                throw new \RuntimeException(sprintf('Invalid config file specified or invalid return type in file %s', $configFile));
58
            }
59
        } else {
60 View Code Duplication
            if ($input->hasArgument('openapi-file') && null !== $input->getArgument('openapi-file')) {
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...
61
                $options['openapi-file'] = $input->getArgument('openapi-file');
62
            }
63
64 View Code Duplication
            if ($input->hasArgument('namespace') && null !== $input->getArgument('namespace')) {
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...
65
                $options['namespace'] = $input->getArgument('namespace');
66
            }
67
68 View Code Duplication
            if ($input->hasArgument('directory') && null !== $input->getArgument('directory')) {
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...
69
                $options['directory'] = $input->getArgument('directory');
70
            }
71
72
            if ($input->hasOption('date-format') && null !== $input->getOption('date-format')) {
73
                $options['date-format'] = $input->getOption('date-format');
74
            }
75
76
            if ($input->hasOption('no-reference') && null !== $input->getOption('no-reference')) {
77
                $options['reference'] = $input->getOption('reference');
78
            }
79
        }
80
81 13
        $options = $this->resolveConfiguration($options);
82 13
        $registry = new Registry();
83
84 13
        if (array_key_exists('openapi-file', $options)) {
85 12
            $registry->addSchema($this->resolveSchema($options['openapi-file'], $options));
86
        } else {
87 1
            foreach ($options['mapping'] as $schema => $schemaOptions) {
88 1
                $registry->addSchema($this->resolveSchema($schema, $schemaOptions));
89
            }
90
        }
91
92 13
        $janeOpenApi = JaneOpenApi::build($options);
93 13
        $files       = $janeOpenApi->generate($registry);
94 13
        $janeOpenApi->printFiles($files, $registry);
95
96 13
        foreach ($files as $file) {
97 13
            $output->writeln(sprintf("Generate %s", $file->getFilename()));
98
        }
99 13
    }
100
101 13
    protected function resolveConfiguration(array $options = [])
102
    {
103 13
        $optionsResolver = new OptionsResolver();
104 13
        $optionsResolver->setDefaults([
105 13
            'reference' => false,
106
            'date-format' => \DateTime::RFC3339,
107
        ]);
108
109 13
        if (array_key_exists('openapi-file', $options)) {
110 12
            $optionsResolver->setRequired([
111 12
                'openapi-file',
112
                'namespace',
113
                'directory',
114
            ]);
115
        } else {
116 1
            $optionsResolver->setRequired([
117 1
                'mapping'
118
            ]);
119
        }
120
121 13
        return $optionsResolver->resolve($options);
122
    }
123
124 13
    protected function resolveSchema($schema, array $options = [])
125
    {
126 13
        $optionsResolver = new OptionsResolver();
127
128
        // To support old schema
129 13
        $optionsResolver->setDefined([
130 13
            'openapi-file',
131
            'reference',
132
            'date-format',
133
        ]);
134
135 13
        $optionsResolver->setRequired([
136 13
            'namespace',
137
            'directory',
138
        ]);
139
140 13
        $options = $optionsResolver->resolve($options);
141
142 13
        return new Schema($schema, $options['namespace'], $options['directory'], '');
143
    }
144
}
145