Issues (337)

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/component/Html/Head.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 Rudolf\Component\Html;
4
5
class Head
6
{
7
    use DocumentPart;
8
9
    /**
10
     * @var string
11
     */
12
    private $pageTitle;
13
14
    /**
15
     * @var string
16
     */
17
    private $pageCharset;
18
19
    /**
20
     * @var array
21
     */
22
    private $pageStylesheets = [];
23
24
    /**
25
     * @var string
26
     */
27
    private $pageFavicon;
28
29
    /**
30
     * @var string
31
     */
32
    private $canonical;
33
34
    /**
35
     * Make all elements inside <head>.
36
     *
37
     * @param bool $return
38
     * @param int $nesting
39
     * @return string|array|null
40
     */
41
    public function make($return = false, $nesting = 1)
42
    {
43
        $html = [];
44
45
        $html[] = $this->before(true);
46
        $html[] = sprintf('<meta charset="%1$s">', $this->charset(true));
47
        $html[] = sprintf('<title>%1$s</title>', $this->title(true));
48
        $html[] = $this->stylesheets(true, $nesting);
49
        $html[] = $this->scripts(true, $nesting);
50
        $html[] = $this->favicon(true);
51
        $html[] = $this->canonical(true);
52
        $html[] = $this->after(true);
53
54
        // trimmmmmmmmmmmmm
55
        foreach ($html as $key => $value) {
56
            $html[$key] = trim($value);
57
        }
58
59
        $html = implode("\n".str_repeat("\t", $nesting), array_filter($html)).PHP_EOL;
60
61
        if (false === $return) {
62
            echo $html;
63
            return null;
64
        }
65
66
        return $html;
67
    }
68
69
    /**
70
     * Get page title.
71
     *
72
     * @param bool $return
73
     *
74
     * @return string
75
     */
76
    public function title($return = false)
77
    {
78
        $title = trim($this->pageTitle.' | '.GENERAL_SITE_NAME, ' | ');
79
        $title = strip_tags($title);
80
81
        if (false === $return) {
82
            echo $title;
83
            return null;
84
        }
85
86
        return $title;
87
    }
88
89
    public function setTitle($title)
90
    {
91
        $this->pageTitle = $title;
92
    }
93
94
    /**
95
     * Get page charset.
96
     *
97
     * @param bool $return
98
     *
99
     * @return string
100
     */
101
    public function charset($return = false)
102
    {
103
        $charset = empty($this->pageCharset) ? 'utf-8' : $this->pageCharset;
104
105
        if (false === $return) {
106
            echo $charset;
107
            return null;
108
        }
109
110
        return $charset;
111
    }
112
113
    public function setCharset($pageCharset)
114
    {
115
        $this->pageCharset = $pageCharset;
116
    }
117
118
    /**
119
     * Get favicon links.
120
     *
121
     * @param bool $return
122
     *
123
     * @return string
124
     */
125
    public function favicon($return = false)
126
    {
127
        if (empty($this->pageFavicon)) {
128
            return false;
129
        }
130
131
        $link = sprintf('<link rel="shortcut icon" href="%1$s">', $this->pageFavicon);
132
133
        if (true === $return) {
134
            echo $link;
135
            return null;
136
        }
137
138
        return $link;
139
    }
140
141
    /**
142
     * Set page favicon.
143
     *
144
     * @param string $favicon Favicon location
145
     */
146
    public function setFavicon($favicon)
147
    {
148
        $this->pageFavicon = $favicon;
149
    }
150
151
    /**
152
     * Get canonical link.
153
     *
154
     * @param bool $return
155
     *
156
     * @return string
157
     */
158
    public function canonical($return = false)
159
    {
160
        if (empty($this->canonical)) {
161
            return false;
162
        }
163
164
        $canonical = sprintf(
165
            '<link rel="canonical" href="%1$s">',
166
            (new Url())->getOrigin().$this->canonical
167
        );
168
169
        if (false === $return) {
170
            echo $canonical;
171
            return null;
172
        }
173
174
        return $canonical;
175
    }
176
177
    /**
178
     * Set canonical link.
179
     *
180
     * @param string $href
181
     */
182
    public function setCanonical($href)
183
    {
184
        $this->canonical = $href;
185
    }
186
187
    /**
188
     * Get stylesheets links.
189
     *
190
     * @param bool $return
191
     * @param int  $nesting
192
     *
193
     * @return string
194
     */
195 View Code Duplication
    public function stylesheets($return = false, $nesting = 1)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
196
    {
197
        if (empty($this->pageStylesheets)) {
198
            return false;
199
        }
200
201
        $html = [];
202
203
        foreach ($this->pageStylesheets as $key => $value) {
204
            $html[] = sprintf('<link rel="stylesheet" href="%1$s">', $value);
205
        }
206
207
        $html = implode("\n".str_repeat("\t", $nesting), $html).PHP_EOL;
208
209
        if (false === $return) {
210
            echo $html;
211
            return null;
212
        }
213
214
        return $html;
215
    }
216
217
    /**
218
     * Get stylesheet array.
219
     *
220
     * @return array
221
     */
222
    public function getStylesheetsArray()
223
    {
224
        return $this->pageStylesheets;
225
    }
226
227
    /**
228
     * Set page stylesheet.
229
     *
230
     * @param string $href    Stylesheet location
231
     * @param string $version Version
232
     */
233
    public function setStylesheet($href, $version = '')
234
    {
235
        if ($version) {
236
            $href .= '?v='.$version;
237
        }
238
239
        $this->pageStylesheets[] = $href;
240
    }
241
    public function setStylesheetsArray($array)
242
    {
243
        //$this->pageStylesheets = array_merge($this->pageStylesheets, $array);
244
        $this->pageStylesheets = $array;
245
    }
246
}
247