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/Mime/GenericPart.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\Mime;
5
6
use Genkgo\Mail\HeaderInterface;
7
use Genkgo\Mail\MessageInterface;
8
use Genkgo\Mail\Stream\EmptyStream;
9
use Genkgo\Mail\StreamInterface;
10
11
final class GenericPart implements PartInterface
12
{
13
    private const ALLOWED_HEADERS = [
14
        'content-type' => true,
15
        'content-transfer-encoding' => true,
16
        'content-id' => true,
17
        'content-disposition' => true,
18
        'content-description' => true,
19
        'content-location' => true,
20
        'content-language' => true,
21
    ];
22
23
    /**
24
     * @var array|HeaderInterface[]
25
     */
26
    private $headers = [];
27
28
    /**
29
     * @var StreamInterface
30
     */
31
    private $body;
32
    
33 78
    public function __construct()
34
    {
35 78
        $this->body = new EmptyStream();
36 78
    }
37
38
    /**
39
     * @return iterable<HeaderInterface>
0 ignored issues
show
The doc-type iterable<HeaderInterface> could not be parsed: Expected "|" or "end of type", but got "<" at position 8. (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...
40
     */
41 31
    public function getHeaders(): iterable
42
    {
43 31
        return $this->headers;
44
    }
45
46
    /**
47
     * @param string $name
48
     * @return bool
49
     */
50 29
    public function hasHeader(string $name): bool
51
    {
52 29
        $name = \strtolower($name);
53
54 29
        return isset($this->headers[$name]);
55
    }
56
57
    /**
58
     * @param string $name
59
     * @return HeaderInterface
60
     */
61 51
    public function getHeader(string $name): HeaderInterface
62
    {
63 51
        $name = \strtolower($name);
64
65 51
        if (!isset($this->headers[$name])) {
66 17
            throw new \UnexpectedValueException('No header with name ' . $name);
67
        }
68
69 50
        return $this->headers[$name];
70
    }
71
72
    /**
73
     * @param HeaderInterface $header
74
     * @return PartInterface
75
     */
76 78
    public function withHeader(HeaderInterface $header): PartInterface
77
    {
78 78
        $name = \strtolower((string)$header->getName());
79 78
        $this->assertValidHeader($name);
80
81 77
        $clone = clone $this;
82 77
        $clone->headers[$name] = $header;
83 77
        return $clone;
84
    }
85
86
    /**
87
     * @param string $name
88
     * @return PartInterface
89
     */
90 7
    public function withoutHeader(string $name): PartInterface
91
    {
92 7
        $name = \strtolower($name);
93
94 7
        $clone = clone $this;
95 7
        unset($clone->headers[$name]);
96 7
        return $clone;
97
    }
98
99
    /**
100
     * @param StreamInterface $body
101
     * @return PartInterface
102
     */
103 63
    public function withBody(StreamInterface $body): PartInterface
104
    {
105 63
        $clone = clone $this;
106 63
        $clone->body = $body;
107 63
        return $clone;
108
    }
109
110
    /**
111
     * @return StreamInterface
112
     */
113 42
    public function getBody(): StreamInterface
114
    {
115 42
        return $this->body;
116
    }
117
118
    /**
119
     * @param string $name
120
     */
121 78
    private function assertValidHeader(string $name): void
122
    {
123 78
        if (!isset(self::ALLOWED_HEADERS[$name])) {
124 1
            throw new \InvalidArgumentException('Invalid Mime part header ' . $name);
125
        }
126 77
    }
127
128
    /**
129
     * @param MessageInterface $message
130
     * @return GenericPart
131
     */
132 18
    public static function fromMessage(MessageInterface $message): self
133
    {
134 18
        $part = new self();
135 18
        foreach ($message->getHeaders() as $headers) {
136 18
            foreach ($headers as $header) {
137 18
                $headerName = \strtolower((string)$header->getName());
138 18
                if (isset(self::ALLOWED_HEADERS[$headerName])) {
139 18
                    $part->headers[$headerName] = $header;
140
                }
141
            }
142
        }
143
144 18
        $part->body = $message->getBody();
145 18
        return $part;
146
    }
147
}
148