Issues (1401)

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.

client/includes/Hooks/SidebarHookHandler.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
3
declare( strict_types = 1 );
4
5
namespace Wikibase\Client\Hooks;
6
7
use MediaWiki\Hook\OutputPageParserOutputHook;
8
use MediaWiki\Hook\SidebarBeforeOutputHook;
9
use MediaWiki\Hook\SkinTemplateGetLanguageLinkHook;
10
use OutputPage;
11
use ParserOutput;
12
use Skin;
13
use Title;
14
use Wikibase\Client\ClientHooks;
15
use Wikibase\Client\NamespaceChecker;
16
use Wikibase\Client\WikibaseClient;
17
18
/**
19
 * Handler for ParserOutput-related hooks.
20
 *
21
 * @license GPL-2.0-or-later
22
 */
23
class SidebarHookHandler implements
24
	OutputPageParserOutputHook,
25
	SkinTemplateGetLanguageLinkHook,
26
	SidebarBeforeOutputHook
27
{
28
29
	/**
30
	 * @var NamespaceChecker
31
	 */
32
	private $namespaceChecker;
33
34
	/**
35
	 * @var LanguageLinkBadgeDisplay
36
	 */
37
	private $badgeDisplay;
38
39
	public function __construct(
40
		NamespaceChecker $namespaceChecker,
41
		LanguageLinkBadgeDisplay $badgeDisplay
42
	) {
43
		$this->namespaceChecker = $namespaceChecker;
44
		$this->badgeDisplay = $badgeDisplay;
45
	}
46
47
	public static function factory(): self {
48
		$wikibaseClient = WikibaseClient::getDefaultInstance();
49
50
		return new self(
51
			$wikibaseClient->getNamespaceChecker(),
52
			$wikibaseClient->getLanguageLinkBadgeDisplay()
53
		);
54
	}
55
56
	/**
57
	 * Add output page property if repo links are suppressed, and property for item id
58
	 *
59
	 * @param OutputPage $out
60
	 * @param ParserOutput $parserOutput
61
	 */
62
	public function onOutputPageParserOutput( $out, $parserOutput ): void {
63
		$title = $out->getTitle();
64
		if ( !$title || !$this->namespaceChecker->isWikibaseEnabled( $title->getNamespace() ) ) {
65
			// shorten out
66
			return;
67
		}
68
69
		$noExternalLangLinks = NoLangLinkHandler::getNoExternalLangLinks( $parserOutput );
70
71
		if ( !empty( $noExternalLangLinks ) ) {
72
			$out->setProperty( 'noexternallanglinks', $noExternalLangLinks );
73
		}
74
75
		$itemId = $parserOutput->getProperty( 'wikibase_item' );
76
77
		if ( $itemId !== false ) {
78
			$out->setProperty( 'wikibase_item', $itemId );
79
		}
80
81
		$otherProjects = $parserOutput->getExtensionData( 'wikibase-otherprojects-sidebar' );
82
83
		if ( $otherProjects !== null ) {
84
			$out->setProperty( 'wikibase-otherprojects-sidebar', $otherProjects );
85
		}
86
87
		$badges = $parserOutput->getExtensionData( 'wikibase_badges' );
88
89
		if ( $badges !== null ) {
90
			$out->setProperty( 'wikibase_badges', $badges );
91
		}
92
	}
93
94
	/**
95
	 * Add badges to the language links.
96
	 *
97
	 * @param array &$languageLink
98
	 * @param Title $languageLinkTitle
99
	 * @param Title $title
100
	 * @param OutputPage|null $output
101
	 */
102
	public function onSkinTemplateGetLanguageLink(
103
		&$languageLink,
104
		$languageLinkTitle,
105
		$title,
106
		$output
107
	): void {
108
		$this->badgeDisplay->applyBadges( $languageLink, $languageLinkTitle, $output );
0 ignored issues
show
It seems like $output defined by parameter $output on line 106 can be null; however, Wikibase\Client\Hooks\La...eDisplay::applyBadges() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
109
	}
110
111
	/**
112
	 * SidebarBeforeOutput hook handler
113
	 *
114
	 * This handler adds too items to the sidebar section.
115
	 * First it adds the 'Wikidata items' to the 'toolbox' section of the sidebar.
116
	 * Second it adds the 'In other projects' item which lives in its own section.
117
	 *
118
	 * The items generation logic are handled separately for each. This callback
119
	 * is only concerned with adding them to the &$sidebar array (if they exist).
120
	 *
121
	 * If current page cannot have 'Wikidata item' link, this callback will receive
122
	 * null value from ClientHooks::buildWikidataItemLink() method and so it will
123
	 * skip attempting to add the link. Same thing repeats for the second case.
124
	 *
125
	 * @param Skin $skin
126
	 * @param array &$sidebar
127
	 */
128
	public function onSidebarBeforeOutput( $skin, &$sidebar ): void {
129
		// Add 'Wikidata item' to the toolbox
130
		$wikidataItemLink = ClientHooks::buildWikidataItemLink( $skin );
131
132
		if ( $wikidataItemLink !== null ) {
133
			$sidebar['TOOLBOX']['wikibase'] = $wikidataItemLink;
134
		}
135
136
		// Add the 'In other projects' section
137
		$otherProjectsSidebar = $this->buildOtherProjectsSidebar( $skin );
138
139
		if ( $otherProjectsSidebar !== null ) {
140
			$sidebar['wikibase-otherprojects'] = $otherProjectsSidebar;
141
		}
142
	}
143
144
	/**
145
	 * Build 'In other projects' section of the sidebar, if enabled project wide or
146
	 * the user has the beta featured enabled.
147
	 *
148
	 * @param Skin $skin
149
	 *
150
	 * @return null|array[] Array of 'In other projects' contents or null if there are none
151
	 */
152
	public function buildOtherProjectsSidebar( Skin $skin ): ?array {
153
		$outputPage = $skin->getContext()->getOutput();
154
155
		$otherProjectsSidebar = $outputPage->getProperty( 'wikibase-otherprojects-sidebar' );
156
157
		if ( empty( $otherProjectsSidebar ) ) {
158
			return null;
159
		}
160
161
		return $otherProjectsSidebar;
162
	}
163
164
}
165