|
MediaWiki master
|
Service to verify file uploads are safe. More...
Public Member Functions | |
| __construct (private ServiceOptions $config, private MimeAnalyzer $mimeAnalyzer, private LoggerInterface $logger,) | |
| detectScript ( $file, $mime, $extension) | |
| Heuristic for detecting files that could contain JavaScript instructions or things that may look like HTML to a browser and are thus potentially harmful. | |
| detectVirus ( $file) | |
| Generic wrapper function for a virus scanner program. | |
| verifyExtension ( $mime, $extension) | |
| Checks if the MIME type of the uploaded file matches the file extension. | |
| verifyFile (string $path, string $ext, array $fileProps) | |
| Verifies that the upload file is safe. | |
| verifyPartialFile (string $path, string $ext, array $fileProps) | |
| A verification routine suitable for partial files. | |
Public Attributes | |
| const | CONSTRUCTOR_OPTIONS |
Service to verify file uploads are safe.
This is responsible for checks on the file contents themselves. It is not responsible for on wiki checks like if the user has permission or if the upload target is protected.
Definition at line 34 of file UploadVerification.php.
| MediaWiki\Upload\UploadVerification::__construct | ( | private ServiceOptions | $config, |
| private MimeAnalyzer | $mimeAnalyzer, | ||
| private LoggerInterface | $logger ) |
Definition at line 65 of file UploadVerification.php.
References MediaWiki\Config\ServiceOptions\assertRequiredOptions().
| MediaWiki\Upload\UploadVerification::detectScript | ( | $file, | |
| $mime, | |||
| $extension ) |
Heuristic for detecting files that could contain JavaScript instructions or things that may look like HTML to a browser and are thus potentially harmful.
The present implementation will produce false positives in some situations.
| string | null | $file | Pathname to the temporary upload file |
| string | $mime | The MIME type of the file |
| string | null | $extension | The extension of the file |
Definition at line 289 of file UploadVerification.php.
Referenced by MediaWiki\Upload\UploadVerification\verifyPartialFile().
| MediaWiki\Upload\UploadVerification::detectVirus | ( | $file | ) |
Generic wrapper function for a virus scanner program.
This relies on the $wgAntivirus and $wgAntivirusSetup variables. $wgAntivirusRequired may be used to deny upload if the scan fails.
| string | $file | Pathname to the temporary upload file |
Definition at line 954 of file UploadVerification.php.
References MediaWiki\MainConfigNames\Antivirus, MediaWiki\MainConfigNames\AntivirusRequired, MediaWiki\MainConfigNames\AntivirusSetup, AV_NO_VIRUS, AV_SCAN_ABORTED, AV_SCAN_FAILED, and wfMessage().
Referenced by MediaWiki\Upload\UploadBase\detectVirus(), and MediaWiki\Upload\UploadVerification\verifyPartialFile().
| MediaWiki\Upload\UploadVerification::verifyExtension | ( | $mime, | |
| $extension ) |
Checks if the MIME type of the uploaded file matches the file extension.
| string | $mime | The MIME type of the uploaded file |
| string | $extension | The filename extension that the file is to be served with |
Definition at line 215 of file UploadVerification.php.
Referenced by MediaWiki\Upload\UploadVerification\verifyFile().
| MediaWiki\Upload\UploadVerification::verifyFile | ( | string | $path, |
| string | $ext, | ||
| array | $fileProps ) |
Verifies that the upload file is safe.
| string | $path | Path to the (temporary) file to check |
| string | $ext | Final extension of file (UploadBase->mFinalExtension) |
| array | $fileProps | Result of $mwProps->getPropsFromPath. |
Definition at line 108 of file UploadVerification.php.
References $path, MediaWiki\MainConfigNames\DisableUploadScriptChecks, MediaWiki\Upload\UploadVerification\verifyExtension(), MediaWiki\MainConfigNames\VerifyMimeType, and MediaWiki\Upload\UploadVerification\verifyPartialFile().
| MediaWiki\Upload\UploadVerification::verifyPartialFile | ( | string | $path, |
| string | $ext, | ||
| array | $fileProps ) |
A verification routine suitable for partial files.
Runs the deny list checks, but not any checks that may assume the entire file is present.
fileProps can be very expensive to calculate, so the calling class is responsible for caching it.
| string | $path | Path to the (temporary) file to check |
| string | $ext | Final extension of file (UploadBase->mFinalExtension) |
| array | $fileProps | Result of $mwProps->getPropsFromPath |
Definition at line 172 of file UploadVerification.php.
References $path, MediaWiki\Upload\UploadVerification\detectScript(), MediaWiki\Upload\UploadVerification\detectVirus(), and MediaWiki\MainConfigNames\DisableUploadScriptChecks.
Referenced by MediaWiki\Upload\UploadVerification\verifyFile().
| const MediaWiki\Upload\UploadVerification::CONSTRUCTOR_OPTIONS |
Definition at line 54 of file UploadVerification.php.