Issues (37)

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/Service/PagePurger.php (3 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 Mediawiki\Api\Service;
4
5
use Mediawiki\Api\Generator\ApiGenerator;
6
use Mediawiki\Api\SimpleRequest;
7
use Mediawiki\DataModel\Page;
8
use Mediawiki\DataModel\Pages;
9
10
/**
11
 * @access private
12
 *
13
 * @author Addshore
14
 * @author Thomas Arrow
15
 */
16
class PagePurger extends Service {
17
18
	/**
19
	 * @since 0.3
20
	 *
21
	 * Purge a single page
22
	 *
23
	 * Purges a single page by submitting a
24
	 * 'purge' action to the mediawiki api
25
	 * with the parameter 'pageids' set to
26
	 * the singe page id
27
	 *
28
	 * @param Page $page the page that is going to be purged
29
	 *
30
	 * @return bool return true if the purge was successful
31
	 */
32
	public function purge( Page $page ) {
33
		if ( $page->getPageIdentifier()->getId() ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $page->getPageIdentifier()->getId() of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
34
			$params = [ 'pageids' => $page->getPageIdentifier()->getId() ];
35
		} else {
36
			$params = [ 'titles' => $page->getPageIdentifier()->getTitle()->getText() ];
37
		}
38
39
		$responseArray = $this->api->postRequest(
40
			new SimpleRequest( 'purge', $params )
41
		);
42
43
		// the purge response for the page
44
		$purgeResponse = $responseArray['purge'][0];
45
46
		return array_key_exists( 'purged', $purgeResponse );
47
	}
48
49
	/**
50
	 * @since 0.7
51
	 *
52
	 * Purge multiple pages
53
	 *
54
	 * Purges all the pages of the Pages object
55
	 * by submitting a 'purge' action to the mediawiki
56
	 * api with the parameter 'pageids' set to be the
57
	 * pages ids in multiple-value seperation.
58
	 *
59
	 * @param Pages $pages the pages that are going to be purged
60
	 *
61
	 * @return Pages the pages that have been purged successfully
62
	 */
63
	public function purgePages( Pages $pages ) {
64
		$pagesArray = $pages->toArray();
65
		$pagesIds = [];
66
67
		foreach ( $pagesArray as $page ) {
68
			array_push( $pagesIds, $page->getId() );
0 ignored issues
show
Deprecated Code introduced by
The method Mediawiki\DataModel\Page::getId() has been deprecated with message: since 0.5

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...
69
		}
70
71
		// convert an array to multiple-value format
72
		// because the mediawiki api require multiple
73
		// values to be seperated like the example
74
		// ex: [111, 222, 333] => "111|222|333"
75
		$pageIdsMultiple = implode( '|', $pagesIds );
76
77
		$responseArray = $this->api->postRequest(
78
			new SimpleRequest( 'purge', [ 'pageids' => $pageIdsMultiple ] )
79
		);
80
81
		// array that will hold the successfully purged pages
82
		$purgedPages = new Pages();
83
84
		// for every purge result
85
		foreach ( $responseArray['purge'] as $purgeResponse ) {
86
			// if the purge for the page was successful
87
			if ( array_key_exists( 'purged', $purgeResponse ) ) {
88
				// we iterate all the input pages
89
				foreach ( $pagesArray as $page ) {
90
					// and if the page from the input was successfully purged
91
					if ( $purgeResponse['title'] === $page->getTitle()->getText() ) {
0 ignored issues
show
Deprecated Code introduced by
The method Mediawiki\DataModel\Page::getTitle() has been deprecated with message: since 0.5

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
						// add it in the purgedPages object
93
						$purgedPages->addPage( $page );
94
95
						break;
96
					}
97
98
				}
99
100
			}
101
102
		}
103
104
		return $purgedPages;
105
	}
106
107
	/**
108
	 * @since 0.6
109
	 *
110
	 * @param ApiGenerator $generator
111
	 *
112
	 * @return bool
113
	 */
114
	public function purgeGenerator( ApiGenerator $generator ) {
115
		$this->api->postRequest(
116
			new SimpleRequest( 'purge', $generator->getParams() )
117
		);
118
119
		return true;
120
	}
121
122
}
123