Issues (21)

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/Metas/MetaBase.php (2 issues)

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 SocialLinks\Metas;
4
5
use SocialLinks\Page;
6
use ArrayObject;
7
8
/**
9
 * Base class extended by all metas.
10
 */
11
abstract class MetaBase extends ArrayObject
12
{
13
    const META_ATTRIBUTE_NAME = 'name';
14
    const META_NAME_PREFIX = '';
15
16
    protected $page;
17
    protected static $characterLimits = array();
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param Page $page
23
     */
24
    public function __construct(Page $page)
25
    {
26
        $this->page = $page;
27
        $this->generateTags();
28
    }
29
30
    /**
31
     * Convert all tags to html
32
     *
33
     * @return string
34
     */
35
    public function __toString()
36
    {
37
        $html = [];
38
39
        foreach ($this as $tag) {
40
            if (is_array($tag)) {
41
                $html = array_merge($html, $tag);
42
            } else {
43
                $html[] = $tag;
44
            }
45
        }
46
47
        return implode("\n", $html);
48
    }
49
50
    /**
51
     * Generate all tags.
52
     *
53
     * @return array
54
     */
55
    abstract protected function generateTags();
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 View Code Duplication
    public function addMeta($name, $content)
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...
61
    {
62
        if (is_array($content)) {
63
            $content = array_map(function ($content) use ($name) {
64
                return static::getHtmlMeta($name, $content);
65
            }, array_filter($content));
66
67
            if (empty($content)) {
68
                return;
69
            }
70
        } elseif (!empty($content)) {
71
            $content = static::getHtmlMeta($name, $content);
72
        } else {
73
            return;
74
        }
75
76
        $this[$name] = $content;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 View Code Duplication
    public function addLink($rel, $href)
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...
83
    {
84
        if (is_array($href)) {
85
            $href = array_map(function ($href) use ($rel) {
86
                return static::getHtmlLink($rel, $href);
87
            }, array_filter($href));
88
89
            if (empty($href)) {
90
                return;
91
            }
92
        } elseif (!empty($href)) {
93
            $href = static::getHtmlLink($rel, $href);
94
        } else {
95
            return;
96
        }
97
98
        $this[$rel] = $href;
99
    }
100
101
    /**
102
     * Adds an array of metas.
103
     * 
104
     * @param array $metas
105
     */
106
    protected function addMetas(array $metas)
107
    {
108
        foreach ($metas as $name => $content) {
109
            if (!empty($content)) {
110
                $this->addMeta($name, $content);
111
            }
112
        }
113
    }
114
115
    /**
116
     * Adds an array of links.
117
     * 
118
     * @param array $links
119
     */
120
    protected function addLinks(array $links)
121
    {
122
        foreach ($links as $rel => $href) {
123
            if (!empty($href)) {
124
                $this->addLink($rel, $href);
125
            }
126
        }
127
    }
128
129
    /**
130
     * Escapes the value of an attribute.
131
     *
132
     * @param string $value
133
     *
134
     * @return string
135
     */
136
    protected static function escape($value)
137
    {
138
        return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
139
    }
140
141
    /**
142
     * Generates the html code of a link
143
     *
144
     * @param string $rel
145
     * @param string $href
146
     */
147
    protected static function getHtmlLink($rel, $href)
148
    {
149
        return '<link rel="'.static::escape($rel).'" href="'.static::escape($href).'">';
150
    }
151
152
    /**
153
     * Generates the html code of a meta
154
     *
155
     * @param string $name
156
     * @param string $content
157
     */
158
    protected static function getHtmlMeta($name, $content)
159
    {
160
        $content = static::trim($name, $content);
161
162
        return '<meta '.static::META_ATTRIBUTE_NAME.'="'.static::META_NAME_PREFIX.static::escape($name).'" content="'.static::escape($content).'">';
163
    }
164
165
    /**
166
     * Filters attribute values to trim by length.
167
     *
168
     * @param string $name
169
     * @param string $content
170
     *
171
     * @return string
172
     */
173
    protected static function trim($name, $content)
174
    {
175
        $limit = isset(static::$characterLimits[$name]) ? static::$characterLimits[$name] : null;
176
177
        if ($limit && mb_strlen($content) > $limit) {
178
            $content = mb_substr($content, 0, $limit - 3).'...';
179
        }
180
181
        return $content;
182
    }
183
}
184