|
MediaWiki master
|
Service to verify file uploads are safe. More...
Public Member Functions | |
| __construct (ServiceOptions $config, MimeAnalyzer $mimeAnalyzer, SVGCSSChecker $SVGCSSChecker) | |
| 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 | ( | ServiceOptions | $config, |
| MimeAnalyzer | $mimeAnalyzer, | ||
| SVGCSSChecker | $SVGCSSChecker ) |
| ServiceOptions | $config | |
| MimeAnalyzer | $mimeAnalyzer |
Definition at line 71 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 281 of file UploadVerification.php.
References wfDebug().
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 890 of file UploadVerification.php.
References MediaWiki\MainConfigNames\Antivirus, MediaWiki\MainConfigNames\AntivirusRequired, MediaWiki\MainConfigNames\AntivirusSetup, AV_NO_VIRUS, AV_SCAN_ABORTED, AV_SCAN_FAILED, wfDebug(), wfMessage(), and wfShellExecWithStderr().
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 224 of file UploadVerification.php.
References wfDebug().
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. FIXME final ext can sometimes be null, but should we require casting to string? |
Definition at line 119 of file UploadVerification.php.
References $path, MediaWiki\MainConfigNames\DisableUploadScriptChecks, MediaWiki\Config\ServiceOptions\get(), MediaWiki\Upload\UploadVerification\verifyExtension(), MediaWiki\MainConfigNames\VerifyMimeType, MediaWiki\Upload\UploadVerification\verifyPartialFile(), and wfDebug().
| 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 183 of file UploadVerification.php.
References $path, MediaWiki\Upload\UploadVerification\detectScript(), MediaWiki\Upload\UploadVerification\detectVirus(), MediaWiki\MainConfigNames\DisableUploadScriptChecks, and MediaWiki\Config\ServiceOptions\get().
Referenced by MediaWiki\Upload\UploadVerification\verifyFile().
| const MediaWiki\Upload\UploadVerification::CONSTRUCTOR_OPTIONS |
Definition at line 54 of file UploadVerification.php.