Issues (126)

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/Io/StreamWrapper.php (11 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
declare(strict_types=1);
3
/**
4
 * Minotaur
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
 * use this file except in compliance with the License. You may obtain a copy of
8
 * the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 * License for the specific language governing permissions and limitations under
16
 * the License.
17
 *
18
 * @copyright 2015-2017 Appertly
19
 * @license   Apache-2.0
20
 */
21
namespace Minotaur\Io;
22
23
/**
24
 * Allows PSR-7 streams to be used as PHP streams.
25
 *
26
 * Based on Guzzle PSR7 stream wrapper and MongoDB's PHP library stream wrapper.
27
 */
28
class StreamWrapper
29
{
30
    /**
31
     * @var resource|null The stream context
32
     */
33
    public $context;
34
35
    /**
36
     * @var StreamInterface|null The PSR-7 stream
37
     */
38
    private $stream;
39
40
    /**
41
     * @var string|null The stream mode
42
     */
43
    private $mode;
44
45
    /**
46
     * Registers this stream wrapper
47
     */
48
    public static function register(): void
49
    {
50
        if (!in_array('psr7', stream_get_wrappers())) {
51
            stream_wrapper_register('psr7', __CLASS__);
52
        }
53
    }
54
55
    /**
56
     * Unregisters this stream wrapper
57
     */
58
    public static function unregister(): void
59
    {
60
        if (in_array('psr7', stream_get_wrappers())) {
61
            stream_wrapper_unregister('psr7');
62
        }
63
    }
64
65
    /**
66
     * Gets a PHP stream resource for the provided PSR-7 stream.
67
     *
68
     * @param \Psr\Http\Message\StreamInterface $stream The stream to wrap
69
     * @return resource The generated resource
70
     * @throws \InvalidArgumentException if stream is not readable or writable
71
     */
72
    public static function getResource(\Psr\Http\Message\StreamInterface $stream)
73
    {
74
        self::register();
75
        if ($stream->isReadable()) {
76
            $mode = $stream->isWritable() ? 'r+' : 'r';
77
        } elseif ($stream->isWritable()) {
78
            $mode = 'w';
79
        } else {
80
            throw new \InvalidArgumentException('The stream must be readable, writable, or both');
81
        }
82
        return fopen('psr7://stream', $mode, false, stream_context_create([
83
            'psr7' => ['stream' => $stream]
84
        ]));
85
    }
86
87
    public function stream_open(string $path, string $mode, int $options, ?string &$opened_path)
0 ignored issues
show
The parameter $path 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 $options 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 $opened_path 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...
Method name "StreamWrapper::stream_open" is not in camel caps format
Loading history...
88
    {
89
        $options = stream_context_get_options($this->context);
90
        if (!isset($options['psr7']['stream'])) {
91
            return false;
92
        }
93
        $this->stream = $options['psr7']['stream'];
94
        $this->mode = $mode;
95
        return true;
96
    }
97
98
    public function stream_read(int $count): string
0 ignored issues
show
Method name "StreamWrapper::stream_read" is not in camel caps format
Loading history...
99
    {
100
        return $this->stream->read($count);
101
    }
102
103
    public function stream_write(string $data): int
0 ignored issues
show
Method name "StreamWrapper::stream_write" is not in camel caps format
Loading history...
104
    {
105
        return (int) $this->stream->write($data);
106
    }
107
108
    public function stream_tell(): int
0 ignored issues
show
Method name "StreamWrapper::stream_tell" is not in camel caps format
Loading history...
109
    {
110
        return $this->stream->tell();
111
    }
112
113
    public function stream_eof(): bool
0 ignored issues
show
Method name "StreamWrapper::stream_eof" is not in camel caps format
Loading history...
114
    {
115
        return $this->stream->eof();
116
    }
117
118
    public function stream_seek(int $offset, int $whence = SEEK_SET): bool
0 ignored issues
show
Method name "StreamWrapper::stream_seek" is not in camel caps format
Loading history...
119
    {
120
        return $this->stream->seek($offset, $whence);
121
    }
122
123
    public function stream_stat(): array
0 ignored issues
show
Method name "StreamWrapper::stream_stat" is not in camel caps format
Loading history...
124
    {
125
        static $modeMap = [
126
            'r'  => 33060,
127
            'r+' => 33206,
128
            'w'  => 33188
129
        ];
130
        $stat = $this->getStatTemplate();
131
        $stat[2] = $stat['mode'] = $modeMap[$this->mode];
132
        $stat[7] = $stat['size'] = $this->stream->getSize();
133
        return $stat;
134
    }
135
136
    /**
137
     * Gets a URL stat template with default values.
138
     *
139
     * Blatently lifted from https://github.com/aws/aws-sdk-php/blob/master/src/S3/StreamWrapper.php
140
     *
141
     * @return - The stat template.
0 ignored issues
show
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
142
     */
143
    private function getStatTemplate(): array
144
    {
145
        return [
146
            0  => 0,  'dev'     => 0,
147
            1  => 0,  'ino'     => 0,
148
            2  => 0,  'mode'    => 0,
149
            3  => 0,  'nlink'   => 0,
150
            4  => 0,  'uid'     => 0,
151
            5  => 0,  'gid'     => 0,
152
            6  => -1, 'rdev'    => -1,
153
            7  => 0,  'size'    => 0,
154
            8  => 0,  'atime'   => 0,
155
            9  => 0,  'mtime'   => 0,
156
            10 => 0,  'ctime'   => 0,
157
            11 => -1, 'blksize' => -1,
158
            12 => -1, 'blocks'  => -1,
159
        ];
160
    }
161
}
162