testable-eu / sast-testability-patterns

Testability Pattern Catalogs for SAST
https://owasp.org/www-project-testability-patterns-for-web-applications/
Apache License 2.0
29 stars 2 forks source link

Update TP: PHP - 6_coalesce #36

Closed felix-20 closed 1 year ago

felix-20 commented 1 year ago

Testability pattern

6_coalesce

Problem statement

There is not really a problem with the existing pattern, I would just like to propose a new instance for that pattern. The null coalescing operator in php can also be used in combination with '=', this null coalescing assignment operator was introduced in PHP 7.4 (source). I think it might be interesting to see, if the SAST tool is able to recognize this.

Proposed changes

Introduce instance 3 with the following PHP code:

$a = $_GET["p1"]; // source
$b = null;
$b ??= $a; //tarpit: $b assigned to $a as the 1st param of coalescing is null
echo $b; // sink

Other

The discovery rule can be the same, as for the other two instances.

compaluca commented 1 year ago

It looks good to me. We can proceed with this improvement. Thanks