Issues (10)

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.

src/Request/OAuth2Request.php (3 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
declare(strict_types=1);
4
5
namespace Facile\OAuth2\HttpClient\Request;
6
7
use function array_key_exists;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\StreamInterface;
10
use Psr\Http\Message\UriInterface;
11
12
class OAuth2Request implements OAuth2RequestInterface
13
{
14
    /** @var RequestInterface */
15
    private $request;
16
17
    /**
18
     * @var array<string, mixed>
19
     */
20
    private $grantParams = [];
21
22 25
    public function __construct(RequestInterface $request)
23
    {
24 25
        $this->request = $request;
25 25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30 10
    public function getGrantParams(): array
31
    {
32 10
        return $this->grantParams;
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 10
    public function withGrantParams(array $grantParams): OAuth2RequestInterface
39
    {
40 10
        $new = clone $this;
41 10
        $new->grantParams = $grantParams;
42
43 10
        return $new;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $new; (Facile\OAuth2\HttpClient\Request\OAuth2Request) is incompatible with the return type declared by the interface Facile\OAuth2\HttpClient...erface::withGrantParams of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49 1
    public function withGrantParam(string $name, $value): OAuth2RequestInterface
50
    {
51 1
        $new = clone $this;
52 1
        $new->grantParams[$name] = $value;
53
54 1
        return $new;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $new; (Facile\OAuth2\HttpClient\Request\OAuth2Request) is incompatible with the return type declared by the interface Facile\OAuth2\HttpClient...terface::withGrantParam of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60 1
    public function withoutGrantParam(string $name): OAuth2RequestInterface
61
    {
62 1
        $new = clone $this;
63 1
        if (array_key_exists($name, $new->grantParams)) {
64 1
            unset($new->grantParams[$name]);
65
        }
66
67 1
        return $new;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $new; (Facile\OAuth2\HttpClient\Request\OAuth2Request) is incompatible with the return type declared by the interface Facile\OAuth2\HttpClient...face::withoutGrantParam of type self.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73 1
    public function getProtocolVersion(): string
74
    {
75 1
        return $this->request->getProtocolVersion();
76
    }
77
78
    /**
79
     * @inheritDoc
80
     */
81 2
    public function withProtocolVersion($version)
82
    {
83 2
        $new = clone $this;
84 2
        $new->request = $this->request->withProtocolVersion($version);
85
86 2
        return $new;
87
    }
88
89
    /**
90
     * @inheritDoc
91
     */
92 1
    public function getHeaders(): array
93
    {
94 1
        return $this->request->getHeaders();
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100 10
    public function hasHeader($name): bool
101
    {
102 10
        return $this->request->hasHeader($name);
103
    }
104
105
    /**
106
     * @inheritDoc
107
     */
108 8
    public function getHeader($name): array
109
    {
110 8
        return $this->request->getHeader($name);
111
    }
112
113
    /**
114
     * @inheritDoc
115
     */
116 1
    public function getHeaderLine($name): string
117
    {
118 1
        return $this->request->getHeaderLine($name);
119
    }
120
121
    /**
122
     * @inheritDoc
123
     */
124 7
    public function withHeader($name, $value)
125
    {
126 7
        $new = clone $this;
127 7
        $new->request = $this->request->withHeader($name, $value);
128
129 7
        return $new;
130
    }
131
132
    /**
133
     * @inheritDoc
134
     */
135 1
    public function withAddedHeader($name, $value)
136
    {
137 1
        $new = clone $this;
138 1
        $new->request = $this->request->withAddedHeader($name, $value);
139
140 1
        return $new;
141
    }
142
143
    /**
144
     * @inheritDoc
145
     */
146 7
    public function withoutHeader($name)
147
    {
148 7
        $new = clone $this;
149 7
        $new->request = $this->request->withoutHeader($name);
150
151 7
        return $new;
152
    }
153
154
    /**
155
     * @inheritDoc
156
     */
157 2
    public function getBody()
158
    {
159 2
        return $this->request->getBody();
160
    }
161
162
    /**
163
     * @inheritDoc
164
     */
165 1
    public function withBody(StreamInterface $body)
166
    {
167 1
        $new = clone $this;
168 1
        $new->request = $this->request->withBody($body);
169
170 1
        return $new;
171
    }
172
173
    /**
174
     * @inheritDoc
175
     */
176 2
    public function getRequestTarget(): string
177
    {
178 2
        return $this->request->getRequestTarget();
179
    }
180
181
    /**
182
     * @inheritDoc
183
     */
184 1
    public function withRequestTarget($requestTarget)
185
    {
186 1
        $new = clone $this;
187 1
        $new->request = $this->request->withRequestTarget($requestTarget);
188
189 1
        return $new;
190
    }
191
192
    /**
193
     * @inheritDoc
194
     */
195 6
    public function getMethod(): string
196
    {
197 6
        return $this->request->getMethod();
198
    }
199
200
    /**
201
     * @inheritDoc
202
     */
203 1
    public function withMethod($method)
204
    {
205 1
        $new = clone $this;
206 1
        $new->request = $this->request->withMethod($method);
207
208 1
        return $new;
209
    }
210
211
    /**
212
     * @inheritDoc
213
     */
214 2
    public function getUri(): UriInterface
215
    {
216 2
        return $this->request->getUri();
217
    }
218
219
    /**
220
     * @inheritdoc
221
     */
222 1
    public function withUri(UriInterface $uri, $preserveHost = false)
223
    {
224 1
        $new = clone $this;
225 1
        $new->request = $this->request->withUri($uri, $preserveHost);
226
227 1
        return $new;
228
    }
229
}
230