Issues (4122)

Security Analysis    not enabled

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.

maintenance/edit.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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Make a page edit.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 * http://www.gnu.org/copyleft/gpl.html
19
 *
20
 * @file
21
 * @ingroup Maintenance
22
 */
23
24
require_once __DIR__ . '/Maintenance.php';
25
26
/**
27
 * Maintenance script to make a page edit.
28
 *
29
 * @ingroup Maintenance
30
 */
31
class EditCLI extends Maintenance {
32
	public function __construct() {
33
		parent::__construct();
34
		$this->addDescription( 'Edit an article from the command line, text is from stdin' );
35
		$this->addOption( 'user', 'Username', false, true, 'u' );
36
		$this->addOption( 'summary', 'Edit summary', false, true, 's' );
37
		$this->addOption( 'minor', 'Minor edit', false, false, 'm' );
38
		$this->addOption( 'bot', 'Bot edit', false, false, 'b' );
39
		$this->addOption( 'autosummary', 'Enable autosummary', false, false, 'a' );
40
		$this->addOption( 'no-rc', 'Do not show the change in recent changes', false, false, 'r' );
41
		$this->addOption( 'nocreate', 'Don\'t create new pages', false, false );
42
		$this->addOption( 'createonly', 'Only create new pages', false, false );
43
		$this->addArg( 'title', 'Title of article to edit' );
44
	}
45
46
	public function execute() {
47
		global $wgUser;
48
49
		$userName = $this->getOption( 'user', false );
50
		$summary = $this->getOption( 'summary', '' );
51
		$minor = $this->hasOption( 'minor' );
52
		$bot = $this->hasOption( 'bot' );
53
		$autoSummary = $this->hasOption( 'autosummary' );
54
		$noRC = $this->hasOption( 'no-rc' );
55
56 View Code Duplication
		if ( $userName === false ) {
57
			$wgUser = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
58
		} else {
59
			$wgUser = User::newFromName( $userName );
60
		}
61
		if ( !$wgUser ) {
62
			$this->error( "Invalid username", true );
63
		}
64
		if ( $wgUser->isAnon() ) {
65
			$wgUser->addToDatabase();
66
		}
67
68
		$title = Title::newFromText( $this->getArg() );
69
		if ( !$title ) {
70
			$this->error( "Invalid title", true );
71
		}
72
73
		if ( $this->hasOption( 'nocreate' ) && !$title->exists() ) {
74
			$this->error( "Page does not exist", true );
75
		} elseif ( $this->hasOption( 'createonly' ) && $title->exists() ) {
76
			$this->error( "Page already exists", true );
77
		}
78
79
		$page = WikiPage::factory( $title );
0 ignored issues
show
It seems like $title defined by \Title::newFromText($this->getArg()) on line 68 can be null; however, WikiPage::factory() 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
81
		# Read the text
82
		$text = $this->getStdin( Maintenance::STDIN_ALL );
83
		$content = ContentHandler::makeContent( $text, $title );
0 ignored issues
show
It seems like $text defined by $this->getStdin(\Maintenance::STDIN_ALL) on line 82 can also be of type resource; however, ContentHandler::makeContent() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
84
85
		# Do the edit
86
		$this->output( "Saving... " );
87
		$status = $page->doEditContent( $content, $summary,
88
			( $minor ? EDIT_MINOR : 0 ) |
89
			( $bot ? EDIT_FORCE_BOT : 0 ) |
90
			( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
91
			( $noRC ? EDIT_SUPPRESS_RC : 0 ) );
92
		if ( $status->isOK() ) {
93
			$this->output( "done\n" );
94
			$exit = 0;
95
		} else {
96
			$this->output( "failed\n" );
97
			$exit = 1;
98
		}
99
		if ( !$status->isGood() ) {
100
			$this->output( $status->getWikiText( false, false, 'en' ) . "\n" );
101
		}
102
		exit( $exit );
0 ignored issues
show
Coding Style Compatibility introduced by
The method execute() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
103
	}
104
}
105
106
$maintClass = "EditCLI";
107
require_once RUN_MAINTENANCE_IF_MAIN;
108