1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Improve file-based suppression of taints

This commit is contained in:
Brown 2020-09-20 19:37:25 -04:00 committed by Daniil Gentili
parent dbe4b4c708
commit b9c33aaa03
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
21 changed files with 15 additions and 59 deletions

View File

@ -46,9 +46,7 @@ class EchoAnalyzer
);
}
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if ($statements_analyzer->taint_graph) {
$call_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
$echo_param_sink = Sink::getForMethodArgument(

View File

@ -203,7 +203,6 @@ class ArrayAnalyzer
}
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
if ($item_value_type = $statements_analyzer->node_data->getType($item->value)) {

View File

@ -1147,11 +1147,7 @@ class InstancePropertyAssignmentAnalyzer
Type\Union $assignment_value_type,
Context $context
) : void {
$codebase = $statements_analyzer->getCodebase();
if (!$statements_analyzer->taint_graph
|| !$codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if (!$statements_analyzer->taint_graph) {
return;
}

View File

@ -878,9 +878,7 @@ class AssignmentAnalyzer
return $context->vars_in_scope[$var_id];
}
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if ($statements_analyzer->taint_graph) {
$taint_graph = $statements_analyzer->taint_graph;
if ($context->vars_in_scope[$var_id]->parent_nodes) {
@ -1200,7 +1198,6 @@ class AssignmentAnalyzer
$statements_analyzer->node_data->setType($stmt, clone $context->vars_in_scope[$array_var_id]);
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
$stmt_left_type = $statements_analyzer->node_data->getType($stmt->var);

View File

@ -104,10 +104,7 @@ class BinaryOpAnalyzer
$stmt_type = $result_type;
}
$codebase = $statements_analyzer->getCodebase();
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
$stmt_left_type = $statements_analyzer->node_data->getType($stmt->left);

View File

@ -1220,7 +1220,6 @@ class ArgumentAnalyzer
$codebase = $statements_analyzer->getCodebase();
if (!$statements_analyzer->taint_graph
|| !$codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
|| \in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
return $input_type;

View File

@ -1059,10 +1059,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
FunctionLikeStorage $function_storage,
Type\Union $stmt_type
) : void {
$codebase = $statements_analyzer->getCodebase();
if (!$statements_analyzer->taint_graph
|| !$codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
|| \in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
return;

View File

@ -228,7 +228,6 @@ class MethodCallReturnTypeFetcher
if ($statements_analyzer->taint_graph
&& $declaring_method_id
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
$method_storage = $codebase->methods->getStorage(

View File

@ -641,7 +641,6 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
}
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
&& ($stmt_type = $statements_analyzer->node_data->getType($stmt))
) {

View File

@ -1423,10 +1423,7 @@ class StaticCallAnalyzer extends CallAnalyzer
Type\Union $return_type_candidate,
?\Psalm\Storage\MethodStorage $method_storage
) : void {
$codebase = $statements_analyzer->getCodebase();
if (!$statements_analyzer->taint_graph
|| !$codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
|| \in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
return;

View File

@ -15,8 +15,6 @@ class EncapsulatedStringAnalyzer
PhpParser\Node\Scalar\Encapsed $stmt,
Context $context
) : bool {
$codebase = $statements_analyzer->getCodebase();
$stmt_type = Type::getString();
foreach ($stmt->parts as $part) {
@ -35,7 +33,6 @@ class EncapsulatedStringAnalyzer
);
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
$var_location = new CodeLocation($statements_analyzer, $part);

View File

@ -23,11 +23,8 @@ class EvalAnalyzer
$expr_type = $statements_analyzer->node_data->getType($stmt->expr);
if ($expr_type) {
$codebase = $statements_analyzer->getCodebase();
if ($statements_analyzer->taint_graph
&& $expr_type->parent_nodes
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
$arg_location = new CodeLocation($statements_analyzer->getSource(), $stmt->expr);

View File

@ -27,11 +27,7 @@ class ExitAnalyzer
return false;
}
$codebase = $statements_analyzer->getCodebase();
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if ($statements_analyzer->taint_graph) {
$call_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
$echo_param_sink = Sink::getForMethodArgument(

View File

@ -312,12 +312,9 @@ class ArrayFetchAnalyzer
Type\Union $stmt_type,
Type\Union $offset_type
) : void {
$codebase = $statements_analyzer->getCodebase();
if ($statements_analyzer->taint_graph
&& ($stmt_var_type = $statements_analyzer->node_data->getType($var))
&& $stmt_var_type->parent_nodes
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if (\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())) {
$stmt_var_type->parent_nodes = [];

View File

@ -1193,11 +1193,7 @@ class InstancePropertyFetchAnalyzer
\Psalm\Storage\ClassLikeStorage $class_storage,
bool $in_assignment
) : void {
$codebase = $statements_analyzer->getCodebase();
if (!$statements_analyzer->taint_graph
|| !$codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if (!$statements_analyzer->taint_graph) {
return;
}

View File

@ -393,10 +393,7 @@ class VariableFetchAnalyzer
Type\Union $type,
PhpParser\Node\Expr\Variable $stmt
) : void {
$codebase = $statements_analyzer->getCodebase();
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
if ($var_name === '$_GET'

View File

@ -104,7 +104,6 @@ class IncludeAnalyzer
if ($stmt_expr_type
&& $statements_analyzer->taint_graph
&& $stmt_expr_type->parent_nodes
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
&& !\in_array('TaintedInput', $statements_analyzer->getSuppressedIssues())
) {
$arg_location = new CodeLocation($statements_analyzer->getSource(), $stmt->expr);

View File

@ -25,9 +25,7 @@ class PrintAnalyzer
return false;
}
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if ($statements_analyzer->taint_graph) {
$call_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
$print_param_sink = Sink::getForMethodArgument(

View File

@ -189,9 +189,7 @@ class ReturnAnalyzer
$source->getParentFQCLN()
);
if ($statements_analyzer->taint_graph
&& $codebase->config->trackTaintsInPath($statements_analyzer->getFilePath())
) {
if ($statements_analyzer->taint_graph) {
self::handleTaints(
$statements_analyzer,
$stmt,

View File

@ -135,7 +135,9 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource
$this->file_analyzer = $source->getFileAnalyzer();
$this->codebase = $source->getCodebase();
$this->node_data = $node_data;
$this->taint_graph = $this->codebase->taint_graph ? new TaintGraph() : null;
$this->taint_graph = $this->codebase->taint_graph
? new TaintGraph()
: null;
}
/**
@ -191,7 +193,11 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource
}
}
if ($root_scope && $this->taint_graph && $this->codebase->taint_graph) {
if ($root_scope
&& $this->taint_graph
&& $this->codebase->taint_graph
&& $codebase->config->trackTaintsInPath($this->getFilePath())
) {
$this->codebase->taint_graph->addGraph($this->taint_graph);
}

View File

@ -118,10 +118,7 @@ class FilterVarReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturnTy
$filter_type = Type::getMixed();
}
$codebase = $statements_source->getCodebase();
if ($statements_source->taint_graph
&& $codebase->config->trackTaintsInPath($statements_source->getFilePath())
&& !\in_array('TaintedInput', $statements_source->getSuppressedIssues())
) {
$function_return_sink = TaintNode::getForMethodReturn(