Issues (74)

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.

src/Stream/ResourceStream.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
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Stream;
5
6
use Genkgo\Mail\StreamInterface;
7
8
final class ResourceStream implements StreamInterface
9
{
10
    /**
11
     * @var resource
12
     */
13
    private $resource;
14
15
    /**
16
     * @param resource $resource
17
     */
18 113
    public function __construct($resource)
19
    {
20 113
        if (!\is_resource($resource)) {
21
            throw new \InvalidArgumentException('Argument 0 must be a resource');
22
        }
23
24 113
        \rewind($resource);
25 113
        $this->resource = $resource;
26 113
    }
27
28
    /**
29
     * @return string
30
     */
31 52
    public function __toString(): string
32
    {
33 52
        \rewind($this->resource);
34 52
        return (string)\stream_get_contents($this->resource);
35
    }
36
    
37
    public function close(): void
38
    {
39
        \fclose($this->resource);
40
    }
41
42
    /**
43
     * @return mixed
44
     */
45 107
    public function detach()
46
    {
47 107
        return $this->resource;
48
    }
49
50
    /**
51
     * @return int|null
52
     */
53 8
    public function getSize(): ?int
54
    {
55 8
        $stat = \fstat($this->resource);
56 8
        if ($stat === false) {
57
            throw new \UnexpectedValueException('Cannot get stat from resource');
58
        }
59
60 8
        return $stat['size'];
61
    }
62
63
    /**
64
     * @return int
65
     * @throws \RuntimeException
66
     */
67 6
    public function tell(): int
68
    {
69 6
        $tell = \ftell($this->resource);
70 6
        if ($tell === false) {
71
            throw new \UnexpectedValueException('Cannot get tell from resource');
72
        }
73
74 6
        return $tell;
75
    }
76
77
    /**
78
     * @return bool
79
     */
80 7
    public function eof(): bool
81
    {
82 7
        return \feof($this->resource);
83
    }
84
85
    /**
86
     * @return bool
87
     */
88
    public function isSeekable(): bool
89
    {
90
        $metaData = \stream_get_meta_data($this->resource);
91
        if (!isset($metaData['seekable'])) {
92
            return false;
93
        }
94
95
        return $metaData['seekable'];
96
    }
97
98
    /**
99
     * @param int $offset
100
     * @param int $whence
101
     * @return int
102
     */
103 1
    public function seek(int $offset, int $whence = SEEK_SET): int
104
    {
105 1
        return \fseek($this->resource, $offset, $whence);
106
    }
107
108
    /**
109
     * @return bool
110
     */
111 55
    public function rewind(): bool
112
    {
113 55
        return \rewind($this->resource);
114
    }
115
116
    /**
117
     * @return bool
118
     */
119 1
    public function isWritable(): bool
120
    {
121 1
        $metaData = \stream_get_meta_data($this->resource);
122 1
        if (!isset($metaData['uri'])) {
123
            return false;
124
        }
125
126 1
        return \is_writable($metaData['uri']) || $metaData['uri'] === 'php://memory';
127
    }
128
129
    /**
130
     * @param string $string
131
     * @return int
132
     */
133 1
    public function write($string): int
134
    {
135 1
        $written = \fwrite($this->resource, $string);
136 1
        if ($written === false) {
137
            throw new \UnexpectedValueException('Cannot write data to resource');
138
        }
139
140 1
        return $written;
141
    }
142
143
    /**
144
     * @return bool
145
     */
146
    public function isReadable(): bool
147
    {
148
        return true;
149
    }
150
151
    /**
152
     * @param int $length
153
     * @return string
154
     */
155 15
    public function read(int $length): string
156
    {
157 15
        $bytes = \fread($this->resource, $length);
158 15
        if ($bytes === false) {
159
            throw new \UnexpectedValueException('Cannot read from resource');
160
        }
161
162 15
        return $bytes;
163
    }
164
165
    /**
166
     * @return string
167
     */
168 17
    public function getContents(): string
169
    {
170 17
        $contents = \stream_get_contents($this->resource);
171 17
        if ($contents === false) {
172
            throw new \UnexpectedValueException('Cannot read contents from resource');
173
        }
174
175 17
        return $contents;
176
    }
177
178
    /**
179
     * @param array<int, string> $keys
180
     * @return array<string, mixed>
0 ignored issues
show
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (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...
181
     */
182 43
    public function getMetadata(array $keys = []): array
183
    {
184 43
        $metaData = \stream_get_meta_data($this->resource);
185
186 43
        $keys = \array_map('strtolower', $keys);
187
188 43
        return \array_filter(
189 43
            $metaData,
190
            function ($key) use ($keys) {
191 43
                return \in_array(\strtolower($key), $keys);
192 43
            },
193 43
            ARRAY_FILTER_USE_KEY
194
        );
195
    }
196
}
197