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/Cache/ElementsCacheBuilder.php (2 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\Cache;
4
5
use SG\PropertyRegistrationHelper;
6
use SMW\DataValueFactory;
7
use SMW\Store;
8
use SMW\DIProperty;
9
use SMWStringValue as StringValue;
10
use SMWPrintRequest as PrintRequest;
11
use SMWPropertyValue as PropertyValue;
12
use SMWThingDescription as ThingDescription;
13
use SMWSomeProperty as SomeProperty;
14
use SMWQuery as Query;
15
use Lingo\Element;
16
17
/**
18
 * @ingroup SG
19
 * @ingroup SemanticGlossary
20
 *
21
 * @license GNU GPL v2+
22
 * @since 1.1
23
 *
24
 * @author Stephan Gambke
25
 * @author mwjames
26
 */
27
class ElementsCacheBuilder {
28
29
	/* @var Store */
30
	private $store;
31
32
	/* @var GlossaryCache */
33
	private $glossaryCache;
34
35
	private $mDiTerm;
36
	private $mDiDefinition;
37
	private $mDiLink;
38
	private $mDiStyle;
39
40
	private $mDvTerm;
41
	private $mDvDefinition;
42
	private $mDvLink;
43
	private $mDvStyle;
44
45
	private $queryResults;
46
47
	/**
48
	 * @since  1.1
49
	 *
50
	 * @param SMWStore $store
51
	 * @param GlossaryCache $cache
0 ignored issues
show
There is no parameter named $cache. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
52
	 */
53 2
	public function __construct( Store $store, GlossaryCache $glossaryCache ) {
54 2
		$this->store = $store;
55 2
		$this->glossaryCache = $glossaryCache;
56 2
	}
57
58
	/**
59
	 * @since 1.1
60
	 *
61
	 * @return array
62
	 */
63 1
	public function getElements() {
64
65 1
		$ret = array();
66
67 1
		if ( $this->queryResults === null ) {
68 1
			$this->queryResults = $this->store->getQueryResult( $this->buildQuery() )->getResults();
69
		}
70
71
		// find next line
72 1
		$page = current( $this->queryResults );
73
74 1
		if ( $page && count( $ret ) == 0 ) {
75
76 1
			next( $this->queryResults );
77
78 1
			$cachekey = $this->glossaryCache->getKeyForSubject( $page );
79 1
			$cachedResult = $this->glossaryCache->getCache()->get( $cachekey );
80
81
			// cache hit?
82 1
			if ( $cachedResult !== false && $cachedResult !== null ) {
83
84
				wfDebug( "Cache hit: Got glossary entry $cachekey from cache.\n" );
85
				$ret = &$cachedResult;
86
			} else {
87
88 1
				wfDebug( "Cache miss: Glossary entry $cachekey not found in cache.\n" );
89
90 1
				$ret = $this->buildElements(
91 1
					$this->getTerms( $page ),
92 1
					$this->getDefinitionValue( $page ),
93 1
					$this->getLinkValue( $page ),
94 1
					$this->getStyleValue( $page ),
95 1
					$page
96
				);
97
98 1
				wfDebug( "Cached glossary entry $cachekey.\n" );
99 1
				$this->glossaryCache->getCache()->set( $cachekey, $ret );
100
			}
101
		}
102
103 1
		return $ret;
104
	}
105
106 1
	private function buildElements( $terms, $definition, $link, $style, $page ) {
107
108 1
		$ret = array();
109
110 1
		foreach ( $terms as $term ) {
111
			$tmp_ret = array(
112 1
				Element::ELEMENT_TERM => $term,
113 1
				Element::ELEMENT_DEFINITION => $definition,
114 1
				Element::ELEMENT_LINK => $link,
115 1
				Element::ELEMENT_STYLE => $style,
116 1
				Element::ELEMENT_SOURCE => $page
117
			);
118
119 1
			$ret[] = $tmp_ret;
120
		}
121
122 1
		return $ret;
123
	}
124
125 1
	private function buildQuery() {
126
127 1
		$dataValueFactory = DataValueFactory::getInstance();
128
129
		// build term data item and data value for later use
130 1
		$this->mDiTerm = new DIProperty( PropertyRegistrationHelper::SG_TERM );
131 1
		$this->mDvTerm = $dataValueFactory->newDataValueByType( '_txt' );
132 1
		$this->mDvTerm->setProperty( $this->mDiTerm );
133
134 1
		$pvTerm = $dataValueFactory->newDataValueByType( '__pro' );
135 1
		$pvTerm->setDataItem( $this->mDiTerm );
136 1
		$prTerm = new PrintRequest( PrintRequest::PRINT_PROP, null, $pvTerm );
137
138
		// build definition data item and data value for later use
139 1
		$this->mDiDefinition = new DIProperty( PropertyRegistrationHelper::SG_DEFINITION );
140 1
		$this->mDvDefinition = $dataValueFactory->newDataValueByType( '_txt' );
141 1
		$this->mDvDefinition->setProperty( $this->mDiDefinition );
142
143 1
		$pvDefinition = $dataValueFactory->newDataValueByType( '__pro' );
144 1
		$pvDefinition->setDataItem( $this->mDiDefinition );
145 1
		$prDefinition = new PrintRequest( PrintRequest::PRINT_PROP, null, $pvDefinition );
146
147
		// build link data item and data value for later use
148 1
		$this->mDiLink = new DIProperty( PropertyRegistrationHelper::SG_LINK );
149 1
		$this->mDvLink = $dataValueFactory->newDataValueByType( '_txt' );
150 1
		$this->mDvLink->setProperty( $this->mDiLink );
151
152 1
		$pvLink = $dataValueFactory->newDataValueByType( '__pro' );
153 1
		$pvLink->setDataItem( $this->mDiLink );
154 1
		$prLink = new PrintRequest( PrintRequest::PRINT_PROP, null, $pvLink );
155
156
		// build style data item and data value for later use
157 1
		$this->mDiStyle = new DIProperty( PropertyRegistrationHelper::SG_STYLE );
158 1
		$this->mDvStyle = $dataValueFactory->newDataValueByType( '_txt' );
159 1
		$this->mDvStyle->setProperty( $this->mDiStyle );
160
161 1
		$pvStyle = $dataValueFactory->newDataValueByType( '__pro' );
162 1
		$pvStyle->setDataItem( $this->mDiStyle );
163 1
		$prStyle = new PrintRequest( PrintRequest::PRINT_PROP, null, $pvStyle );
164
165
		// Create query
166 1
		$desc = new SomeProperty( new DIProperty( '___glt' ), new ThingDescription() );
167 1
		$desc->addPrintRequest( $prTerm );
168 1
		$desc->addPrintRequest( $prDefinition );
169 1
		$desc->addPrintRequest( $prLink );
170 1
		$desc->addPrintRequest( $prStyle );
171
172 1
		$query = new Query( $desc, 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...
173 1
		$query->sort = true;
174 1
		$query->sortkeys['___glt'] = 'ASC';
175
176 1
		if ( defined( 'SMWQuery::PROC_CONTEXT' ) ) {
177 1
			$query->setOption( Query::PROC_CONTEXT, 'SG.ElementsCacheBuilder' );
178
		}
179
180 1
		return $query;
181
	}
182
183 1
	private function getDefinitionValue( $page ) {
184
185 1
		$definition  = null;
186
187 1
		$definitions = $this->store->getPropertyValues(
188 1
			$page,
189 1
			$this->mDiDefinition
190
		);
191
192 1
		if ( !empty( $definitions ) ) {
193 1
			$this->mDvDefinition->setDataItem( $definitions[0] );
194 1
			$definition = trim( $this->mDvDefinition->getShortWikiText() );
195
		}
196
197 1
		return $definition;
198
	}
199
200 1
	private function getLinkValue( $page ) {
201
202 1
		$link  = null;
203
204 1
		$links = $this->store->getPropertyValues( $page, $this->mDiLink );;
205
206 1
		if ( !empty( $links ) ) {
207
			$this->mDvLink->setDataItem( $links[0] );
208
			$link = trim( $this->mDvLink->getShortWikiText() );
209
		}
210
211 1
		return $link;
212
	}
213
214 1
	private function getStyleValue( $page ) {
215
216 1
		$style  = null;
217
218 1
		$styles = $this->store->getPropertyValues( $page, $this->mDiStyle );;
219
220 1
		if ( !empty( $styles ) ) {
221
		  $this->mDvStyle->setDataItem( $styles[0] );
222
		  $style = trim( $this->mDvStyle->getShortWikiText() );
223
		}
224
225 1
		return $style;
226
	}
227
228 1
	private function getTerms( $page ) {
229
230 1
		$collectedTerms = array();
231
232 1
		$terms = $this->store->getPropertyValues( $page, $this->mDiTerm );
233
234 1
		if ( $terms !== array() ) {
235 1
			foreach ( $terms as $term ) {
236 1
				$this->mDvTerm->setDataItem( $term );
237 1
				$collectedTerms[] = trim( $this->mDvTerm->getShortWikiText() );
238
			}
239
		}
240
241 1
		return $collectedTerms;
242
	}
243
244
}
245