Issues (48)

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.

Request/RequestBodyParamConverter.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
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\Request;
13
14
use FOS\RestBundle\Context\Context;
15
use FOS\RestBundle\Serializer\Serializer;
16
use JMS\Serializer\Exception\Exception as JMSSerializerException;
17
use JMS\Serializer\Exception\UnsupportedFormatException;
18
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
19
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
22
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
23
use Symfony\Component\OptionsResolver\OptionsResolver;
24
use Symfony\Component\Serializer\Exception\ExceptionInterface as SymfonySerializerException;
25
use Symfony\Component\Validator\Validator\ValidatorInterface;
26
27
/**
28
 * @author Tyler Stroud <[email protected]>
29
 */
30
final class RequestBodyParamConverter implements ParamConverterInterface
31
{
32
    private $serializer;
33
    private $context = [];
34
    private $validator;
35
    private $validationErrorsArgument;
36
37
    /**
38
     * @param string[]|null $groups
39
     */
40 15
    public function __construct(
41
        Serializer $serializer,
42
        ?array $groups = null,
43
        ?string $version = null,
44
        ValidatorInterface $validator = null,
45
        ?string $validationErrorsArgument = null
46
    ) {
47 15
        $this->serializer = $serializer;
48
49 15
        if (!empty($groups)) {
50 1
            $this->context['groups'] = (array) $groups;
51
        }
52
53 15
        if (!empty($version)) {
54 1
            $this->context['version'] = $version;
55
        }
56
57 15
        if (null !== $validator && null === $validationErrorsArgument) {
58
            throw new \InvalidArgumentException('"$validationErrorsArgument" cannot be null when using the validator');
59
        }
60
61 15
        $this->validator = $validator;
62 15
        $this->validationErrorsArgument = $validationErrorsArgument;
63 15
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 9
    public function apply(Request $request, ParamConverter $configuration): bool
69
    {
70 9
        $options = (array) $configuration->getOptions();
71
72 9
        if (isset($options['deserializationContext']) && is_array($options['deserializationContext'])) {
73 1
            $arrayContext = array_merge($this->context, $options['deserializationContext']);
74
        } else {
75 8
            $arrayContext = $this->context;
76
        }
77 9
        $this->configureContext($context = new Context(), $arrayContext);
78
79
        try {
80 9
            $object = $this->serializer->deserialize(
81 9
                $request->getContent(),
0 ignored issues
show
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, FOS\RestBundle\Serialize...rializer::deserialize() does only seem to accept string, maybe add an additional type check?

This check looks at variables that 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...
82 9
                $configuration->getClass(),
83 9
                $request->getContentType(),
84
                $context
85
            );
86 3
        } catch (UnsupportedFormatException $e) {
87
            return $this->throwException(new UnsupportedMediaTypeHttpException($e->getMessage(), $e), $configuration);
88 3
        } catch (JMSSerializerException $e) {
89 1
            return $this->throwException(new BadRequestHttpException($e->getMessage(), $e), $configuration);
90 2
        } catch (SymfonySerializerException $e) {
91 1
            return $this->throwException(new BadRequestHttpException($e->getMessage(), $e), $configuration);
92
        }
93
94 6
        $request->attributes->set($configuration->getName(), $object);
95
96 6
        if (null !== $this->validator && (!isset($options['validate']) || $options['validate'])) {
97 1
            $validatorOptions = $this->getValidatorOptions($options);
98
99 1
            $errors = $this->validator->validate($object, null, $validatorOptions['groups']);
100
101 1
            $request->attributes->set(
102 1
                $this->validationErrorsArgument,
103
                $errors
104
            );
105
        }
106
107 6
        return true;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113 4
    public function supports(ParamConverter $configuration): bool
114
    {
115 4
        return null !== $configuration->getClass() && 'fos_rest.request_body' === $configuration->getConverter();
116
    }
117
118 10
    private function configureContext(Context $context, array $options): void
119
    {
120 10
        foreach ($options as $key => $value) {
121 2
            if ('groups' === $key) {
122 2
                $context->addGroups($options['groups']);
123 2
            } elseif ('version' === $key) {
124 2
                $context->setVersion($options['version']);
125 2
            } elseif ('enableMaxDepth' === $key) {
126 1
                $context->enableMaxDepth($options['enableMaxDepth']);
0 ignored issues
show
The call to Context::enableMaxDepth() has too many arguments starting with $options['enableMaxDepth'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
127 2
            } elseif ('serializeNull' === $key) {
128 1
                $context->setSerializeNull($options['serializeNull']);
129
            } else {
130 2
                $context->setAttribute($key, $value);
131
            }
132
        }
133 10
    }
134
135 2
    private function throwException(\Exception $exception, ParamConverter $configuration): bool
136
    {
137 2
        if ($configuration->isOptional()) {
138
            return false;
139
        }
140
141 2
        throw $exception;
142
    }
143
144 2
    private function getValidatorOptions(array $options): array
145
    {
146 2
        $resolver = new OptionsResolver();
147 2
        $resolver->setDefaults([
148 2
            'groups' => null,
149
            'traverse' => false,
150
            'deep' => false,
151
        ]);
152
153 2
        return $resolver->resolve(isset($options['validator']) ? $options['validator'] : []);
154
    }
155
}
156