Issues (201)

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.

tests/unit/Model/CommentTest.php (1 issue)

Labels
Severity

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
namespace Redaxscript\Tests\Model;
3
4
use Redaxscript\Db;
5
use Redaxscript\Model;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * CommentTest
10
 *
11
 * @since 4.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Model\Comment
18
 */
19
20
class CommentTest extends TestCaseAbstract
21
{
22
	/**
23
	 * setUp
24
	 *
25
	 * @since 4.0.0
26
	 */
27
28
	public function setUp() : void
29
	{
30
		parent::setUp();
31
		$optionArray = $this->getOptionArray();
32
		$installer = $this->installerFactory();
33
		$installer->init();
34
		$installer->rawCreate();
35
		$installer->insertSettings($optionArray);
36
		$categoryOne = Db::forTablePrefix('categories')->create();
37
		$categoryOne
38
			->set(
39
			[
40
				'title' => 'Category One',
41
				'alias' => 'category-one'
42
			])
43
			->save();
44
		$articleOne = Db::forTablePrefix('articles')->create();
45
		$articleOne
46
			->set(
47
			[
48
				'title' => 'Article One',
49
				'alias' => 'article-one',
50
				'category' => $categoryOne->id
51
			])
52
			->save();
53
		$articleTwo = Db::forTablePrefix('articles')->create();
54
		$articleTwo
55
			->set(
56
			[
57
				'title' => 'Article Two',
58
				'alias' => 'article-two'
59
			])
60
			->save();
61
		Db::forTablePrefix('comments')
62
			->create()
63
			->set(
64
			[
65
				'author' => 'Comment One',
66
				'text' => 'Comment One',
67
				'article' => $articleOne->id
68
			])
69
			->save();
70
		Db::forTablePrefix('comments')
71
			->create()
72
			->set(
73
			[
74
				'author' => 'Comment Two',
75
				'text' => 'Comment Two',
76
				'article' => $articleTwo->id
77
			])
78
			->save();
79
		Db::forTablePrefix('comments')
80
			->create()
81
			->set(
82
			[
83
				'author' => 'Comment Three',
84
				'text' => 'Comment Three',
85
				'language' => 'en',
86
				'article' => $articleTwo->id
87
			])
88
			->save();
89
		Db::forTablePrefix('comments')
90
			->create()
91
			->set(
92
			[
93
				'author' => 'Comment Four',
94
				'text' => 'Comment Four',
95
				'language' => 'de',
96
				'article' => $articleTwo->id
97
			])
98
			->save();
99
	}
100
101
	/**
102
	 * tearDown
103
	 *
104
	 * @since 4.0.0
105
	 */
106
107
	public function tearDown() : void
108
	{
109
		$this->dropDatabase();
110
	}
111
112
	/**
113
	 * testCountByArticleAndLanguage
114
	 *
115
	 * @since 4.0.0
116
	 *
117
	 * @param int $articleId
118
	 * @param string $language
119
	 * @param int $expect
120
	 *
121
	 * @dataProvider providerAutoloader
122
	 */
123
124
	public function testCountByArticleAndLanguage(int $articleId = null, string $language = null, int $expect = null) : void
125
	{
126
		/* setup */
127
128
		$commentModel = new Model\Comment();
129
130
		/* actual */
131
132
		$actual = $commentModel->countByArticleAndLanguage($articleId, $language);
133
134
		/* compare */
135
136
		$this->assertEquals($expect, $actual);
137
	}
138
139
	/**
140
	 * testGetByArticleAndLanguageAndOrderAndStep
141
	 *
142
	 * @since 4.0.0
143
	 *
144
	 * @param int|null $articleId
145
	 * @param string|null $language
146
	 * @param string|null $orderColumn
147
	 * @param int|null $limitStep
148
	 * @param array $expectArray
149
	 *
150
	 * @dataProvider providerAutoloader
151
	 */
152
153
	public function testGetByArticleAndLanguageAndOrderAndStep(int $articleId = null, string $language = null, string $orderColumn = null, int $limitStep = null, array $expectArray = []) : void
154
	{
155
		/* setup */
156
157
		$commentModel = new Model\Comment();
158
		$setting = $this->settingFactory();
159
		$setting->set('limit', 1);
160
161
		/* actual */
162
163
		$actualArray = [];
164
		$actualObject = $commentModel->getByArticleAndLanguageAndOrderAndStep($articleId, $language, $orderColumn, $limitStep);
165
166
		/* process comments */
167
168
		foreach ($actualObject as $value)
0 ignored issues
show
The expression $actualObject of type object|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
169
		{
170
			$actualArray[] = $value->author;
171
		}
172
173
		/* compare */
174
175
		$this->assertEquals($expectArray, $actualArray);
176
	}
177
178
	/**
179
	 * testGetRouteById
180
	 *
181
	 * @since 4.0.0
182
	 *
183
	 * @param int $commentId
184
	 * @param string $expect
185
	 *
186
	 * @dataProvider providerAutoloader
187
	 */
188
189
	public function testGetRouteById(int $commentId = null, string $expect = null) : void
190
	{
191
		/* setup */
192
193
		$commentModel = new Model\Comment();
194
195
		/* actual */
196
197
		$actual = $commentModel->getRouteById($commentId);
198
199
		/* compare */
200
201
		$this->assertEquals($expect, $actual);
202
	}
203
204
	/**
205
	 * testCreateByArray
206
	 *
207
	 * @since 4.0.0
208
	 *
209
	 * @param array $createArray
210
	 * @param bool $expect
211
	 *
212
	 * @dataProvider providerAutoloader
213
	 */
214
215
	public function testCreateByArray(array $createArray = [], bool $expect = null) : void
216
	{
217
		/* setup */
218
219
		$commentModel = new Model\Comment();
220
221
		/* actual */
222
223
		$actual = $commentModel->createByArray($createArray);
224
225
		/* compare */
226
227
		$this->assertEquals($expect, $actual);
228
	}
229
}
230