Issues (1704)

Branch: master

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.

Resolver/APIBusinessEntityResolver.php (5 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 Victoire\Bundle\APIBusinessEntityBundle\Resolver;
4
5
use Victoire\Bundle\APIBusinessEntityBundle\Chain\ApiAuthenticationChain;
6
use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIBusinessEntity;
7
use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIEndpoint;
8
use Victoire\Bundle\BusinessEntityBundle\Converter\ParameterConverter;
9
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessProperty;
10
use Victoire\Bundle\BusinessEntityBundle\Resolver\BusinessEntityResolverInterface;
11
use Victoire\Bundle\CoreBundle\Entity\EntityProxy;
12
13
/**
14
 * Class APIBusinessEntityResolver.
15
 */
16
class APIBusinessEntityResolver implements BusinessEntityResolverInterface
17
{
18
    /**
19
     * @var ParameterConverter
20
     */
21
    private $parameterConverter;
22
    /**
23
     * @var ApiAuthenticationChain
24
     */
25
    private $authenticationChain;
26
27
    /**
28
     * APIBusinessEntityResolver constructor.
29
     *
30
     * @param ParameterConverter     $parameterConverter
31
     * @param ApiAuthenticationChain $authenticationChain
32
     */
33
    public function __construct(ParameterConverter $parameterConverter, APIAuthenticationChain $authenticationChain)
34
    {
35
        $this->parameterConverter = $parameterConverter;
36
        $this->authenticationChain = $authenticationChain;
37
    }
38
39
    /**
40
     * Fetch API to get a single entity.
41
     *
42
     * @param EntityProxy $entityProxy
43
     *
44
     * @return mixed
45
     */
46
    public function getBusinessEntity(EntityProxy $entityProxy)
47
    {
48
        /** @var APIBusinessEntity $businessEntity */
49
        $businessEntity = $entityProxy->getBusinessEntity();
50
        $getMethod = $businessEntity->getGetMethod();
51
        preg_match_all('/{{([a-zA-Z]+)}}/', $getMethod, $matches);
52
        // build an array with businessIdentifiers properties names
53
        $identifiers = array_map(function ($property) {
54
            return $property->getName();
55
        },
56
            $businessEntity->getBusinessIdentifiers()->toArray()
57
        );
58
        foreach ($matches[1] as $match) {
59
            if (in_array($match, $identifiers)) {
60
                $value = $entityProxy->getRessourceId();
61
            } else {
62
                $props = $entityProxy->getAdditionnalProperties();
63
                $value = $props[$match];
64
            }
65
            $getMethod = $this->parameterConverter->convert($getMethod, $match, $value);
66
        }
67
68
        $entity = $this->callApi($businessEntity->getEndpoint(), $getMethod);
69
        // Then the BusinessEntity is an API result, it's not a proper object but a decoded json result.
70
        // It has no classname so we cannot resolve the related BusinessEntity definition, so we
71
        // store the businessEntity object into the entity.
72
        $entity->_businessEntity = $entityProxy->getBusinessEntity();
73
74
        return $entity;
75
    }
76
77
    /**
0 ignored issues
show
Doc comment for parameter "$page" missing
Loading history...
78
     * Fetch API to get a list of entities.
79
     *
80
     * @param APIBusinessEntity $businessEntity
81
     *
82
     * @return array
83
     */
84
    public function getBusinessEntities(APIBusinessEntity $businessEntity, $page = 1)
85
    {
86
        $data = $this->callApi($businessEntity->getEndpoint(), $businessEntity->getListMethod($page));
87
88
        foreach ($data as $entity) {
89
            $entity->_businessEntity = $businessEntity;
90
        }
91
        if (count($data) > 0) {
92
            $data = array_merge($data, $this->getBusinessEntities($businessEntity, ++$page));
93
        }
94
95
        return $data;
96
    }
97
98
    /**
0 ignored issues
show
Doc comment for parameter "$businessProperty" missing
Loading history...
99
     * filter API to get a list of entities.
100
     *
101
     * @param APIBusinessEntity $businessEntity
102
     * @param array             $filter
0 ignored issues
show
Doc comment for parameter $filter does not match actual variable name $businessProperty
Loading history...
103
     *
104
     * @return mixed
105
     */
106
    public function searchBusinessEntities(APIBusinessEntity $businessEntity, BusinessProperty $businessProperty, $filter)
107
    {
108
        $getMethod = $businessEntity->getListMethod()
109
            .(false !== strpos($businessEntity->getListMethod(), '?') ? '&' : '?')
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
110
            .$businessProperty->getFilterMethod();
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
111
        $getMethod = preg_replace('/{{([a-zA-Z]+)}}/', $filter, $getMethod);
112
113
        $data = $this->callApi($businessEntity->getEndpoint(), $getMethod);
114
115
        foreach ($data as $entity) {
116
            $entity->businessEntity = $businessEntity;
117
        }
118
119
        return $data;
120
    }
121
122
    /**
123
     * Sends a curl request to a given path.
124
     *
125
     * @param APIEndpoint $endPoint
126
     * @param string      $getMethod
127
     *
128
     * @return array
129
     */
130
    protected function callApi(APIEndpoint $endPoint, $getMethod)
131
    {
132
        $host = $endPoint->getHost();
133
        $token = $endPoint->getToken();
134
        $curl = curl_init();
135
        if ($tokenType = $endPoint->getTokenType()) {
136
            $this->authenticationChain->resolve($tokenType)->handle($curl, $getMethod, $token);
137
        }
138
        curl_setopt($curl, CURLOPT_URL, $host.$getMethod);
139
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
140
141
        $result = curl_exec($curl);
142
143
        curl_close($curl);
144
145
        return json_decode($result);
146
    }
147
}
148