Issues (234)

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.

Tests/Schema/FragmentsTest.php (6 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 Youshido\Tests\Schema;
4
5
use Youshido\GraphQL\Config\Object\InterfaceTypeConfig;
6
use Youshido\GraphQL\Config\Object\ObjectTypeConfig;
7
use Youshido\GraphQL\Execution\Processor;
8
use Youshido\GraphQL\Schema\Schema;
9
use Youshido\GraphQL\Type\InterfaceType\AbstractInterfaceType;
10
use Youshido\GraphQL\Type\InterfaceType\InterfaceType;
11
use Youshido\GraphQL\Type\ListType\ListType;
12
use Youshido\GraphQL\Type\NonNullType;
13
use Youshido\GraphQL\Type\Object\AbstractObjectType;
14
use Youshido\GraphQL\Type\Object\ObjectType;
15
use Youshido\GraphQL\Type\Scalar\IdType;
16
use Youshido\GraphQL\Type\Scalar\IntType;
17
use Youshido\GraphQL\Type\Scalar\StringType;
18
19
20
class UserType extends AbstractObjectType
21
{
22
    public function build($config)
23
    {
24
        $config->addFields([
25
            'id'           => new IdType(),
26
            'fullName'     => new StringType(),
27
            'reservations' => new ListType(new ReservationInterface())
28
        ]);
29
    }
30
}
31
32
class CourtReservation extends AbstractObjectType
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
33
{
34
35
    public function build($config)
36
    {
37
        $config->addFields([
38
            'id'      => new IdType(),
39
            'players' => new ListType(new ObjectType([
40
                'name'   => 'Player',
41
                'fields' => [
42
                    'id'   => new IdType(),
43
                    'user' => new UserType()
44
                ]
45
            ]))
46
        ]);
47
    }
48
49
    public function getInterfaces()
50
    {
51
        return [new ReservationInterface()];
52
    }
53
54
}
55
56
class ClassReservation extends AbstractObjectType
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
57
{
58
    public function build($config)
59
    {
60
        $config->addFields([
61
            'id'   => new IdType(),
62
            'user' => new UserType()
63
        ]);
64
    }
65
66
    public function getInterfaces()
67
    {
68
        return [new ReservationInterface()];
69
    }
70
}
71
72
class ReservationInterface extends AbstractInterfaceType
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
73
{
74
    public function resolveType($object)
75
    {
76
        return strpos($object['id'], 'cl') === false ? new CourtReservation() : new ClassReservation();
77
    }
78
79
    public function build($config)
80
    {
81
        $config->addFields([
82
            'id' => new IdType()
83
        ]);
84
    }
85
86
}
87
88
class FragmentsTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
89
{
90
91
    /**
92
     * @dataProvider queries
93
     *
94
     * @param $query
95
     * @param $expected
96
     * @param $variables
97
     */
98
    public function testVariables($query, $expected, $variables)
99
    {
100
        $schema = new Schema([
101
            'query' => new ObjectType([
102
                'name'   => 'RootQuery',
103
                'fields' => [
104
                    'user' => [
105
                        'type'    => new UserType(),
106
                        'resolve' => function ($args) {
0 ignored issues
show
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
                            return [
108
                                'id'           => 'user-id-1',
109
                                'fullName'     => 'Alex',
110
                                'reservations' => [
111
                                    [
112
                                        'id'   => 'cl-1',
113
                                        'user' => [
114
                                            'id'       => 'user-id-2',
115
                                            'fullName' => 'User class1'
116
                                        ],
117
                                    ],
118
                                    [
119
                                        'id'      => 'court-1',
120
                                        'players' => [
121
                                            [
122
                                                'id'   => 'player-id-1',
123
                                                'user' => [
124
                                                    'id'       => 'user-id-3',
125
                                                    'fullName' => 'User court1'
126
                                                ]
127
                                            ]
128
                                        ]
129
                                    ],
130
                                ]
131
                            ];
132
                        },
133
                    ],
134
                ]
135
            ])
136
        ]);
137
138
        $processor = new Processor($schema);
139
        $processor->processPayload($query, $variables);
140
        $result = $processor->getResponseData();
141
142
        $this->assertEquals($expected, $result);
143
    }
144
145
    public function queries()
146
    {
147
        return [
148
            [
149
                'query {
150
                    user {
151
                        ...fUser
152
                        reservations {
153
                            ...fReservation
154
                        }
155
                    }
156
                }
157
                fragment fReservation on ReservationInterface {
158
                    id
159
                    ... on CourtReservation {
160
                        players {
161
                            id
162
                            user {
163
                                ...fUser
164
                            }
165
                        }
166
                    }
167
                    ... on ClassReservation {
168
                        user {
169
                            ...fUser
170
                        }
171
                    }
172
                }
173
                fragment fUser on User {
174
                    id
175
                    fullName
176
                }',
177
                [
178
                    'data' => [
179
                        'user' => [
180
                            'id'           => 'user-id-1',
181
                            'fullName'     => 'Alex',
182
                            'reservations' => [
183
                                [
184
                                    'id'   => 'cl-1',
185
                                    'user' => [
186
                                        'id'       => 'user-id-2',
187
                                        'fullName' => 'User class1'
188
                                    ]
189
                                ],
190
                                [
191
                                    'id'      => 'court-1',
192
                                    'players' => [
193
                                        [
194
                                            'id'   => 'player-id-1',
195
                                            'user' => [
196
                                                'id'       => 'user-id-3',
197
                                                'fullName' => 'User court1'
198
                                            ]
199
                                        ]
200
                                    ]
201
                                ],
202
                            ]
203
                        ]
204
                    ],
205
                ],
206
                [
207
                ]
208
            ],
209
        ];
210
    }
211
212
    public function testSimpleFragment()
213
    {
214
        $schema = new Schema([
215
            'query' => new ObjectType([
216
                'name'   => 'RootQuery',
217
                'fields' => [
218
                    'user' => [
219
                        'type'    => new UserType(),
220
                        'resolve' => function ($args) {
0 ignored issues
show
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
221
                            return [
222
                                'id'       => 'user-id-1',
223
                                'fullName' => 'Alex',
224
                            ];
225
                        },
226
                        'args' => [
227
                            'id' => new IntType(),
228
                        ]
229
                    ],
230
                ]
231
            ])
232
        ]);
233
234
        $query = '
235
        {
236
            User1: user(id: 1) {
237
                fullName
238
            }
239
            User2: user(id: 1) {
240
                ...Fields
241
            }
242
        }
243
        
244
        fragment Fields on User {
245
            fullName
246
        }';
247
248
        $processor = new Processor($schema);
249
        $processor->processPayload($query);
250
        $result = $processor->getResponseData();
251
252
        $expected = ['data' => ['User1' => ['fullName' => 'Alex'], 'User2' => ['fullName' => 'Alex']]];
253
        $this->assertEquals($expected, $result);
254
    }
255
256
}