Issues (6)

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/FosRest/ParamFetcher.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 Nicofuma\SwaggerBundle\FosRest;
4
5
use FOS\RestBundle\Request\ParamFetcherInterface;
6
use Nicofuma\SwaggerBundle\Exception\NoValidatorException;
7
use Nicofuma\SwaggerBundle\Validator\Validator;
8
use Nicofuma\SwaggerBundle\Validator\ValidatorMap;
9
use Symfony\Component\HttpFoundation\RequestStack;
10
11
class ParamFetcher implements ParamFetcherInterface
12
{
13
    /** @var ParamFetcherInterface */
14
    private $decorated;
15
16
    /** @var ValidatorMap */
17
    private $validatorMap;
18
19
    /** @var RequestStack */
20
    private $requestStack;
21
22
    /** @var Validator */
23
    private $currentValidator;
24
25
    /** @var \stdClass[] */
26
    private $currentSchema;
27
28
    private $usingSwagger = false;
29
30 6
    public function __construct(ParamFetcherInterface $decorated, ValidatorMap $validatorMap, RequestStack $requestStack)
31
    {
32 6
        $this->decorated = $decorated;
33 6
        $this->validatorMap = $validatorMap;
34 6
        $this->requestStack = $requestStack;
35 6
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 6
    public function setController($controller)
41
    {
42 6
        $request = $this->requestStack->getCurrentRequest();
43
44
        // Workaround for https://github.com/symfony/symfony/issues/19749
45 6
        if ($this->requestStack->getMasterRequest() !== $request) {
46
            $this->usingSwagger = false;
47
            $this->decorated->setController($controller);
48
49
            return;
50
        }
51
52
        try {
53 6
            $this->currentValidator = $this->validatorMap->getValidator($request);
0 ignored issues
show
It seems like $request defined by $this->requestStack->getCurrentRequest() on line 42 can be null; however, Nicofuma\SwaggerBundle\V...atorMap::getValidator() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
54 5
            $this->currentSchema = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array<integer,object<stdClass>> of property $currentSchema.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55 5
            $this->usingSwagger = true;
56 6
        } catch (NoValidatorException $e) {
57 1
            $this->usingSwagger = false;
58 1
            $this->decorated->setController($controller);
59
        }
60 6
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 6
    public function get($name, $strict = null)
66
    {
67 6
        if ($this->usingSwagger) {
68 5
            $currentSchema = $this->getCurrentSchema();
69 5
            if (array_key_exists($name, $currentSchema)) {
70 4
                $default = isset($currentSchema[$name]->default) ? $currentSchema[$name]->default : null;
71
72 4
                return $this->requestStack->getCurrentRequest()->query->get($name, $default);
73
            } else {
74 1
                throw new \InvalidArgumentException(sprintf("No swagger definition for parameter '%s'.", $name));
75
            }
76
        } else {
77 1
            return $this->decorated->get($name, $strict);
78
        }
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 2
    public function all($strict = null)
85
    {
86 2
        if ($this->usingSwagger) {
87 1
            $parameters = [];
88 1
            foreach ($this->getCurrentSchema() as $item) {
89 1
                $parameters[$item->name] = $this->get($item->name);
90 1
            }
91
92 1
            return $parameters;
93
        } else {
94 1
            return $this->decorated->all($strict);
0 ignored issues
show
It seems like $strict defined by parameter $strict on line 84 can also be of type null; however, FOS\RestBundle\Request\P...FetcherInterface::all() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
95
        }
96
    }
97
98
    /**
99
     * @return \stdClass[]
100
     */
101 5
    private function getCurrentSchema()
102
    {
103 5
        $request = $this->requestStack->getCurrentRequest();
104 5
        $path = $request->getPathInfo();
105
106 5
        if ($this->currentSchema === null) {
107 5
            $schemaManager = $this->currentValidator->getSchemaManager();
108
109 5
            $this->currentSchema = [];
110 5
            if ($schemaManager->findPathInTemplates($path, $template, $params)) {
111 5
                $currentSchema = $schemaManager->getRequestQueryParameters($template, $request->getMethod());
112
113 5
                foreach ($currentSchema as $keySchema) {
114 5
                    $this->currentSchema[$keySchema->name] = $keySchema;
115 5
                }
116 5
            }
117 5
        }
118
119 5
        return $this->currentSchema;
120
    }
121
}
122