Issues (20)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Points.php (1 issue)

1
<?php
2
3
namespace PhpEarth\Stats;
4
5
use PhpEarth\Stats\Model\Topic;
6
use PhpEarth\Stats\Model\Comment;
7
use PhpEarth\Stats\Model\Reply;
8
use PhpEarth\Stats\Util\CodeDetector;
9
10
/**
11
 * Class Points.
12
 */
13
class Points
14
{
15
    /**
16
     * @var ExpressionLanguage
17
     */
18
    private $language;
19
20
    /**
21
     * @var CodeDetector
22
     */
23
    private $codeDetector;
24
25
    /**
26
     * @var array
27
     */
28
    private $points;
29
30
    /**
31
     * @var array
32
     */
33
    private $admins;
34
35
    /**
36
     * @var array
37
     */
38
    private $offensiveWords;
39
40
    /**
41
     * Points constructor.
42
     */
43
    public function __construct()
44
    {
45
        $this->language = new ExpressionLanguage();
46
        $this->codeDetector = new CodeDetector();
47
    }
48
49
    /**
50
     * Set points configuration values.
51
     *
52
     * @param array $points
53
     */
54
    public function setPoints($points)
55
    {
56
        $this->points = $points;
57
        $this->codeDetector->setPatterns($points['code_regex']);
58
        $this->codeDetector->setMinCodeLines($points['min_code_lines']);
59
    }
60
61
    /**
62
     * Set admins from configuration values.
63
     *
64
     * @param array $admins
65
     */
66
    public function setAdmins($admins)
67
    {
68
        $this->admins = $admins;
69
    }
70
71
    /**
72
     * Set offensive words.
73
     *
74
     * @param array $offensiveWords
75
     */
76
    public function setOffensiveWords($offensiveWords)
77
    {
78
        $this->offensiveWords = $offensiveWords;
79
    }
80
81
    /**
82
     * Add points based on creating a topic.
83
     *
84
     * @param Topic $topic
85
     *
86
     * @return int
87
     */
88
    public function addPointsForTopic(Topic $topic)
89
    {
90
        // Add points for creating a topic
91
        $points = $this->points['topic'];
92
93
        // Add points based on the topic reactions
94
        $points += $this->language->evaluate($this->points['topic_reactions'], ['topic' => $topic]);
95
96
        // Add points for using recommended links
97
        $points += $this->addPointsForLinks($topic->getMessage());
98
99
        // Set points for only photo shares
100
        $points = $this->language->evaluate($this->points['image'], ['topic' => $topic, 'points' => $points]);
101
102
        // Set points if topic is closed for comments
103
        $points = $this->language->evaluate($this->points['closed_topic'], ['topic' => $topic, 'points' => $points]);
104
105
        // Set points if message contains code
106
        $points = $this->language->evaluate($this->points['code'], ['codeDetector' => $this->codeDetector, 'message' => $topic->getMessage(), 'points' => $points]);
107
108
        // Remove points for using offensive words
109
        $points += $this->getOffensivePoints($topic->getMessage());
110
111
        // Add points for special admin topics
112
        $points += $this->language->evaluate($this->points['admin_topic'], ['topic' => $topic, 'admins' => $this->admins]);
113
114
        return $points;
115
    }
116
117
    /**
118
     * Add points based on comment.
119
     *
120
     * @param Comment $comment
121
     *
122
     * @return int
123
     */
124 View Code Duplication
    public function addPointsForComment(Comment $comment)
125
    {
126
        $points = $this->points['comment'];
127
        $points += $this->language->evaluate($this->points['comment_reactions'], ['comment' => $comment]);
128
        $points += $this->getPointsForMessageLength($comment->getMessage());
129
130
        // Add points for using recommended links
131
        $points += $this->addPointsForLinks($comment->getMessage());
132
133
        // Set points if message contains code
134
        $points = $this->language->evaluate($this->points['code'], ['codeDetector' => $this->codeDetector, 'message' => $comment->getMessage(), 'points' => $points]);
135
136
        // Remove points for using offensive words
137
        $points += $this->getOffensivePoints($comment->getMessage());
138
139
        return $points;
140
    }
141
142
    /**
143
     * Add points based on reply.
144
     *
145
     * @param Reply $reply
146
     *
147
     * @return int
148
     */
149 View Code Duplication
    public function addPointsForReply(Reply $reply)
150
    {
151
        $points = $this->points['reply'];
152
        $points += $this->language->evaluate($this->points['comment_reactions'], ['comment' => $reply]);
153
        $points += $this->getPointsForMessageLength($reply->getMessage());
154
155
        // Add points for using recommended links
156
        $points += $this->addPointsForLinks($reply->getMessage());
157
158
        // Set points if message contains code
159
        $points = $this->language->evaluate($this->points['code'], ['codeDetector' => $this->codeDetector, 'message' => $reply->getMessage(), 'points' => $points]);
160
161
        // Remove points for using offensive words
162
        $points += $this->getOffensivePoints($reply->getMessage());
163
164
        return $points;
165
    }
166
167
    /**
168
     * Add points for attaching recommended links.
169
     *
170
     * @param string $message
171
     *
172
     * @return int
173
     */
174
    private function addPointsForLinks($message)
175
    {
176
        $positivePoints = 0;
177
        $negativePoints = 0;
178
179
        if (isset($message)) {
180
            foreach ($this->points['urls'] as $url) {
181
                if (false !== stripos($message, $url[0])) {
182
                    $positivePoints = ($url[1] > 0 && $positivePoints < $url[1]) ? $positivePoints : $url[1];
183
                    $negativePoints = ($url[1] <= 0 && $negativePoints > $url[1]) ? $negativePoints : $url[1];
184
                }
185
            }
186
        }
187
188
        return $positivePoints + $negativePoints;
189
    }
190
191
    /**
192
     * Remove points for using offensive and inappropriate keywords.
193
     *
194
     * @param string $message
195
     *
196
     * @return int
197
     */
198
    private function getOffensivePoints($message)
199
    {
200
        $points = 0;
201
        if (isset($message)) {
202
            foreach ($this->offensiveWords as $keyword) {
203
                if (false !== stripos($message, str_rot13($keyword[0]))) {
204
                    $points = ($points < $keyword[1]) ? $points : $keyword[1];
205
                }
206
            }
207
        }
208
209
        return $points;
210
    }
211
212
    /**
213
     * Get points based on message length
214
     *
215
     * @param $message
216
     *
217
     * @return int
218
     */
219
    private function getPointsForMessageLength($message)
220
    {
221
        return $this->language->evaluate($this->points['message_length'], ['message' => $message]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->language->...'message' => $message)) returns the type string which is incompatible with the documented return type integer.
Loading history...
222
    }
223
}
224