Issues (17)

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.

src/Maintenance/GlossaryCacheRebuilder.php (4 issues)

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 SG\Maintenance;
4
5
use SG\PropertyRegistrationHelper;
6
use SG\Cache\GlossaryCache;
7
8
use SMWUpdateJob as UpdateJob;
9
use SMW\Store;
10
11
use SMWQuery as Query;
12
use SMWSomeProperty as SomeProperty;
13
use SMWDIProperty as DIProperty;
14
use SMWThingDescription as ThingDescription;
15
16
/**
17
 * Part of the `rebuildGlossaryCache.php` maintenance script
18
 *
19
 * @ingroup SG
20
 *
21
 * @license GNU GPL v2+
22
 * @since 1.1
23
 *
24
 * @author mwjames
25
 */
26
class GlossaryCacheRebuilder {
27
28
	/** @var Store */
29
	private $store;
30
31
	/** @var GlossaryCache */
32
	private $glossaryCache;
33
34
	private $reporter = null;
35
	private $rebuildCount = 0;
36
	private $verbose = false;
37
38
	/**
39
	 * @since 1.1
40
	 *
41
	 * @param Store $store
42
	 * @param GlossaryCache $glossaryCache
43
	 * @param $reporter
44
	 */
45 3
	public function __construct( Store $store, GlossaryCache $glossaryCache, $reporter = null ) {
46 3
		$this->store = $store;
47 3
		$this->glossaryCache = $glossaryCache;
48 3
		$this->reporter = $reporter; // Should be a MessageReporter instance
49 3
	}
50
51
	/**
52
	 * @since 1.1
53
	 *
54
	 * @param array $options
55
	 */
56 2
	public function setParameters( array $options ) {
57 2
		$this->verbose = array_key_exists( 'verbose', $options );
58 2
	}
59
60
	/**
61
	 * @since 1.1
62
	 *
63
	 * @return int
64
	 */
65 1
	public function getRebuildCount() {
66 1
		return $this->rebuildCount;
67
	}
68
69
	/**
70
	 * @since 1.1
71
	 *
72
	 * @return boolean
73
	 */
74 2
	public function rebuild() {
75
76 2
		$pages = $this->store->getQueryResult( $this->buildQuery() )->getResults();
77
78 2
		$this->removeEntitiesFromCache( $pages );
79 2
		$this->updateSelectedPages( $pages );
80
81 2
		return true;
82
	}
83
84 2
	private function updateSelectedPages( array $pages ) {
85
86 2
		$titleCache = array();
87
88 2
		foreach ( $pages as $page ) {
89
90 2
			$title = $page->getTitle();
91
92 2
			if ( $title !== null && !isset( $titleCache[ $title->getPrefixedDBkey() ] ) ) {
93
94 2
				$this->rebuildCount++;
95
96 2
				$this->reportMessage( "($this->rebuildCount) Processing page " . $title->getPrefixedDBkey() . " ...\n", $this->verbose );
97
98
				// FIXME Wrong approach, users outside of smw-core should not
99
				// directly create an instance and instead use a factory for
100
				// that purpose such as JobFactory::newUpdateJob( ... )
101 2
				$updatejob = new UpdateJob( $title );
102 2
				$updatejob->run();
103
104 2
				$titleCache[ $title->getPrefixedDBkey() ] = true;
105
			}
106
		}
107
108 2
		$this->reportMessage( "$this->rebuildCount pages refreshed.\n" );
109
110 2
		return true;
111
	}
112
113 2
	private function buildQuery() {
114
115 2
		$description = new SomeProperty(
116 2
			new DIProperty( PropertyRegistrationHelper::SG_TERM ),
117 2
			new ThingDescription()
118
		);
119
120 2
		$countQuery = new Query( $description, false, false );
0 ignored issues
show
The call to SMWQuery::__construct() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
121 2
		$countQuery->querymode = Query::MODE_COUNT;
122
123 2
		$queryResult = $this->store->getQueryResult( $countQuery );
124 2
		$numberOfPages = $queryResult instanceof \SMWQueryResult ? $queryResult->getCountValue() : $queryResult;
0 ignored issues
show
The class SMWQueryResult does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
125
126 2
		$resultQuery = new Query(
127 2
			$description,
128 2
			false,
129 2
			false
0 ignored issues
show
The call to SMWQuery::__construct() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
130
		);
131
132 2
		$resultQuery->setUnboundLimit( $numberOfPages, false );
0 ignored issues
show
The call to SMWQuery::setUnboundLimit() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
133
134 2
		return $resultQuery;
135
	}
136
137 2
	private function removeEntitiesFromCache( array $pages ) {
138
139 2
		$cache = $this->glossaryCache->getCache();
140
141 2
		$cache->delete( $this->glossaryCache->getKeyForLingo() );
142
143 2
		foreach ( $pages as $page ) {
144 2
			$cache->delete( $this->glossaryCache->getKeyForSubject( $page ) );
145
		}
146
147 2
		$this->reportMessage( "\n" . ( count( $pages ) + 1 ) . " cache entities deleted.\n\n" );
148 2
	}
149
150
	/**
151
	 * @codeCoverageIgnore
152
	 */
153
	private function reportMessage( $message, $output = true ) {
154
		if ( is_callable( $this->reporter ) && $output ) {
155
			call_user_func( $this->reporter, $message );
156
		}
157
	}
158
159
}
160