Issues (171)

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/Functional/ProfilingTest.php (9 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 Http\HttplugBundle\Tests\Functional;
6
7
use GuzzleHttp\Psr7\Request;
8
use Http\Client\Common\Plugin;
9
use Http\Client\Common\PluginClient;
10
use Http\Discovery\StreamFactoryDiscovery;
11
use Http\Discovery\UriFactoryDiscovery;
12
use Http\HttplugBundle\Collector\Collector;
13
use Http\HttplugBundle\Collector\Formatter;
14
use Http\HttplugBundle\Collector\ProfileClient;
15
use Http\HttplugBundle\Collector\ProfilePlugin;
16
use Http\HttplugBundle\Collector\StackPlugin;
17
use Http\Message\Formatter\CurlCommandFormatter;
18
use Http\Message\Formatter\FullHttpMessageFormatter;
19
use Http\Mock\Client;
20
use PHPUnit\Framework\TestCase;
21
use Psr\Http\Message\RequestInterface;
22
use Symfony\Component\Cache\Adapter\ArrayAdapter;
23
use Symfony\Component\Stopwatch\Stopwatch;
24
25
class ProfilingTest extends TestCase
26
{
27
    /**
28
     * @var Collector
29
     */
30
    private $collector;
31
32
    /**
33
     * @var Formatter
34
     */
35
    private $formatter;
36
37
    /**
38
     * @var Stopwatch
39
     */
40
    private $stopwatch;
41
42
    public function setUp(): void
43
    {
44
        $this->collector = new Collector([]);
0 ignored issues
show
The call to Collector::__construct() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
45
        $this->formatter = new Formatter(new FullHttpMessageFormatter(), new CurlCommandFormatter());
46
        $this->stopwatch = new Stopwatch();
47
    }
48
49
    public function testProfilingWithCachePlugin(): void
50
    {
51
        $client = $this->createClient([
52
            new Plugin\CachePlugin(new ArrayAdapter(), StreamFactoryDiscovery::find(), [
53
                'respect_response_cache_directives' => [],
54
                'default_ttl' => 86400,
55
            ]),
56
        ]);
57
58
        $client->sendRequest(new Request('GET', 'https://example.com'));
59
        $client->sendRequest(new Request('GET', 'https://example.com'));
60
61
        $this->assertCount(2, $this->collector->getStacks());
0 ignored issues
show
$this->collector->getStacks() is of type array<integer,object<Htt...undle\Collector\Stack>>, but the function expects a object<Countable>|object...nit\Framework\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...
62
        $stack = $this->collector->getStacks()[1];
63
        $this->assertEquals('GET', $stack->getRequestMethod());
64
        $this->assertEquals('https', $stack->getRequestScheme());
65
        $this->assertEquals('/', $stack->getRequestTarget());
66
        $this->assertEquals('example.com', $stack->getRequestHost());
67
    }
68
69
    public function testProfilingWhenPluginThrowException(): void
70
    {
71
        $client = $this->createClient([
72
            new ExceptionThrowerPlugin(),
73
        ]);
74
75
        try {
76
            $this->expectException(\Exception::class);
77
            $client->sendRequest(new Request('GET', 'https://example.com'));
78
        } finally {
79
            $this->assertCount(1, $this->collector->getStacks());
0 ignored issues
show
$this->collector->getStacks() is of type array<integer,object<Htt...undle\Collector\Stack>>, but the function expects a object<Countable>|object...nit\Framework\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...
80
            $stack = $this->collector->getStacks()[0];
81
            $this->assertEquals('GET', $stack->getRequestMethod());
82
            $this->assertEquals('https', $stack->getRequestScheme());
83
            $this->assertEquals('/', $stack->getRequestTarget());
84
            $this->assertEquals('example.com', $stack->getRequestHost());
85
        }
86
    }
87
88
    public function testProfiling(): void
89
    {
90
        $client = $this->createClient([
91
            new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://example.com')),
92
            new Plugin\RedirectPlugin(),
93
            new Plugin\RetryPlugin(),
94
        ]);
95
96
        $client->sendRequest(new Request('GET', '/'));
97
98
        $this->assertCount(1, $this->collector->getStacks());
0 ignored issues
show
$this->collector->getStacks() is of type array<integer,object<Htt...undle\Collector\Stack>>, but the function expects a object<Countable>|object...nit\Framework\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...
99
        $stack = $this->collector->getStacks()[0];
100
        $this->assertCount(3, $stack->getProfiles());
0 ignored issues
show
$stack->getProfiles() is of type array<integer,object<Htt...dle\Collector\Profile>>, but the function expects a object<Countable>|object...nit\Framework\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...
101
        $this->assertEquals('GET', $stack->getRequestMethod());
102
        $this->assertEquals('https', $stack->getRequestScheme());
103
        $this->assertEquals('/', $stack->getRequestTarget());
104
        $this->assertEquals('example.com', $stack->getRequestHost());
105
    }
106
107
    private function createClient(array $plugins, $clientName = 'Acme', array $clientOptions = [])
108
    {
109
        $plugins = array_map(function (Plugin $plugin) {
110
            return new ProfilePlugin($plugin, $this->collector, $this->formatter, get_class($plugin));
0 ignored issues
show
The call to ProfilePlugin::__construct() has too many arguments starting with get_class($plugin).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
111
        }, $plugins);
112
113
        array_unshift($plugins, new StackPlugin($this->collector, $this->formatter, $clientName));
114
115
        $client = new Client();
116
        $client = new ProfileClient($client, $this->collector, $this->formatter, $this->stopwatch);
117
        $client = new PluginClient($client, $plugins, $clientOptions);
118
119
        return $client;
120
    }
121
}
122
123
class ExceptionThrowerPlugin implements Plugin
124
{
125
    use Plugin\VersionBridgePlugin;
126
127
    protected function doHandleRequest(RequestInterface $request, callable $next, callable $first): void
0 ignored issues
show
The parameter $request 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...
The parameter $next 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...
The parameter $first 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...
128
    {
129
        throw new \Exception();
130
    }
131
}
132