Issues (61)

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/Schema.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 Fubhy\GraphQL;
4
5
use Fubhy\GraphQL\Type\Definition\FieldArgument;
6
use Fubhy\GraphQL\Type\Definition\Types\InterfaceType;
7
use Fubhy\GraphQL\Type\Definition\Types\ModifierInterface;
8
use Fubhy\GraphQL\Type\Definition\Types\ObjectType;
9
use Fubhy\GraphQL\Type\Definition\Types\Type;
10
use Fubhy\GraphQL\Type\Definition\Types\TypeInterface;
11
use Fubhy\GraphQL\Type\Definition\Types\UnionType;
12
use Fubhy\GraphQL\Type\Directives\Directive;
13
use Fubhy\GraphQL\Type\Introspection;
14
15
/**
16
 * Schema Definition
17
 *
18
 * A Schema is created by supplying the root types of each type of operation,
19
 * query and mutation (optional). A schema definition is then supplied to the
20
 * validator and executor.
21
 */
22
class Schema
23
{
24
    /**
25
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType|null
26
     */
27
    protected $mutationType;
28
29
    /**
30
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
31
     */
32
    protected $queryType;
33
34
    /**
35
     * @var \Fubhy\GraphQL\Type\Directives\DirectiveInterface[]
36
     */
37
    protected $directives;
38
39
    /**
40
     * @var \Fubhy\GraphQL\Type\Definition\Types\TypeInterface[]
41
     */
42
    protected $typeMap;
43
44
    /**
45
     * Constructor.
46
     *
47
     * @param \Fubhy\GraphQL\Type\Definition\Types\TypeInterface $queryType
48
     * @param \Fubhy\GraphQL\Type\Definition\Types\TypeInterface|null $mutationType
49
     */
50 309
    public function __construct(TypeInterface $queryType, TypeInterface $mutationType = NULL)
51
    {
52 309
        $this->queryType = $queryType;
0 ignored issues
show
Documentation Bug introduced by
$queryType is of type object<Fubhy\GraphQL\Typ...on\Types\TypeInterface>, but the property $queryType was declared to be of type object<Fubhy\GraphQL\Typ...ition\Types\ObjectType>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
53 309
        $this->mutationType = $mutationType;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mutationType can also be of type object<Fubhy\GraphQL\Typ...on\Types\TypeInterface>. However, the property $mutationType is declared as type object<Fubhy\GraphQL\Typ...\Types\ObjectType>|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
54 309
    }
55
56
    /**
57
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
58
     */
59 297
    public function getQueryType()
60
    {
61 297
        return $this->queryType;
62
    }
63
64
    /**
65
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType|null
66
     */
67 162
    public function getMutationType()
68
    {
69 162
        return $this->mutationType;
70
    }
71
72
    /**
73
     * @param string $name
74
     *
75
     * @return \Fubhy\GraphQL\Type\Directives\DirectiveInterface|null
76
     */
77 3
    public function getDirective($name)
78
    {
79
        foreach ($this->getDirectives() as $directive) {
80
            if ($directive->getName() === $name) {
81 3
                return $directive;
82
            }
83
        }
84
        return NULL;
85
    }
86
87
    /**
88
     * @return \Fubhy\GraphQL\Type\Directives\DirectiveInterface[]
89
     */
90 3
    public function getDirectives()
91
    {
92 3
        if (!isset($this->directives)) {
93 3
            $include = Directive::includeDirective();
94 3
            $skip = Directive::skipDirective();
95
96 3
            $this->directives = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array($include->getName(...ip->getName() => $skip) of type array<string,object<Fubh...es\DirectiveInterface>> is incompatible with the declared type array<integer,object<Fub...es\DirectiveInterface>> of property $directives.

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...
97 3
                $include->getName() => $include,
98 3
                $skip->getName() => $skip,
99
            ];
100 3
        }
101
102 3
        return $this->directives;
103
    }
104
105
    /**
106
     * @return \Fubhy\GraphQL\Type\Definition\Types\TypeInterface[]
107
     */
108 153
    public function getTypeMap()
109
    {
110 153
        if (!isset($this->typeMap)) {
111 153
            $input = [$this->getQueryType(), $this->getMutationType(), Introspection::schema()];
112 153
            $this->typeMap = array_reduce($input, [$this, 'typeMapReducer'], []);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_reduce($input, arr...eMapReducer'), array()) of type * is incompatible with the declared type array<integer,object<Fub...n\Types\TypeInterface>> of property $typeMap.

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...
113
114 153
            $this->typeMap['Boolean'] = Type::booleanType();
115 153
            $this->typeMap['Float'] = Type::floatType();
116 153
            $this->typeMap['Id'] = Type::idType();
117 153
            $this->typeMap['Integer'] = Type::intType();
118 153
            $this->typeMap['String'] = Type::stringType();
119 153
        }
120
121 153
        return $this->typeMap;
122
    }
123
124
    /**
125
     * @param string $name
126
     *
127
     * @return \Fubhy\GraphQL\Type\Definition\Types\TypeInterface
128
     */
129 147
    public function getType($name)
130
    {
131 147
        $map = $this->getTypeMap();
132 147
        return isset($map[$name]) ? $map[$name] : NULL;
133
    }
134
135
    /**
136
     * @param \Fubhy\GraphQL\Type\Definition\Types\TypeInterface[] $map
137
     * @param mixed $type
138
     *
139
     * @return \Fubhy\GraphQL\Type\Definition\Types\TypeInterface[]
140
     */
141 153
    protected function typeMapReducer(array $map, $type)
142
    {
143 153
        if ($type instanceof ModifierInterface) {
144 153
            return $this->typeMapReducer($map, $type->getWrappedType());
145
        }
146
147 153
        if (!$type instanceof TypeInterface) {
148 153
            return $map;
149
        }
150
151 153
        if (!empty($map[$type->getName()])) {
152 153
            if ($type instanceof ObjectType || $type instanceof InterfaceType) {
153 48
                $type->setFields($map[$type->getName()]->getFields());
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Fubhy\GraphQL\Type\Definition\Types\TypeInterface as the method getFields() does only exist in the following implementations of said interface: Fubhy\GraphQL\Type\Defin...n\Types\InputObjectType, Fubhy\GraphQL\Type\Definition\Types\InterfaceType, Fubhy\GraphQL\Type\Definition\Types\ObjectType.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
154 48
            }
155 48
156 48
            return $map;
157
        }
158 153
159 153
        $reducedMap = array_merge($map, [$type->getName() => $type]);
160 153
        if ($type instanceof InterfaceType || $type instanceof UnionType) {
161 153
            $reducedMap = array_reduce(
162 153
                $type->getPossibleTypes(), [$this, 'typeMapReducer'], $reducedMap
163
            );
164 153
        }
165 153
166 153
        if ($type instanceof ObjectType) {
167 153
            $reducedMap = array_reduce(
168 153
                $type->getInterfaces(), [$this, 'typeMapReducer'], $reducedMap
169 153
            );
170
        }
171 153
172 153
        if ($type instanceof ObjectType || $type instanceof InterfaceType) {
173 153
            foreach ($type->getFields() as $fieldName => $field) {
174
                $args = $field->getArguments();
175 153
                $reducedMap = array_reduce(array_map(function (FieldArgument $arg) {
176
                    return $arg->getType();
177
                }, $args), [$this, 'typeMapReducer'], $reducedMap);
178
179
                $reducedMap = $this->typeMapReducer($reducedMap, $field->getType());
180
            }
181
        }
182
183
        return $reducedMap;
184
    }
185
186
    /**
187
     * Re-populate static properties when de-serializing.
188
     */
189
    public function __wakeup() {
190
        Type::intType();
191
        Type::booleanType();
192
        Type::floatType();
193
        Type::idType();
194
        Type::stringType();
195
    }
196
}
197