Issues (3)

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/Notify.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 Yoeunes\Notify;
4
5
use Illuminate\Config\Repository;
6
use Illuminate\Session\SessionManager;
7
use function in_array;
8
use RuntimeException;
9
use Yoeunes\Notify\Notifiers\NotifierInterface;
10
11
class Notify
12
{
13
    const NOTIFICATIONS_NAMESPACE = 'notify::notifications';
14
15
    /**
16
     * Added notifications.
17
     *
18
     * @var array
19
     */
20
    protected $notifications = [];
21
22
    /**
23
     * Illuminate Session.
24
     *
25
     * @var \Illuminate\Session\SessionManager
26
     */
27
    protected $session;
28
29
    /**
30
     * Notification config.
31
     *
32
     * @var \Illuminate\Config\Repository
33
     */
34
    protected $config;
35
36
    /** @var NotifyInterface */
37
    protected $notifier;
38
39
    /**
40
     * Notification constructor.
41
     *
42
     * @param NotifierInterface $notifier
43
     * @param SessionManager $session
44
     * @param Repository $config
45
     */
46
    public function __construct(NotifierInterface $notifier, SessionManager $session, Repository $config)
47
    {
48
        $this->notifier = $notifier;
0 ignored issues
show
Documentation Bug introduced by
It seems like $notifier of type object<Yoeunes\Notify\No...iers\NotifierInterface> is incompatible with the declared type object<Yoeunes\Notify\NotifyInterface> of property $notifier.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
50
        $this->session = $session;
51
52
        $this->config = $config;
53
54
        $this->notifications = $this->session->get(self::NOTIFICATIONS_NAMESPACE, []);
55
    }
56
57
    /**
58
     * Add a notification.
59
     *
60
     * @param string $type    Could be error, info, success, or warning.
61
     * @param string $message The notification's message
62
     * @param string $title   The notification's title
63
     * @param array $options
64
     *
65
     * @return self
66
     */
67
    public function addNotification(string $type, string $message, string $title = '', array $options = []): self
68
    {
69
        if (!in_array($type, $this->notifier->getAllowedTypes(), true)) {
70
            throw new RuntimeException('Invalid type "'.$type.'" for the "'.$this->notifier->getName().'"');
71
        }
72
73
        $this->notifications[] = [
74
            'type'    => $type,
75
            'title'   => $this->escapeSingleQuote($title),
76
            'message' => $this->escapeSingleQuote($message),
77
            'options' => json_encode($options),
78
        ];
79
80
        $this->session->flash(self::NOTIFICATIONS_NAMESPACE, $this->notifications);
81
82
        return $this;
83
    }
84
85
    /**
86
     * helper function to escape single quote for example for french words.
87
     *
88
     * @param string $value
89
     *
90
     * @return string
91
     */
92
    private function escapeSingleQuote(string $value): string
93
    {
94
        return str_replace("'", "\\'", $value);
95
    }
96
97
    /**
98
     * Render the notifications' script tag.
99
     *
100
     * @return string
101
     */
102
    public function render(): string
103
    {
104
        $notification = $this->notifier->render($this->notifications);
105
106
        $this->session->forget(self::NOTIFICATIONS_NAMESPACE);
107
108
        return $notification;
109
    }
110
111
    /**
112
     * Clear all notifications.
113
     *
114
     * @return self
115
     */
116
    public function clear(): self
117
    {
118
        $this->notifications = [];
119
120
        $this->session->forget(self::NOTIFICATIONS_NAMESPACE);
121
122
        return $this;
123
    }
124
125
    /**
126
     * @param $method
127
     * @param $arguments
128
     */
129
    public function __call($method, $arguments)
130
    {
131
        if (!in_array($method, $this->notifier->getAllowedTypes(), true)) {
132
            throw new RuntimeException('Invalid type "'.$method.'" for the "'.$this->notifier->getName().'"');
133
        }
134
135
        $this->addNotification($method, ...$arguments);
136
    }
137
}
138