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/eraseArchivedFile.php (1 issue)

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
 * Delete archived (non-current) files from storage
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
 * @author Aaron Schulz
23
 */
24
25
require_once __DIR__ . '/Maintenance.php';
26
27
/**
28
 * Maintenance script to delete archived (non-current) files from storage.
29
 *
30
 * @todo Maybe add some simple logging
31
 *
32
 * @ingroup Maintenance
33
 * @since 1.22
34
 */
35
class EraseArchivedFile extends Maintenance {
36 View Code Duplication
	public function __construct() {
37
		parent::__construct();
38
		$this->addDescription( 'Erases traces of deleted files.' );
39
		$this->addOption( 'delete', 'Perform the deletion' );
40
		$this->addOption( 'filename', 'File name', false, true );
41
		$this->addOption( 'filekey', 'File storage key (with extension) or "*"', true, true );
42
	}
43
44
	public function execute() {
45
		if ( !$this->hasOption( 'delete' ) ) {
46
			$this->output( "Use --delete to actually confirm this script\n" );
47
		}
48
49
		$filekey = $this->getOption( 'filekey' );
50
		$filename = $this->getOption( 'filename' );
51
52
		if ( $filekey === '*' ) { // all versions by name
53
			if ( !strlen( $filename ) ) {
54
				$this->error( "Missing --filename parameter.", 1 );
55
			}
56
			$afile = false;
57
		} else { // specified version
58
			$dbw = $this->getDB( DB_MASTER );
59
			$row = $dbw->selectRow( 'filearchive', '*',
60
				[ 'fa_storage_group' => 'deleted', 'fa_storage_key' => $filekey ],
61
				__METHOD__ );
62
			if ( !$row ) {
63
				$this->error( "No deleted file exists with key '$filekey'.", 1 );
64
			}
65
			$filename = $row->fa_name;
66
			$afile = ArchivedFile::newFromRow( $row );
67
		}
68
69
		$file = wfLocalFile( $filename );
70
		if ( $file->exists() ) {
71
			$this->error( "File '$filename' is still a public file, use the delete form.\n", 1 );
72
		}
73
74
		$this->output( "Purging all thumbnails for file '$filename'..." );
75
		$file->purgeCache();
76
		$this->output( "done.\n" );
77
78
		if ( $afile instanceof ArchivedFile ) {
79
			$this->scrubVersion( $afile );
80
		} else {
81
			$this->output( "Finding deleted versions of file '$filename'...\n" );
82
			$this->scrubAllVersions( $filename );
83
			$this->output( "Done\n" );
84
		}
85
	}
86
87
	protected function scrubAllVersions( $name ) {
88
		$dbw = $this->getDB( DB_MASTER );
89
		$res = $dbw->select( 'filearchive', '*',
90
			[ 'fa_name' => $name, 'fa_storage_group' => 'deleted' ],
91
			__METHOD__ );
92
		foreach ( $res as $row ) {
93
			$this->scrubVersion( ArchivedFile::newFromRow( $row ) );
94
		}
95
	}
96
97
	protected function scrubVersion( ArchivedFile $archivedFile ) {
98
		$key = $archivedFile->getStorageKey();
99
		$name = $archivedFile->getName();
100
		$ts = $archivedFile->getTimestamp();
101
		$repo = RepoGroup::singleton()->getLocalRepo();
102
		$path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
103
		if ( $this->hasOption( 'delete' ) ) {
104
			$status = $repo->getBackend()->delete( [ 'src' => $path ] );
105
			if ( $status->isOK() ) {
106
				$this->output( "Deleted version '$key' ($ts) of file '$name'\n" );
107
			} else {
108
				$this->output( "Failed to delete version '$key' ($ts) of file '$name'\n" );
109
				$this->output( print_r( $status->getErrorsArray(), true ) );
0 ignored issues
show
The method getErrorsArray() does not exist on StatusValue. Did you maybe mean getErrors()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
110
			}
111
		} else {
112
			$this->output( "Would delete version '{$key}' ({$ts}) of file '$name'\n" );
113
		}
114
	}
115
}
116
117
$maintClass = "EraseArchivedFile";
118
require_once RUN_MAINTENANCE_IF_MAIN;
119