Issues (57)

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

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 Thruster\Component\HttpMessage;
4
5
use Psr\Http\Message\StreamInterface;
6
7
/**
8
 * Class BufferStream
9
 *
10
 * @package Thruster\Component\HttpMessage
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class BufferStream implements StreamInterface
14
{
15
    /**
16
     * @var int
17
     */
18
    private $hwm;
19
20
    /**
21
     * @var string
22
     */
23
    private $buffer;
24
25
    /**
26
     * @param int $hwm High water mark, representing the preferred maximum
27
     *                 buffer size. If the size of the buffer exceeds the high
28
     *                 water mark, then calls to write will continue to succeed
29
     *                 but will return false to inform writers to slow down
30
     *                 until the buffer has been drained by reading from it.
31
     */
32 11
    public function __construct($hwm = 16384)
33
    {
34 11
        $this->buffer = '';
35 11
        $this->hwm = $hwm;
36 11
    }
37
38 2
    public function __toString()
39
    {
40 2
        return $this->getContents();
41
    }
42
43 2
    public function getContents()
44
    {
45 2
        $buffer = $this->buffer;
46 2
        $this->buffer = '';
47
48 2
        return $buffer;
49
    }
50
51 1
    public function close()
52
    {
53 1
        $this->buffer = '';
54 1
    }
55
56 1
    public function detach()
57
    {
58 1
        $this->close();
59 1
    }
60
61 2
    public function getSize()
62
    {
63 2
        return strlen($this->buffer);
64
    }
65
66 1
    public function isReadable() : bool
67
    {
68 1
        return true;
69
    }
70
71 1
    public function isWritable() : bool
72
    {
73 1
        return true;
74
    }
75
76 2
    public function isSeekable() : bool
77
    {
78 2
        return false;
79
    }
80
81
    public function rewind()
82
    {
83
        $this->seek(0);
84
    }
85
86
    public function seek($offset, $whence = SEEK_SET)
87
    {
88
        throw new \RuntimeException('Cannot seek a BufferStream');
89
    }
90
91 3
    public function eof() : bool
92
    {
93 3
        return strlen($this->buffer) === 0;
94
    }
95
96 1
    public function tell()
97
    {
98 1
        throw new \RuntimeException('Cannot determine the position of a BufferStream');
99
    }
100
101
    /**
102
     * Reads data from the buffer.
103
     */
104 8
    public function read($length)
105
    {
106 8
        $currentLength = strlen($this->buffer);
107
108 8
        if ($length >= $currentLength) {
109
            // No need to slice the buffer because we don't have enough data.
110 7
            $result = $this->buffer;
111 7
            $this->buffer = '';
112
        } else {
113
            // Slice up the result to provide a subset of the buffer.
114 2
            $result = substr($this->buffer, 0, $length);
115 2
            $this->buffer = substr($this->buffer, $length);
116
        }
117
118 8
        return $result;
119
    }
120
121
    /**
122
     * Writes data to the buffer.
123
     */
124 8
    public function write($string)
125
    {
126 8
        $this->buffer .= $string;
127
128
        // TODO: What should happen here?
129 8
        if (strlen($this->buffer) >= $this->hwm) {
130 1
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type declared by the interface Psr\Http\Message\StreamInterface::write of type integer.

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...
131
        }
132
133 8
        return strlen($string);
134
    }
135
136 1
    public function getMetadata($key = null)
137
    {
138 1
        if ($key == 'hwm') {
139 1
            return $this->hwm;
140
        }
141
142 1
        return $key ? null : [];
143
    }
144
}
145