Issues (23)

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.

RelationshipData/ParseRelationshipDataTrait.php (2 issues)

Severity

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 declare(strict_types=1);
2
3
namespace Neomerx\JsonApi\Parser\RelationshipData;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use IteratorAggregate;
22
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
23
use Neomerx\JsonApi\Contracts\Parser\EditableContextInterface;
24
use Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface;
25
use Neomerx\JsonApi\Contracts\Schema\IdentifierInterface;
26
use Neomerx\JsonApi\Contracts\Schema\PositionInterface;
27
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
28
use Neomerx\JsonApi\Contracts\Schema\SchemaInterface;
29
use Neomerx\JsonApi\Exceptions\InvalidArgumentException;
30
use Neomerx\JsonApi\Parser\IdentifierAndResource;
31
use Traversable;
32
use function Neomerx\JsonApi\I18n\format as _;
33
34
/**
35
 * @package Neomerx\JsonApi
36
 */
37
trait ParseRelationshipDataTrait
38
{
39
    /**
40
     * @param FactoryInterface         $factory
41
     * @param SchemaContainerInterface $container
42
     * @param EditableContextInterface $context
43
     * @param string                   $parentType
44
     * @param string                   $name
45
     * @param array                    $description
46
     * @param int                      $nextLevel
47
     * @param string                   $nextPathPrefix
48
     *
49
     * @return array [has data, parsed data, next position]
50
     */
51 50
    private function parseRelationshipData(
52
        FactoryInterface $factory,
53
        SchemaContainerInterface $container,
54
        EditableContextInterface $context,
55
        string $parentType,
56
        string $name,
57
        array $description,
58
        int $nextLevel,
59
        string $nextPathPrefix
60
    ): array {
61 50
        $hasData = \array_key_exists(SchemaInterface::RELATIONSHIP_DATA, $description);
62
        // either no data or data should be array/object/null
63 50
        \assert(
64 50
            $hasData === false ||
65
            (
66 39
                \is_array($data = $description[SchemaInterface::RELATIONSHIP_DATA]) === true ||
67 33
                \is_object($data) === true ||
68 50
                $data === null
69
            )
70
        );
71
72 50
        $nextPosition = $factory->createPosition(
73 50
            $nextLevel,
74 50
            $nextPathPrefix . $name,
75 50
            $parentType,
76 50
            $name
77
        );
78
79 50
        $relationshipData = $hasData === true ? $this->parseData(
80 39
            $factory,
81 39
            $container,
82 39
            $context,
83 39
            $nextPosition,
84 39
            $description[SchemaInterface::RELATIONSHIP_DATA]
85 50
        ) : null;
86
87 50
        return [$hasData, $relationshipData, $nextPosition];
88
    }
89
90
    /**
91
     * @param FactoryInterface         $factory
92
     * @param SchemaContainerInterface $container
93
     * @param EditableContextInterface $context
94
     * @param PositionInterface        $position
95
     * @param mixed                    $data
96
     *
97
     * @return RelationshipDataInterface
98
     */
99 39
    private function parseData(
100
        FactoryInterface $factory,
101
        SchemaContainerInterface $container,
102
        EditableContextInterface $context,
103
        PositionInterface $position,
104
        $data
105
    ): RelationshipDataInterface {
106
        // support if data is callable (e.g. a closure used to postpone actual data reading)
107 39
        if (\is_callable($data) === true) {
108 1
            $data = \call_user_func($data);
109
        }
110
111 39
        if ($container->hasSchema($data) === true) {
112 27
            return $factory->createRelationshipDataIsResource($container, $context, $position, $data);
113 37
        } elseif ($data instanceof IdentifierInterface) {
114 1
            return $factory->createRelationshipDataIsIdentifier($container, $context, $position, $data);
115 36
        } elseif (\is_array($data) === true) {
116 34
            return $factory->createRelationshipDataIsCollection($container, $context, $position, $data);
0 ignored issues
show
$data is of type array, but the function expects a object<Neomerx\JsonApi\C...cts\Factories\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
117 6
        } elseif ($data instanceof Traversable) {
118 1
            return $factory->createRelationshipDataIsCollection(
119 1
                $container,
120 1
                $context,
121 1
                $position,
122 1
                $data instanceof IteratorAggregate ? $data->getIterator() : $data
0 ignored issues
show
$data instanceof \Iterat...->getIterator() : $data is of type object<Traversable>, but the function expects a object<Neomerx\JsonApi\C...cts\Factories\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
            );
124 5
        } elseif ($data === null) {
125 5
            return $factory->createRelationshipDataIsNull();
126
        }
127
128 1
        throw new InvalidArgumentException(
129 1
            _(IdentifierAndResource::MSG_NO_SCHEMA_FOUND, \get_class($data), $position->getPath())
130
        );
131
    }
132
}
133