Download the PHP package mediawiki/phan-taint-check-plugin without Composer

On this page you can find all versions of the php package mediawiki/phan-taint-check-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phan-taint-check-plugin

Phan Security Check Plugin

This is a plugin to Phan to try and detect security issues (such as XSS). It keeps track of any time a user can modify a variable, and checks to see that such variables are escaped before being output as html or used as an sql query, etc.

It supports generic PHP projects, and it also has a dedicated mode for MediaWiki code (analyzes hooks, HTMLForms and Database methods).

A web demo is available.

Usage

Install

$ composer require --dev mediawiki/phan-taint-check-plugin

Usage

The plugin can be used in both "manual" and "standalone" mode. The former is the best choice if your project is already running phan, and almost no configuration is needed. The latter should only be used if you don't want to add phan to your project, and is not supported for MediaWiki-related code. For more information about Wikimedia's use of this plugin see https://www.mediawiki.org/wiki/Phan-taint-check-plugin.

Manual

You simply have to add taint-check to the plugins section of your phan config. Assuming that taint-check is in the standard vendor location, e.g. $seccheckPath = 'vendor/mediawiki/phan-taint-check-plugin/';, the file to include is "$seccheckPath/GenericSecurityCheckPlugin.php" for a generic project, and "$seccheckPath/MediaWikiSecurityCheckPlugin.php" for a MediaWiki project.

Also, make sure that quick mode is disabled, or the plugin won't work:

You should also add SecurityCheck-LikelyFalsePositive and SecurityCheck-PHPSerializeInjection to suppress_issue_types (the latter has a high rate of false positives).

Then run phan as you normally would:

$ vendor/bin/phan -d . --long-progress-bar

Running phan with --analyze-twice will catch additional security issues that might go unnoticed in the normal analysis phase. A known limitation of this is that the same issue might be reported more than once with different caused-by lines.

Standalone

You can run taint-check via:

$ ./vendor/bin/seccheck

You might want to add a composer script alias for that:

Note that false positives are disabled by default.

Plugin output

The plugin will output various issue types depending on what it detects. The issue types it outputs are:

The severity field is usually marked as Issue::SEVERITY_NORMAL (5). False positives get Issue::SEVERITY_LOW (0). Issues that may result in server compromise (as opposed to just end user compromise) such as shell or sql injection are marked as Issue::SEVERITY_CRITICAL (10). SerializationInjection would normally be "critical" but its currently denoted as a severity of NORMAL because the check seems to have a high false positive rate at the moment.

You can use the -y command line option of Phan to filter by severity.

How to avoid false positives

If you need to suppress a false positive, you can put @suppress NAME-OF-WARNING in the docblock for a function/method. Alternatively, you can use other types of suppression, like @phan-suppress-next-line. See phan's readme for a complete list. The @param-taint and @return-taint (see "Customizing" section) are also very useful with dealing with false positives.

Note that the plugin will report possible XSS vulnerabilities in CLI context. To avoid them, you can suppress SecurityCheck-XSS file-wide with @phan-file-suppress in CLI scripts, or for the whole application (using the suppress_issue_types config option) if the application only consists of CLI scripts. Alternatively, if all outputting happens from an internal function, you can use @param-taint as follows:

When debugging security issues, you can use:

this will emit a SecurityCheckDebugTaintedness issue containing the taintedness of $varname at the line where the annotation is found. Note that you have to insert the annotation in a string literal; comments will not work. See also phan's @phan-debug-var annotation.

Notable limitations

General limitations

MediaWiki specific limitations

Customizing

The plugin supports being customized, by subclassing the SecurityCheckPlugin class. For a complex example of doing so, see MediaWikiSecurityCheckPlugin.

Sometimes you have methods in your codebase that alter the taint of a variable. For example, a custom html escaping function should clear the html taint bit. Similarly, sometimes phan-taint-check can get confused and you want to override the taint calculated for a specific function.

You can do this by adding a taint directive in a docblock comment. For example:

Methods also inherit these directives from abstract definitions in ancestor interfaces, but not from concrete implementations in ancestor classes.

Taint directives are prefixed with either @param-taint $parametername or @return-taint. If there are multiple directives they can be separated by a comma. @param-taint is used for either marking how taint is transmitted from the parameter to the methods return value, or when used with exec_ directives, to mark places where parameters are outputted/executed. @return-taint is used to adjust the return value's taint regardless of the input parameters.

The type of directives include:

The value for $TYPE can be one of htmlnoent, html, sql, shell, serialize, custom1, custom2, code, path, regex, sql_numkey, escaped, none, tainted. Most of these are taint categories, except:

The default value for @param-taint is tainted if it's a string (or other dangerous type), and none if it's something like an integer. The default value for @return-taint is allow_override (Which is equivalent to none unless something better can be autodetected).

Instead of annotating methods in your codebase, you can also customize phan-taint-check to have builtin knowledge of method taints. In addition you can extend the plugin to have fairly arbitrary behaviour.

To do this, you override the getCustomFuncTaints() method. This method returns an associative array of fully qualified method names to an array describing how the taint of the return value of the function in terms of its arguments. The numeric keys correspond to the number of an argument, and an 'overall' key adds taint that is not present in any of the arguments. Basically for each argument, the plugin takes the taint of the argument, bitwise AND's it to its entry in the array, and then bitwise OR's the overall key. If any of the keys in the array have an EXEC flags, then an issue is immediately raised if the corresponding taint is fed the function (For example, an output function). The EXEC flags don't work in the 'overall' key.

For example, htmlspecialchars which removes html taint, escapes its argument and returns the escaped value would look like:

Environment variables

The following environment variables affect the plugin. Normally you would not have to adjust these.

License

GNU General Public License, version 2 or later


All versions of phan-taint-check-plugin with dependencies

PHP Build Version
Package Version
Requires phan/phan Version 5.4.3
php Version ^7.4.0 | ^8.0.0
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mediawiki/phan-taint-check-plugin contains the following files

Loading the files please wait ....