Issues (10)

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/phpunit/Unit/HookRegistryTest.php (2 issues)

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
3
namespace SBL\Tests;
4
5
use SBL\HookRegistry;
6
use SBL\Options;
7
use Title;
8
9
/**
10
 * @covers \SBL\HookRegistry
11
 * @group semantic-breadcrumb-links
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 *
16
 * @author mwjames
17
 */
18
class HookRegistryTest extends \PHPUnit_Framework_TestCase {
19
20
	public function testCanConstruct() {
21
22
		$store = $this->getMockBuilder( '\SMW\Store' )
23
			->disableOriginalConstructor()
24
			->getMockForAbstractClass();
25
26
		$options = $this->getMockBuilder( '\SBL\Options' )
27
			->disableOriginalConstructor()
28
			->getMock();
29
30
		$this->assertInstanceOf(
31
			'\SBL\HookRegistry',
32
			new HookRegistry( $store, new $options )
33
		);
34
	}
35
36
	public function testRegister() {
37
38
		$title = Title::newFromText( __METHOD__ );
39
40
		$outputPage = $this->getMockBuilder( '\OutputPage' )
41
			->disableOriginalConstructor()
42
			->getMock();
43
44
		$outputPage->expects( $this->any() )
45
			->method( 'getTitle' )
46
			->will( $this->returnValue( $title ) );
47
48
		$skin = $this->getMockBuilder( '\Skin' )
49
			->disableOriginalConstructor()
50
			->getMock();
51
52
		$skin->expects( $this->any() )
53
			->method( 'getOutput' )
54
			->will( $this->returnValue( $outputPage ) );
55
56
		$store = $this->getMockBuilder( '\SMW\Store' )
57
			->disableOriginalConstructor()
58
			->getMockForAbstractClass();
59
60
		$configuration = [
61
			'useSubpageFinderFallback' => false,
62
			'tryToFindClosestDescendant' => false,
63
			'propertySearchPatternByNamespace' => [],
64
			'breadcrumbTrailStyleClass' => 'foo',
65
			'breadcrumbDividerStyleClass' => 'bar',
66
			'hideSubpageParent' => true,
67
			'enabledSubpageParentAnnotation' => true,
68
			'disableTranslationSubpageAnnotation' => false,
69
			'wgNamespacesWithSubpages' => []
70
		];
71
72
		$instance = new HookRegistry(
73
			$store,
74
			new Options( $configuration )
75
		);
76
77
		$instance->register();
78
79
		$this->doTestInitProperties( $instance );
80
		$this->doTestSkinTemplateOutputPageBeforeExec( $instance, $skin );
81
		$this->doTestBeforePageDisplay( $instance, $outputPage, $skin );
82
		$this->doTestParserAfterTidy( $instance );
83
		$this->doTestParserAfterTidyToBailOutEarly( $instance );
84
		$this->doTestSmwParserBeforeMagicWordsFinder( $instance );
85
		$this->doTestOutputPageParserOutput( $instance, $outputPage );
86
	}
87
88
	private function doTestInitProperties( $instance ) {
89
90
		$handler = 'SMW::Property::initProperties';
91
92
		$propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' )
93
			->disableOriginalConstructor()
94
			->getMock();
95
96
		$this->assertTrue(
97
			$instance->isRegistered( $handler )
98
		);
99
100
		$this->assertThatHookIsExcutable(
101
			$instance->getHandlerFor( $handler ),
102
			[ $propertyRegistry ]
103
		);
104
	}
105
106
	private function doTestSkinTemplateOutputPageBeforeExec( $instance, $skin ) {
107
108
		$handler = 'SkinTemplateOutputPageBeforeExec';
109
110
		$this->assertTrue(
111
			$instance->isRegistered( $handler )
112
		);
113
114
		$template = new \stdClass;
115
116
		$this->assertThatHookIsExcutable(
117
			$instance->getHandlerFor( $handler ),
118
			[ &$skin, &$template ]
119
		);
120
	}
121
122
	private function doTestBeforePageDisplay( $instance, $outputPage, $skin ) {
123
124
		$handler = 'BeforePageDisplay';
125
126
		$this->assertTrue(
127
			$instance->isRegistered( $handler )
128
		);
129
130
		$this->assertThatHookIsExcutable(
131
			$instance->getHandlerFor( $handler ),
132
			[ &$outputPage, &$skin ]
133
		);
134
	}
135
136
	private function doTestParserAfterTidy( $instance ) {
137
138
		$handler = 'ParserAfterTidy';
139
140
		$this->assertTrue(
141
			$instance->isRegistered( $handler )
142
		);
143
144
		$title = Title::newFromText( __METHOD__ );
145
146
		$parserOptions = $this->getMockBuilder( '\ParserOptions' )
147
			->disableOriginalConstructor()
148
			->getMock();
149
150
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
151
			->disableOriginalConstructor()
152
			->getMock();
153
154
		$parser = $this->getMockBuilder( '\Parser' )
155
			->disableOriginalConstructor()
156
			->getMock();
157
158
		$parser->expects( $this->any() )
159
			->method( 'getTitle' )
160
			->will( $this->returnValue( $title ) );
161
162
		$parser->expects( $this->any() )
163
			->method( 'getOptions' )
164
			->will( $this->returnValue( $parserOptions ) );
165
166
		$parser->expects( $this->any() )
167
			->method( 'getOutput' )
168
			->will( $this->returnValue( $parserOutput ) );
169
170
		$text = '';
171
172
		$this->assertThatHookIsExcutable(
173
			$instance->getHandlerFor( $handler ),
174
			[ &$parser, &$text ]
175
		);
176
	}
177
178
	private function doTestParserAfterTidyToBailOutEarly( $instance ) {
179
180
		$handler = 'ParserAfterTidy';
181
182
		$this->assertTrue(
183
			$instance->isRegistered( $handler )
184
		);
185
186
		$title = Title::newFromText( __METHOD__ );
187
188
		$parserOptions = $this->getMockBuilder( '\ParserOptions' )
189
			->disableOriginalConstructor()
190
			->getMock();
191
192
		$parserOptions->expects( $this->any() )
193
			->method( 'getInterfaceMessage' )
194
			->will( $this->returnValue( true ) );
195
196
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
0 ignored issues
show
$parserOutput is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
197
			->disableOriginalConstructor()
198
			->getMock();
199
200
		$parser = $this->getMockBuilder( '\Parser' )
201
			->disableOriginalConstructor()
202
			->getMock();
203
204
		$parser->expects( $this->any() )
205
			->method( 'getTitle' )
206
			->will( $this->returnValue( $title ) );
207
208
		$parser->expects( $this->any() )
209
			->method( 'getOptions' )
210
			->will( $this->returnValue( $parserOptions ) );
211
212
		$text = '';
213
214
		$this->assertThatHookIsExcutable(
215
			$instance->getHandlerFor( $handler ),
216
			[ &$parser, &$text ]
217
		);
218
	}
219
220
	private function doTestSmwParserBeforeMagicWordsFinder( $instance ) {
221
222
		$handler = 'SMW::Parser::BeforeMagicWordsFinder';
223
224
		$this->assertTrue(
225
			$instance->isRegistered( $handler )
226
		);
227
228
		$magicWords = [];
229
230
		$this->assertThatHookIsExcutable(
231
			$instance->getHandlerFor( $handler ),
232
			[ &$magicWords ]
233
		);
234
235
		$this->assertContains(
236
			'SBL_NOBREADCRUMBLINKS',
237
			$magicWords
238
		);
239
	}
240
241
	private function doTestOutputPageParserOutput( $instance, $outputPage ) {
242
243
		$handler = 'OutputPageParserOutput';
244
245
		$this->assertTrue(
246
			$instance->isRegistered( $handler )
247
		);
248
249
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
250
			->disableOriginalConstructor()
251
			->getMock();
252
253
		$magicWords = [];
0 ignored issues
show
$magicWords is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
254
255
		$this->assertThatHookIsExcutable(
256
			$instance->getHandlerFor( $handler ),
257
			[ &$outputPage, $parserOutput ]
258
		);
259
260
		$this->assertEquals(
261
			'',
262
			$outputPage->smwmagicwords
263
		);
264
	}
265
266
	private function assertThatHookIsExcutable( \Closure $handler, $arguments ) {
267
		$this->assertInternalType(
268
			'boolean',
269
			call_user_func_array( $handler, $arguments )
270
		);
271
	}
272
273
}
274