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/Base64DecodedStream.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 Base64DecodedStream implements StreamInterface
9
{
10
    /**
11
     * @var StreamInterface
12
     */
13
    private $decoratedStream;
14
15
    /**
16
     * @var resource
17
     */
18
    private $filter;
19
20
    /**
21
     * @param resource $resource
22
     */
23 13
    public function __construct($resource)
24
    {
25 13
        $this->decoratedStream = new ResourceStream($resource);
26
27 13
        $this->applyFilter();
28 13
    }
29
30
    /**
31
     * @param string $string
32
     * @return Base64DecodedStream
33
     */
34 13
    public static function fromString(string $string): Base64DecodedStream
35
    {
36 13
        $resource = \fopen('php://memory', 'r+');
37 13
        if ($resource === false) {
38
            throw new \UnexpectedValueException('Cannot open php://memory for writing');
39
        }
40
41 13
        \fwrite($resource, $string);
42 13
        return new self($resource);
43
    }
44
    
45 13
    private function applyFilter(): void
46
    {
47 13
        $filter = \stream_filter_prepend(
48 13
            $this->decoratedStream->detach(),
49 13
            'convert.base64-decode',
50 13
            STREAM_FILTER_READ
51
        );
52
53 13
        if ($filter === false) {
54
            throw new \UnexpectedValueException('Cannot append filter to stream');
55
        }
56
57 13
        $this->filter = $filter;
58 13
    }
59
60 7
    private function removeFilter(): void
61
    {
62 7
        if ($this->filter !== null) {
63 7
            \stream_filter_remove($this->filter);
64
        }
65 7
    }
66
67
    /**
68
     * @return string
69
     */
70 4
    public function __toString(): string
71
    {
72 4
        $this->rewind();
73 4
        return $this->decoratedStream->__toString();
74
    }
75
    
76
    public function close(): void
77
    {
78
        $this->decoratedStream->close();
79
    }
80
81
    /**
82
     * @return mixed
83
     */
84
    public function detach()
85
    {
86
        return $this->decoratedStream->detach();
87
    }
88
89
    /**
90
     * @return int|null
91
     */
92 2
    public function getSize(): ?int
93
    {
94 2
        $this->removeFilter();
95 2
        $contents = (string)\preg_replace("/\r\n/", '', (string)$this->decoratedStream->getContents());
96 2
        $lastCharacters = \substr($contents, -2);
97 2
        $this->decoratedStream->rewind();
98 2
        $this->applyFilter();
99
100 2
        $padding = 0;
101 2
        if ($lastCharacters[0] === '=') {
102 1
            $padding++;
103
        }
104 2
        if ($lastCharacters[1] === '=') {
105 2
            $padding++;
106
        }
107
108 2
        return (int) ((\strlen($contents) / 4) * 3) - $padding;
109
    }
110
111
    /**
112
     * @return int
113
     * @throws \RuntimeException
114
     */
115 2
    public function tell(): int
116
    {
117 2
        return $this->decoratedStream->tell();
118
    }
119
120
    /**
121
     * @return bool
122
     */
123
    public function eof(): bool
124
    {
125
        return $this->decoratedStream->eof();
126
    }
127
128
    /**
129
     * @return bool
130
     */
131
    public function isSeekable(): bool
132
    {
133
        return false;
134
    }
135
136
    /**
137
     * @param int $offset
138
     * @param int $whence
139
     * @return int
140
     */
141 2
    public function seek(int $offset, int $whence = SEEK_SET): int
142
    {
143 2
        return -1;
144
    }
145
146
    /**
147
     * @return bool
148
     */
149 6
    public function rewind(): bool
150
    {
151 6
        $this->removeFilter();
152 6
        if (!$this->decoratedStream->rewind()) {
153
            return false;
154
        }
155
156 6
        $this->applyFilter();
157 6
        return true;
158
    }
159
160
    /**
161
     * @return bool
162
     */
163 2
    public function isWritable(): bool
164
    {
165 2
        return false;
166
    }
167
168
    /**
169
     * @param string $string
170
     * @return int
171
     */
172 2
    public function write($string): int
173
    {
174 2
        throw new \RuntimeException('Cannot write to stream');
175
    }
176
177
    /**
178
     * @return bool
179
     */
180
    public function isReadable(): bool
181
    {
182
        return true;
183
    }
184
185
    /**
186
     * @param int $length
187
     * @return string
188
     */
189 2
    public function read(int $length): string
190
    {
191 2
        return $this->decoratedStream->read($length);
192
    }
193
194
    /**
195
     * @return string
196
     */
197 4
    public function getContents(): string
198
    {
199 4
        return $this->decoratedStream->getContents();
200
    }
201
202
    /**
203
     * @param array<int, string> $keys
204
     * @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...
205
     */
206
    public function getMetadata(array $keys = []): array
207
    {
208
        return $this->decoratedStream->getMetadata();
209
    }
210
}
211