Issues (74)

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.

Driver/Doctrine/QueryBuilder/JoinGenerator.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
namespace Netdudes\DataSourceryBundle\DataSource\Driver\Doctrine\QueryBuilder;
3
4
use Doctrine\ORM\Query\Expr\Join;
5
use Netdudes\DataSourceryBundle\DataSource\Configuration\Field;
6
use Netdudes\DataSourceryBundle\Query\Query;
7
8
class JoinGenerator
9
{
10
    /**
11
     * @var array
12
     */
13
    private $uniqueJoinNameCache = [];
14
15
    /**
16
     * @var Field[]
17
     */
18
    private $queryBuilderDataSourceFields;
19
20
    /**
21
     * @var Join[]
22
     */
23
    private $joins;
24
25
    /**
26
     * @var string
27
     */
28
    private $fromAlias;
29
30
    /**
31
     * @var Join[][]
32
     */
33
    private $joinCache = [];
34
35
    /**
36
     * @param array                   $queryBuilderDataSourceFields
37
     * @param                         $fromAlias
38
     * @param RequiredFieldsExtractor $requiredFieldsExtractor
39
     */
40
    public function __construct(array $queryBuilderDataSourceFields, $fromAlias, RequiredFieldsExtractor $requiredFieldsExtractor)
41
    {
42
        $this->requiredFieldsExtractor = $requiredFieldsExtractor;
0 ignored issues
show
The property requiredFieldsExtractor does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
        $this->queryBuilderDataSourceFields = $queryBuilderDataSourceFields;
44
        $this->fromAlias = $fromAlias;
45
    }
46
47
    /**
48
     * Generate the needed joins given a $query. This function will build a dependency tree and
49
     * walk it recursively to generate an ordered list of Join statements.
50
     *
51
     * @param Query $query
52
     *
53
     * @return Join[]
54
     */
55 View Code Duplication
    public function generate(Query $query)
0 ignored issues
show
This method seems to be duplicated in 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...
56
    {
57
        $uniqueId = spl_object_hash($query);
58
        if (!isset($this->joinCache[$uniqueId])) {
59
            $this->joinCache[$uniqueId] = $this->build($query);
60
        }
61
62
        return $this->joinCache[$uniqueId];
63
    }
64
65
    /**
66
     * @param Query $query
67
     *
68
     * @return Join[]
69
     */
70
    protected function build(Query $query)
71
    {
72
        $elements = [];
73
        $requiredFields = $this->requiredFieldsExtractor->extractRequiredFields($query);
74
        foreach ($this->queryBuilderDataSourceFields as $field) {
75
            if (!is_null($query) && !in_array($field->getUniqueName(), $requiredFields, true)) {
76
                continue;
77
            }
78
            if (!is_null($field->getDatabaseFilterQueryField())) {
79
                $elements[] = $field->getDatabaseFilterQueryField();
80
            }
81
        }
82
        $tree = $this->generateJoinDependencyTree($elements);
83
        $this->joins = [];
84
        foreach ($tree as $child => $grandChildren) {
85
            $this->walkDependencyTreeNode($this->fromAlias, $child, $grandChildren);
86
        }
87
88
        return $this->joins;
89
    }
90
91
    /**
92
     * Builds a tree of dependencies between entity fields, relating what joins
93
     * are needed for each selected field in the query.
94
     *
95
     * This action is performed recursively.
96
     *
97
     * @param array $elements
98
     *
99
     * @return array
100
     */
101
    protected function generateJoinDependencyTree(array $elements)
102
    {
103
        $subtree = [];
104
        foreach ($elements as $element) {
105
            $parts = explode('.', $element, 2);
106
            if (count($parts) == 1) {
107
                continue;
108
            }
109
            if (!isset($subtree[$parts[0]])) {
110
                $subtree[$parts[0]] = [];
111
            }
112
            $subtree[$parts[0]][] = $parts[1];
113
        }
114
        foreach ($subtree as $key => $elements) {
115
            $subtree[$key] = $this->generateJoinDependencyTree($elements);
116
        }
117
118
        return $subtree;
119
    }
120
121
    /**
122
     * Walks a node of the dependency tree, recursively generating an ordered list on Joins
123
     * that is stored in the $this->joins cache.
124
     *
125
     * @param       $parentUniqueIdentifier
126
     * @param       $node
127
     * @param       $descendants
128
     * @param array $completePath
129
     */
130
    protected function walkDependencyTreeNode($parentUniqueIdentifier, $node, $descendants, $completePath = [])
131
    {
132
        $completePath[] = $node;
133
        $joinedCompletePath = implode('.', $completePath);
134
        $joinUniqueIdentifier =
135
            array_key_exists($joinedCompletePath, $this->uniqueJoinNameCache) ?
136
                $this->uniqueJoinNameCache[$joinedCompletePath] :
137
                ($this->uniqueJoinNameCache[$joinedCompletePath] = uniqid("JOIN_${node}_"));
138
        $this->joins[$joinedCompletePath] = new Join(Join::LEFT_JOIN, $parentUniqueIdentifier . '.' . $node, $joinUniqueIdentifier);
139
        foreach ($descendants as $child => $grandChildren) {
140
            $this->walkDependencyTreeNode($joinUniqueIdentifier, $child, $grandChildren, $completePath);
141
        }
142
    }
143
}
144