Issues (59)

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/AbstractClient.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 Directus\SDK;
4
5
use Directus\SDK\Response\EntryCollection;
6
use Directus\SDK\Response\Entry;
7
use Directus\Util\ArrayUtils;
8
use Directus\Util\StringUtils;
9
10
abstract class AbstractClient implements RequestsInterface
11
{
12
    /**
13
     * @var Container
14
     */
15
    protected $container;
16
17
    /**
18
     * @param Container $container
19
     */
20
    public function setContainer(Container $container)
21
    {
22
        $this->container = $container;
23
    }
24
25
    /**
26
     * @return Container
27
     */
28
    public function getContainer()
29
    {
30
        return $this->container;
31
    }
32
33
    /**
34
     * Creates a response object
35
     *
36
     * @param $data
37
     *
38
     * @return \Directus\SDK\Response\EntryCollection|\Directus\SDK\Response\Entry
39
     */
40 28
    protected function createResponseFromData($data)
41
    {
42 28
        if (isset($data['rows']) || (isset($data['data']) && ArrayUtils::isNumericKeys($data['data']))) {
43 6
            $response = new EntryCollection($data);
44 3
        } else {
45 22
            $response = new Entry($data);
46
        }
47
48 28
        return $response;
49
    }
50
51
    protected function processData($tableName, array $data)
52
    {
53
        $method = 'processDataOn' . StringUtils::underscoreToCamelCase($tableName, true);
54
        if (method_exists($this, $method)) {
55
            $data = call_user_func_array([$this, $method], [$data]);
56
        }
57
58
        return $data;
59
    }
60
61
    protected function processFile(File $file)
62
    {
63
        $data = $file->toArray();
64
        // Not container, we are using remote :)
65
        if (!$this->container) {
66
            return $data;
67
        }
68
69
        $Files = $this->container->get('files');
0 ignored issues
show
$Files does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
70
71
        if (!array_key_exists('type', $data) || strpos($data['type'], 'embed/') === 0) {
72
            $recordData = $Files->saveEmbedData($data);
0 ignored issues
show
$Files does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
73
        } else {
74
            $recordData = $Files->saveData($data['data'], $data['name']);
0 ignored issues
show
$Files does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
75
        }
76
77
        return array_merge($recordData, ArrayUtils::omit($data, ['data', 'name']));
78
    }
79
80
    protected function processDataOnDirectusUsers($data)
81
    {
82
        $data = ArrayUtils::omit($data, ['id', 'user', 'access_token', 'last_login', 'last_access', 'last_page']);
83
84
        if (ArrayUtils::has($data, 'avatar_file_id') && $data['avatar_file_id'] instanceof File) {
85
            $data['avatar_file_id'] = $this->processFile($data['avatar_file_id']);
86
        }
87
88
        return $data;
89
    }
90
91
    protected function processOnDirectusFiles($data)
92
    {
93
        // @NOTE: omit columns such id or user.
94
        $data = ArrayUtils::omit($data, ['id', 'user']);
95
96
        return $data;
97
    }
98
99
    protected function processDataOnDirectusPreferences($data)
100
    {
101
        // @NOTE: omit columns such id or user.
102
        $data = ArrayUtils::omit($data, ['id']);
103
104
        return $data;
105
    }
106
107
    protected function processDataOnDirectusBookmarks($data)
108
    {
109
        // @NOTE: omit columns such id or user.
110
        $data = ArrayUtils::omit($data, ['id']);
111
112
        return $data;
113
    }
114
115
    protected function parseColumnData($data)
116
    {
117
        $requiredAttributes = ['name', 'table', 'type', 'ui'];
118
        if (!ArrayUtils::contains($data, $requiredAttributes)) {
119
            throw new \Exception(sprintf('%s are required', implode(',', $requiredAttributes)));
120
        }
121
122
        $data = ArrayUtils::aliasKeys($data, [
123
            'table_name' => 'table',
124
            'column_name' => 'name',
125
            'data_type' => 'type',
126
            'char_length' => 'length'
127
        ]);
128
129
        return $data;
130
    }
131
132
    protected function requiredAttributes(array $attributes, array $data)
133
    {
134 View Code Duplication
        if (!ArrayUtils::contains($data, $attributes)) {
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...
135
            throw new \Exception(sprintf('These attributes are required: %s', implode(',', $attributes)));
136
        }
137
    }
138
139
    protected function requiredOneAttribute(array $attributes, array $data)
140
    {
141 View Code Duplication
        if (!ArrayUtils::containsSome($data, $attributes)) {
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...
142
            throw new \Exception(sprintf('These attributes are required: %s', implode(',', $attributes)));
143
        }
144
    }
145
146
    protected function getMessagesTo(array $data)
147
    {
148
        $isGroup = ArrayUtils::has($data, 'toGroup');
149
        $to = ArrayUtils::get($data, 'to', ArrayUtils::get($data, 'toGroup', []));
150
151
        if (!is_array($to)) {
152
            $to = explode(',', $to);
153
        }
154
155
        $toIds = array_map(function($id) use ($isGroup) {
156
            return sprintf('%s_%s', ($isGroup ? 1 : 0), $id);
157
        }, $to);
158
159
        return implode(',', $toIds);
160
    }
161
}
162