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.

repo/includes/Rdf/SiteLinksRdfBuilder.php (2 issues)

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
namespace Wikibase\Repo\Rdf;
4
5
use SiteList;
6
use Wikibase\DataModel\Entity\EntityDocument;
7
use Wikibase\DataModel\Entity\Item;
8
use Wikibase\DataModel\SiteLink;
9
use Wikimedia\Purtle\RdfWriter;
10
11
/**
12
 * RDF mapping for entity SiteLinks.
13
 *
14
 * @license GPL-2.0-or-later
15
 */
16
class SiteLinksRdfBuilder implements EntityRdfBuilder {
17
18
	/**
19
	 * @var RdfVocabulary
20
	 */
21
	private $vocabulary;
22
23
	/**
24
	 * @var RdfWriter
25
	 */
26
	private $writer;
27
28
	/**
29
	 * @var SiteList
30
	 */
31
	private $siteLookup;
32
33
	/**
34
	 * @var string[]|null a list of desired sites, or null for all sites.
35
	 */
36
	private $sites;
37
38
	/**
39
	 * @var DedupeBag
40
	 */
41
	private $dedupeBag;
42
43
	/**
44
	 * @param RdfVocabulary $vocabulary
45
	 * @param RdfWriter $writer
46
	 * @param SiteList $siteLookup
47
	 * @param string[]|null $sites
48
	 */
49
	public function __construct( RdfVocabulary $vocabulary, RdfWriter $writer, SiteList $siteLookup, array $sites = null ) {
50
		$this->vocabulary = $vocabulary;
51
		$this->writer = $writer;
52
		$this->siteLookup = $siteLookup;
53
		$this->sites = $sites === null ? null : array_flip( $sites );
54
		$this->dedupeBag = new NullDedupeBag();
55
	}
56
57
	public function setDedupeBag( DedupeBag $dedupeBag ) {
58
		$this->dedupeBag = $dedupeBag;
59
	}
60
61
	/**
62
	 * Site filter
63
	 *
64
	 * @param string $lang
65
	 *
66
	 * @return bool
67
	 */
68
	private function isSiteIncluded( $lang ) {
69
		return $this->sites === null || isset( $this->sites[$lang] );
70
	}
71
72
	/**
73
	 * Adds the site links of the given item to the RDF graph.
74
	 *
75
	 * @param Item $item
76
	 */
77
	public function addSiteLinks( Item $item ) {
78
		$id = $item->getId();
79
		$entityLName = $this->vocabulary->getEntityLName( $id );
0 ignored issues
show
It seems like $id defined by $item->getId() on line 78 can be null; however, Wikibase\Repo\Rdf\RdfVocabulary::getEntityLName() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
80
		$entityRepoName = $this->vocabulary->getEntityRepositoryName( $id );
0 ignored issues
show
It seems like $id defined by $item->getId() on line 78 can be null; however, Wikibase\Repo\Rdf\RdfVoc...tEntityRepositoryName() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
81
82
		/** @var SiteLink $siteLink */
83
		foreach ( $item->getSiteLinkList() as $siteLink ) {
84
			if ( !$this->isSiteIncluded( $siteLink->getSiteId() ) ) {
85
				continue;
86
			}
87
88
			// FIXME: we should check the site exists using hasGlobalId here before asuming it does
89
			$site = $this->siteLookup->getSite( $siteLink->getSiteId() );
90
			if ( !$site ) {
91
				// Somehow we've got site that we don't know about - skip
92
				continue;
93
			}
94
			$baseUrl = str_replace( '$1', wfUrlencode( str_replace( ' ', '_', $siteLink->getPageName() ) ),
95
									$site->getLinkPath() );
96
			// XXX: ideally, we'd use https if the target site supports it.
97
			if ( !parse_url( $baseUrl, PHP_URL_SCHEME ) ) {
98
				$url = "http:" . $baseUrl;
99
			} else {
100
				$url = $baseUrl;
101
			}
102
103
			$group = $site->getGroup();
104
			$siteUrl = parse_url( $url, PHP_URL_SCHEME ) . '://' . parse_url( $url, PHP_URL_HOST ) . "/";
105
			$lang = $this->vocabulary->getCanonicalLanguageCode( $site->getLanguageCode() );
106
107
			$this->writer->about( $url )
108
				->a( RdfVocabulary::NS_SCHEMA_ORG, 'Article' )
109
				->say( RdfVocabulary::NS_SCHEMA_ORG, 'about' )
110
				->is( $this->vocabulary->entityNamespaceNames[$entityRepoName], $entityLName )
111
				->say( RdfVocabulary::NS_SCHEMA_ORG, 'inLanguage' )->text( $lang )
112
				->say( RdfVocabulary::NS_SCHEMA_ORG, 'isPartOf' )->is( $siteUrl )
113
				->say( RdfVocabulary::NS_SCHEMA_ORG, 'name' )->text( $siteLink->getPageName(), $lang );
114
115
			foreach ( $siteLink->getBadges() as $badge ) {
116
				$badgeRepoName = $this->vocabulary->getEntityRepositoryName( $badge );
117
				$this->writer
118
					->say( RdfVocabulary::NS_ONTOLOGY, 'badge' )
119
					->is(
120
						$this->vocabulary->entityNamespaceNames[$badgeRepoName],
121
						$this->vocabulary->getEntityLName( $badge )
122
					);
123
			}
124
125
			/* Write group of the site only once.
126
			 * We are using URL as namespace to ensure it is not cut off.
127
			 * Since we do not have too may distinct sites, memory cost is small.
128
			 */
129
			if ( !$this->dedupeBag->alreadySeen( $group, $siteUrl ) ) {
130
				$this->writer->about( $siteUrl )
131
					->say( RdfVocabulary::NS_ONTOLOGY, 'wikiGroup' )->text( $group );
132
			}
133
134
		}
135
	}
136
137
	/**
138
	 * Add the entity's sitelinks to the RDF graph.
139
	 *
140
	 * @param EntityDocument $entity the entity to output.
141
	 */
142
	public function addEntity( EntityDocument $entity ) {
143
		if ( $entity instanceof Item ) {
144
			$this->addSiteLinks( $entity );
145
		}
146
	}
147
148
	/**
149
	 * Does nothing, since SiteLinks should not be part of entity stubs.
150
	 *
151
	 * @see EntityRdfBuilder::addEntityStub
152
	 *
153
	 * @param EntityDocument $entity the entity to output.
154
	 */
155
	public function addEntityStub( EntityDocument $entity ) {
156
		// noop
157
	}
158
159
}
160