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/ParseRelationshipLinksTrait.php (1 issue)

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 Neomerx\JsonApi\Contracts\Schema\LinkInterface;
22
use Neomerx\JsonApi\Contracts\Schema\SchemaInterface;
23
24
/**
25
 * @package Neomerx\JsonApi
26
 */
27
trait ParseRelationshipLinksTrait
28
{
29
    /**
30
     * @param SchemaInterface $parentSchema
31
     * @param mixed           $parentData
32
     * @param string          $name
33
     * @param array           $description
34
     *
35
     * @return array
36
     *
37
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
38
     */
39 50
    private function parseRelationshipLinks(
40
        SchemaInterface $parentSchema,
41
        $parentData,
42
        string $name,
43
        array $description
44
    ): array {
45 50
        $addSelfLink    = $description[SchemaInterface::RELATIONSHIP_LINKS_SELF] ??
46 50
            $parentSchema->isAddSelfLinkInRelationshipByDefault($name);
47 50
        $addRelatedLink = $description[SchemaInterface::RELATIONSHIP_LINKS_RELATED] ??
48 50
            $parentSchema->isAddRelatedLinkInRelationshipByDefault($name);
49 50
        \assert(\is_bool($addSelfLink) === true || $addSelfLink instanceof LinkInterface);
50 50
        \assert(\is_bool($addRelatedLink) === true || $addRelatedLink instanceof LinkInterface);
51
52 50
        $schemaLinks = $description[SchemaInterface::RELATIONSHIP_LINKS] ?? [];
53 50
        \assert(\is_array($schemaLinks));
54
55
        // if `self` or `related` link was given as LinkInterface merge it with the other links
56 50
        $extraSchemaLinks = null;
57 50
        if (\is_bool($addSelfLink) === false) {
58 1
            $extraSchemaLinks[LinkInterface::SELF] = $addSelfLink;
59 1
            $addSelfLink                           = false;
60
        }
61 50
        if (\is_bool($addRelatedLink) === false) {
62 1
            $extraSchemaLinks[LinkInterface::RELATED] = $addRelatedLink;
63 1
            $addRelatedLink                           = false;
64
        }
65 50
        if (empty($extraSchemaLinks) === false) {
66
            // IDE do not understand it's defined without he line below
67 1
            \assert(isset($extraSchemaLinks));
68 1
            $schemaLinks = \array_merge($extraSchemaLinks, $schemaLinks);
69 1
            unset($extraSchemaLinks);
70
        }
71 50
        \assert(\is_bool($addSelfLink) === true && \is_bool($addRelatedLink) === true);
72
73 50
        $hasLinks = $addSelfLink === true || $addRelatedLink === true || empty($schemaLinks) === false;
74 50
        $links    = $hasLinks === true ?
75 50
            $this->parseLinks($parentSchema, $parentData, $name, $schemaLinks, $addSelfLink, $addRelatedLink) : null;
0 ignored issues
show
$schemaLinks is of type array, but the function expects a object<Neomerx\JsonApi\P...ationshipData\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...
76
77 50
        return [$hasLinks, $links];
78
    }
79
80
    /**
81
     * @param SchemaInterface $parentSchema
82
     * @param mixed           $parentData
83
     * @param string          $relationshipName
84
     * @param iterable        $schemaLinks
85
     * @param bool            $addSelfLink
86
     * @param bool            $addRelatedLink
87
     *
88
     * @return iterable
89
     */
90 27
    private function parseLinks(
91
        SchemaInterface $parentSchema,
92
        $parentData,
93
        string $relationshipName,
94
        iterable $schemaLinks,
95
        bool $addSelfLink,
96
        bool $addRelatedLink
97
    ): iterable {
98 27
        $gotSelf    = false;
99 27
        $gotRelated = false;
100
101 27
        foreach ($schemaLinks as $name => $link) {
102 14
            \assert($link instanceof LinkInterface);
103 14
            if ($name === LinkInterface::SELF) {
104 10
                \assert($gotSelf === false);
105 10
                $gotSelf     = true;
106 10
                $addSelfLink = false;
107 5
            } elseif ($name === LinkInterface::RELATED) {
108 1
                \assert($gotRelated === false);
109 1
                $gotRelated     = true;
110 1
                $addRelatedLink = false;
111
            }
112
113 14
            yield $name => $link;
114
        }
115
116 27
        if ($addSelfLink === true) {
117 18
            $link = $parentSchema->getRelationshipSelfLink($parentData, $relationshipName);
118 18
            yield LinkInterface::SELF => $link;
119 18
            $gotSelf = true;
120
        }
121 27
        if ($addRelatedLink === true) {
122 15
            $link = $parentSchema->getRelationshipRelatedLink($parentData, $relationshipName);
123 15
            yield LinkInterface::RELATED => $link;
124 15
            $gotRelated = true;
125
        }
126
127
        // spec: check links has at least one of the following: self or related
128 27
        \assert($gotSelf || $gotRelated);
129 27
    }
130
}
131