Issues (3)

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.

JsonSchemaAnnotationProcessor.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
 * This file is part of the StfalconApiBundle.
4
 *
5
 * (c) Stfalcon LLC <stfalcon.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace StfalconStudio\ApiBundle\Service\AnnotationProcessor;
14
15
use Doctrine\Common\Annotations\Reader;
16
use StfalconStudio\ApiBundle\Annotation\JsonSchema;
17
use StfalconStudio\ApiBundle\Annotation\JsonSchemaAnnotationInterface;
18
use StfalconStudio\ApiBundle\Exception\InvalidArgumentException;
19
use StfalconStudio\ApiBundle\Exception\RuntimeException;
20
use StfalconStudio\ApiBundle\Util\File\FileReader;
21
22
/**
23
 * JsonSchemaAnnotationProcessor.
24
 */
25
class JsonSchemaAnnotationProcessor
26
{
27
    /** @var DtoAnnotationProcessor */
28
    private $dtoAnnotationProcessor;
29
30
    /** @var Reader */
31
    private $annotationReader;
32
33
    /** @var FileReader */
34
    private $fileReader;
35
36
    /** @var string */
37
    private $jsonSchemaDir;
38
39
    /** @var array|string[] */
40
    private $cachedClasses = [];
41
42
    /**
43
     * @param DtoAnnotationProcessor $dtoAnnotationProcessor
44
     * @param FileReader             $fileReader
45
     * @param Reader                 $annotationReader
46
     * @param string                 $jsonSchemaDir
47
     */
48
    public function __construct(DtoAnnotationProcessor $dtoAnnotationProcessor, FileReader $fileReader, Reader $annotationReader, string $jsonSchemaDir)
49
    {
50
        $this->dtoAnnotationProcessor = $dtoAnnotationProcessor;
51
        $this->fileReader = $fileReader;
52
        $this->annotationReader = $annotationReader;
53
        $this->jsonSchemaDir = $jsonSchemaDir;
54
    }
55
56
    /**
57
     * @param string $controllerClassName
58
     *
59
     * @return mixed
60
     */
61
    public function processAnnotationForControllerClass(string $controllerClassName)
62
    {
63
        $dtoClass = $this->dtoAnnotationProcessor->processAnnotationForClass($controllerClassName);
64
65
        return $this->processAnnotationForDtoClass($dtoClass);
66
    }
67
68
    /**
69
     * @param string $dtoClassName
70
     *
71
     * @throws RuntimeException
72
     * @throws InvalidArgumentException
73
     *
74
     * @return mixed
75
     */
76
    public function processAnnotationForDtoClass(string $dtoClassName)
77
    {
78
        /** @var class-string<object> $dtoClassName */
0 ignored issues
show
The doc-type class-string<object> could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
79
        if (\array_key_exists($dtoClassName, $this->cachedClasses)) {
80
            return $this->cachedClasses[$dtoClassName];
81
        }
82
83
        $classAnnotation = $this->annotationReader->getClassAnnotation(new \ReflectionClass($dtoClassName), JsonSchema::class);
84
85
        if (!$classAnnotation instanceof JsonSchemaAnnotationInterface) {
86
            throw new RuntimeException(\sprintf('Missing Json Schema annotation for class %s', $dtoClassName));
87
        }
88
89
        $jsonSchemaDirPath = \realpath($this->jsonSchemaDir);
90
        if (false === $jsonSchemaDirPath) {
91
            throw new RuntimeException(\sprintf('Directory for json Schema files "%s" is not found.', $this->jsonSchemaDir));
92
        }
93
94
        $path = $jsonSchemaDirPath.\DIRECTORY_SEPARATOR.$classAnnotation->getJsonSchemaFilename();
95
        $realPathToJsonSchemaFile = \realpath($path);
96
        if (false === $realPathToJsonSchemaFile) {
97
            throw new RuntimeException(\sprintf('Json Schema file "%s" is not found.', $path));
98
        }
99
100
        $jsonSchemaContent = $this->fileReader->getFileContents($realPathToJsonSchemaFile);
101
        if (false === $jsonSchemaContent) {
102
            throw new InvalidArgumentException(\sprintf('Cannot read content of file %s', $realPathToJsonSchemaFile));
103
        }
104
105
        $decodedSchema = \json_decode($jsonSchemaContent, true, 512, JSON_THROW_ON_ERROR);
106
107
        $this->cachedClasses[$dtoClassName] = $decodedSchema;
108
109
        return $decodedSchema;
110
    }
111
}
112