PHPackages                             mediawiki/phan-taint-check-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. mediawiki/phan-taint-check-plugin

ActiveLibrary[Security](/categories/security)

mediawiki/phan-taint-check-plugin
=================================

A Phan plugin to do security checking

9.1.0(2mo ago)27777.0k↑21.7%42GPL-2.0-or-laterPHPPHP &gt;=8.1.0

Since Dec 6Pushed 2mo ago11 watchersCompare

[ Source](https://github.com/wikimedia/mediawiki-tools-phan-SecurityCheckPlugin)[ Packagist](https://packagist.org/packages/mediawiki/phan-taint-check-plugin)[ RSS](/packages/mediawiki-phan-taint-check-plugin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (12)Versions (36)Used By (2)

Phan Security Check Plugin
==========================

[](#phan-security-check-plugin)

This is a plugin to [Phan](https://github.com/phan/phan) to try and detect security issues (such as [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting)). 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](https://doc.wikimedia.org/mediawiki-tools-phan-SecurityCheckPlugin/master/demos/) is available.

Usage
-----

[](#usage)

### Install

[](#install)

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

```

### Usage

[](#usage-1)

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 .

#### Manual

[](#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:

```
   'quick_mode' => false
```

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

[](#standalone)

You can run taint-check via:

```
$ ./vendor/bin/seccheck

```

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

```
  "scripts": {
     "seccheck": "seccheck"
  }
```

Note that false positives are disabled by default.

Plugin output
-------------

[](#plugin-output)

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

- `SecurityCheck-XSS`
- `SecurityCheck-SQLInjection`
- `SecurityCheck-ShellInjection`
- `SecurityCheck-PHPSerializeInjection` - For when someone does `unserialize( $_GET['d'] );`This issue type seems to have a high false positive rate currently.
- `SecurityCheck-CUSTOM1` - To allow people to have custom taint types
- `SecurityCheck-CUSTOM2` - ditto
- `SecurityCheck-DoubleEscaped` - Detecting that HTML is being double escaped
- `SecurityCheck-RCE` - Remote code execution, e.g. `eval( $_GET['foo'] )`
- `SecurityCheck-PathTraversal` - Path traversal, e.g. `require $_GET['foo']`
- `SecurityCheck-ReDoS` - Regular expression denial of service (ReDoS), e.g. `preg_match( $_GET['foo'], 'foo')`
- `SecurityCheck-LikelyFalsePositive` - A potential issue, but probably not. Mostly happens when the plugin gets confused.

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
----------------------------

[](#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:

```
  /**
   * @param-taint $stuffToPrint none
   */
  public function printMyStuff( string $stuffToPrint ) {
    echo $stuffToPrint;
  }
```

When debugging security issues, you can use:

```
'@phan-debug-var-taintedness $varname';

```

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
-------------------

[](#notable-limitations)

### General limitations

[](#general-limitations)

- When an issue is output, the plugin tries to include details about what line originally caused the issue. Usually it works, but sometimes it gives misleading/wrong information
- The plugin won't recognize things that do custom escaping. If you have custom escaping methods, you must add annotations to its docblock so that the plugin can recognize it. See the Customizing section.
- Phan does not currently have an API for accessing subclasses for a given class. Therefore the SecurityCheckPlugin cannot accommodate certain data flows for subclasses that should obviously be considered tainted. The workaround for this is to mark any relevant subclass functions as `@return-taint html`.

### MediaWiki specific limitations

[](#mediawiki-specific-limitations)

- With pass by reference parameters to MediaWiki hooks, sometimes the line number is the hook call in MediaWiki core, instead of the hook subscriber in the extension that caused the issue.
- The plugin can only validate the fifth (`$options`) and sixth (`$join_cond`) of MediaWiki's `IDatabase::select()` if its provided directly as an array literal, or directly returned as an array literal from a `getQueryInfo()`method.

Customizing
-----------

[](#customizing)

The plugin supports being customized, by subclassing the [SecurityCheckPlugin](src/SecurityCheckPlugin.php)class. For a complex example of doing so, see [MediaWikiSecurityCheckPlugin](MediaWikiSecurityCheckPlugin.php).

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:

```
/**
 * My function description
 *
 * @param string $html the text to be escaped
 * @param-taint $html escapes_html
 */
function escapeHtml( $html ) {
}
```

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:

- `exec_$TYPE` - If a parameter is marked as `exec_$TYPE` then feeding that parameter a value with `$TYPE` taint will result in a warning triggered. Typically you would use this when a function that outputs or executes its parameter
- `escapes_$TYPE` - Used for parameters where the function escapes and then returns the parameter. So `escapes_sql` would clear the sql taint bit, but leave other taint bits alone.
- `onlysafefor_$TYPE` - For use in `@return-taint`, marks the return type as safe for a specific `$TYPE` but unsafe for the other types.
- `$TYPE` - if just the type is specified in a parameter, it is bitwised AND with the input variable's taint. Normally you wouldn't want to do this, but can be useful when `$TYPE` is `none` to specify that the parameter is not used to generate the return value. In an `@return` this could be used to enumerate which taint flags the return value has, which is usually only useful when specified as `tainted` to say it has all flags.
- `array_ok` - special purpose flag to say ignore tainted arguments if they are in an array.
- `allow_override` - Special purpose flag to specify that that taint annotation should be overridden by phan-taint-check if it can detect a specific taint.

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:

- `htmlnoent` - like `html` but disable double escaping detection that gets used with `html`. When `escapes_html` is specified, escaped automatically gets added to `@return`, and `exec_escaped` is added to `@param`. Similarly `onlysafefor_html` is equivalent to `onlysafefor_htmlnoent,escaped`.
- `none` - Means no taint
- `tainted` - Means all taint categories except special categories (equivalent to `SecurityCheckPlugin::YES_TAINT`)
- `escaped` - Is used to mean the value is already escaped (To track double escaping)
- `sql_numkey` - Is fairly special purpose for MediaWiki. It ignores taint in arrays if they are for associative keys.

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](https://secure.php.net/htmlspecialchars) which removes html taint, escapes its argument and returns the escaped value would look like:

```
'htmlspecialchars' => [
	( self::YES_TAINT & ~self::HTML_TAINT ) | self::ESCAPED_EXEC_TAINT,
	'overall' => self::ESCAPED,
];
```

Environment variables
---------------------

[](#environment-variables)

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

- `SECURITY_CHECK_EXT_PATH` - Path to directory containing `extension.json`/`skin.json` when in MediaWiki mode. If not set assumes the project root directory.
- `SECCHECK_DEBUG` - File to output extra debug information (If running from `shell`, `/dev/stderr` is convenient)

License
-------

[](#license)

[GNU General Public License, version 2 or later](COPYING)

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity49

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 73.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~88 days

Recently: every ~61 days

Total

35

Last Release

74d ago

Major Versions

4.0.0 → 5.0.02023-08-29

5.0.0 → 6.0.02024-02-02

6.2.1 → 7.0.02025-08-07

7.0.0 → 8.0.02025-11-06

8.0.0 → 9.0.02026-02-09

PHP version history (6 changes)1.0.0PHP ~7.0.0

2.0.0PHP ^7.0.0

3.0.0PHP ^7.2.0

3.1.1PHP ^7.2.0 | ^8.0.0

5.0.0PHP ^7.4.0 | ^8.0.0

7.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

---

Top Contributors

[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (541 commits)")[![bawolff](https://avatars.githubusercontent.com/u/6529932?v=4)](https://github.com/bawolff "bawolff (110 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (32 commits)")[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (15 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (9 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (8 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (6 commits)")[![sbassett29](https://avatars.githubusercontent.com/u/5025626?v=4)](https://github.com/sbassett29 "sbassett29 (4 commits)")[![MarcoAurelioWM](https://avatars.githubusercontent.com/u/30000615?v=4)](https://github.com/MarcoAurelioWM "MarcoAurelioWM (3 commits)")[![MatmaRex](https://avatars.githubusercontent.com/u/160413?v=4)](https://github.com/MatmaRex "MatmaRex (3 commits)")[![bd808](https://avatars.githubusercontent.com/u/6469?v=4)](https://github.com/bd808 "bd808 (1 commits)")[![nikitavbv](https://avatars.githubusercontent.com/u/24596921?v=4)](https://github.com/nikitavbv "nikitavbv (1 commits)")[![nomoa](https://avatars.githubusercontent.com/u/5939211?v=4)](https://github.com/nomoa "nomoa (1 commits)")[![KleinMuci](https://avatars.githubusercontent.com/u/84108018?v=4)](https://github.com/KleinMuci "KleinMuci (1 commits)")[![cscott](https://avatars.githubusercontent.com/u/156080?v=4)](https://github.com/cscott "cscott (1 commits)")[![skizzerz](https://avatars.githubusercontent.com/u/72652?v=4)](https://github.com/skizzerz "skizzerz (1 commits)")[![TysonAndre](https://avatars.githubusercontent.com/u/1904430?v=4)](https://github.com/TysonAndre "TysonAndre (1 commits)")[![Albert221](https://avatars.githubusercontent.com/u/4085280?v=4)](https://github.com/Albert221 "Albert221 (1 commits)")

---

Tags

phansecurity-auditstatic-analysistaint-analysisphpsecuritystaticanalyzerphantaint

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mediawiki-phan-taint-check-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/mediawiki-phan-taint-check-plugin/health.svg)](https://phpackages.com/packages/mediawiki-phan-taint-check-plugin)
```

###  Alternatives

[typo3/phar-stream-wrapper

Interceptors for PHP's native phar:// stream handling

5938.0M8](/packages/typo3-phar-stream-wrapper)[asbiin/laravel-webauthn

Laravel Webauthn support

309574.8k](/packages/asbiin-laravel-webauthn)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
