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:
parent
dbe4b4c708
commit
b9c33aaa03
@ -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(
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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(
|
||||
|
@ -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))
|
||||
) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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(
|
||||
|
@ -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 = [];
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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);
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user