Page MenuHomePhabricator

taint-check has trouble for taintedness of unknown array keys and reports possible false positives
Closed, ResolvedPublic

Description

13:49:09 includes/jobqueue/utils/BacklinkJobUtils.php:102 SecurityCheck-SQLInjection Calling method \BacklinkCache::partition() in \BacklinkJobUtils::partitionBacklinkJob that outputs using tainted argument #1 (`$params['table']`). (Caused by: includes/cache/BacklinkCache.php +443) (Caused by: includes/jobqueue/utils/BacklinkJobUtils.php +90)

This could be a false positive: Variable $params has taintedness: YES


13:49:09 includes/jobqueue/utils/BacklinkJobUtils.php:102 SecurityCheck-SQLInjection Calling method \BacklinkCache::partition() in \BacklinkJobUtils::partitionBacklinkJob that outputs using tainted argument #1 (`$params['table']`). (Caused by: includes/cache/BacklinkCache.php +443) (Caused by: includes/jobqueue/utils/BacklinkJobUtils.php +90)

This could be a false positive: Variable $params has taintedness: YES

The annotation still doesn't print the whole taintedness object. Could you please tryapplying the following hack to vendor/mediawiki/phan-taint-check-plugin/src/SecurityCheckPlugin.php

$msg = "Variable {CODE} has taintedness: {DETAILS}"; // Line 246
echo "\n\n$taint\n\n"; // Add this line

and then re-running phan. It should print the whole shape.

$taint is equal to {DETAILS}, but what about var_export( $var->taintedness )?

SecurityCheckPlugin\Taintedness::__set_state(array(
   'flags' => 43688,
   'dimTaint' =>
  array (
    'namespace' =>
    SecurityCheckPlugin\Taintedness::__set_state(array(
       'flags' => 0,
       'dimTaint' =>
      array (
      ),
       'unknownDimsTaint' => 0,
    )),
    'title' =>
    SecurityCheckPlugin\Taintedness::__set_state(array(
       'flags' => 0,
       'dimTaint' =>
      array (
      ),
       'unknownDimsTaint' => 0,
    )),
    'requestId' =>
    SecurityCheckPlugin\Taintedness::__set_state(array(
       'flags' => 43688,
       'dimTaint' =>
      array (
      ),
       'unknownDimsTaint' => 0,
    )),
  ),
   'unknownDimsTaint' => 0,
))

In Job.php:

$this->params = $params + [ 'requestId' => WebRequest::getRequestId() ];

When comment out that line, everything is fine ...


$taint is equal to {DETAILS}, but what about var_export( $var->taintedness )?

Oh yes, I meant $var->taintedness. No need to var_export it though, it has a __toString() which pretty-prints the object.

[ object snip ]

Seems like it's picking up taintedness in an offset it can't resolve.

In Job.php:

$this->params = $params + [ 'requestId' => WebRequest::getRequestId() ];

When comment out that line, everything is fine ...

I'd have to investigate, could you please copy these comments to a new task while I take a look?


pretty print:

{
    Own taint: YES
    Unknown keys: NONE
    Keys: {
        namespace => {
            Own taint: NONE
            Unknown keys: NONE
            Keys: {}
        }
        title => {
            Own taint: NONE
            Unknown keys: NONE
            Keys: {}
        }
        requestId => {
            Own taint: YES
            Unknown keys: NONE
            Keys: {}
        }
    }
}

Event Timeline

Umherirrender renamed this task from taint-check has trouble for taintness for arrays to taint-check has trouble for taintedness of arrays or array-keys.Nov 28 2020, 1:16 AM

WebRequest::getRequestId() is using $_SERVER['UNIQUE_ID'] which means the return could contain user input?

But the first report was about the key 'table', which is not part of this taint print and that is the unknown offset.

Umherirrender renamed this task from taint-check has trouble for taintedness of arrays or array-keys to taint-check has trouble for taintedness of unknown array keys and reports possible false positives.Nov 28 2020, 1:21 AM

Change 644012 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/tools/phan/SecurityCheckPlugin@master] Exclude some taint bits in case of unknown keys

https://gerrit.wikimedia.org/r/644012

The patch above solves part of the issue, but it will remain on MediaWiki core. I got tired after a few hours of debugging, but this is related to the max depth being reached (see https://gerrit.wikimedia.org/r/c/mediawiki/tools/phan/SecurityCheckPlugin/+/601336), which I don't think can be resolved soon, so suppressing is fine.

Change 644049 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/core@master] Suppress taint-check issue in BacklinkJobUtils

https://gerrit.wikimedia.org/r/644049

Change 644049 merged by jenkins-bot:
[mediawiki/core@master] Suppress taint-check issue in BacklinkJobUtils

https://gerrit.wikimedia.org/r/644049

Change 644012 merged by jenkins-bot:
[mediawiki/tools/phan/SecurityCheckPlugin@master] Exclude some taint bits in case of unknown keys

https://gerrit.wikimedia.org/r/644012