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/CacheInvalidator.php (5 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\SemanticDataComparator;
6
use SG\PropertyRegistrationHelper;
7
8
use SMW\Store;
9
use SMW\SemanticData;
10
use SMW\DIWikiPage;
11
use SMW\DIProperty;
12
13
use Lingo\LingoParser;
14
15
use MediaWiki\Linker\LinkTarget;
16
17
/**
18
 * @ingroup SG
19
 * @ingroup SemanticGlossary
20
 *
21
 * @license GNU GPL v2+
22
 * @since 1.0
23
 *
24
 * @author Stephan Gambke
25
 * @author mwjames
26
 */
27
class CacheInvalidator {
28
29
	/**
30
	 * @var CacheInvalidator
31
	 */
32
	private static $instance = null;
33
34
	/**
35
	 * @var GlossaryCache
36
	 */
37
	private $cache = null;
38
39
	/**
40
	 * @since 1.0
41
	 *
42
	 * @return CacheInvalidator
43
	 */
44 4
	public static function getInstance() {
45
46 4
		if ( self::$instance === null ) {
47
48 1
			$instance = new self();
49 1
			$instance->setCache( new GlossaryCache() );
50
51 1
			self::$instance = $instance;
52
		}
53
54 4
		return self::$instance;
55
	}
56
57
	/**
58
	 * @since 1.0
59
	 */
60 1
	public static function clear() {
61 1
		self::$instance = null;
62 1
	}
63
64
	/**
65
	 * @since 1.0
66
	 *
67
	 * @param GlossaryCache $glossaryCache
68
	 */
69 7
	public function setCache( GlossaryCache $glossaryCache ) {
70 7
		$this->glossaryCache = $glossaryCache;
0 ignored issues
show
The property glossaryCache does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
71 7
	}
72
73
	/**
74
	 * @since 1.0
75
	 *
76
	 * @param Store $store
77
	 * @param SemanticData $semanticData
78
	 *
79
	 * @return boolean
80
	 */
81 6
	public function invalidateCacheOnStoreUpdate( Store $store, SemanticData $semanticData = null ) {
82
83 6
		if ( $semanticData === null ) {
84 1
			return false;
85
		}
86
87 5
		$this->matchAllSubobjects( $store, $semanticData );
88
89 5
		if ( $this->hasSemanticDataDeviation( $store, $semanticData ) ) {
90 3
			$this->purgeCache( $semanticData->getSubject() );
91 3
			LingoParser::purgeCache();
0 ignored issues
show
Deprecated Code introduced by
The method Lingo\LingoParser::purgeCache() has been deprecated with message: 2.0.2

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
92
		}
93
94 5
		return true;
95
	}
96
97
	/**
98
	 * @since 1.0
99
	 *
100
	 * @param Store $store
101
	 * @param DIWikiPage $subject
102
	 * @param boolean|true $purgeLingo
103
	 *
104
	 * @return boolean
105
	 */
106 3
	public function invalidateCacheOnPageDelete( Store $store, DIWikiPage $subject, $purgeLingo = true ) {
107
108 3
		$this->matchSubobjectsToSubject( $store, $subject );
109 3
		$this->purgeCache( $subject );
110
111 3
		if ( $purgeLingo ) {
112 3
			LingoParser::purgeCache();
0 ignored issues
show
Deprecated Code introduced by
The method Lingo\LingoParser::purgeCache() has been deprecated with message: 2.0.2

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
113
		}
114
115 3
		return true;
116
	}
117
118
	/**
119
	 * @since 1.0
120
	 *
121
	 * @param LinkTarget $title
122
	 *
123
	 * @return boolean
124
	 */
125 1
	public function invalidateCacheOnPageMove( LinkTarget $title ) {
126 1
		$this->purgeCache( DIWikiPage::newFromText( $title->getDBkey(), $title->getNamespace() ));
127 1
		return true;
128
	}
129
130 5
	private function matchAllSubobjects( Store $store, SemanticData $semanticData ) {
131
132 5
		$properties = $semanticData->getProperties();
133
134 5
		if ( array_key_exists( DIProperty::TYPE_SUBOBJECT, $properties ) ) {
135 1
			foreach ( $semanticData->getPropertyValues( $properties[ DIProperty::TYPE_SUBOBJECT ] ) as $subobject ) {
136 1
				$this->invalidateCacheOnStoreUpdate(
137 1
					$store,
138 1
					$semanticData->findSubSemanticData( $subobject->getSubobjectName() ),
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class SMWDataItem as the method getSubobjectName() does only exist in the following sub-classes of SMWDataItem: SMWDIWikiPage, SMW\DIWikiPage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
139 1
					false
0 ignored issues
show
The call to CacheInvalidator::invalidateCacheOnStoreUpdate() 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...
140
				);
141
			}
142
		}
143 5
	}
144
145 3
	private function matchSubobjectsToSubject( Store $store, DIWikiPage $subject ) {
146
147 3
		$properties = $store->getProperties( $subject );
148
149 3
		if ( array_key_exists( DIProperty::TYPE_SUBOBJECT, $properties ) ) {
150 1
			foreach ( $store->getPropertyValues( $subject, $properties[ DIProperty::TYPE_SUBOBJECT ] ) as $subobject ) {
151
				$this->invalidateCacheOnPageDelete(
152
					$store,
153
					$subobject->getSubject(),
154
					false
155
				);
156
			}
157
		}
158 3
	}
159
160 5
	private function hasSemanticDataDeviation( Store $store, SemanticData $semanticData ) {
161
162 5
		$dataComparator = new SemanticDataComparator( $store, $semanticData );
163
164 5
		return $dataComparator->compareForProperty( PropertyRegistrationHelper::SG_TERM ) ||
165 5
			$dataComparator->compareForProperty( PropertyRegistrationHelper::SG_DEFINITION ) ||
166 5
			$dataComparator->compareForProperty( PropertyRegistrationHelper::SG_LINK ) ||
167 5
			$dataComparator->compareForProperty( PropertyRegistrationHelper::SG_STYLE );
168
	}
169
170 6
	private function purgeCache( DIWikiPage $subject ) {
171
172 6
		$this->glossaryCache->getCache()->delete(
173 6
			$this->glossaryCache->getKeyForSubject( $subject )
174
		);
175
176 6
		return true;
177
	}
178
179
}
180