Commit facfe537 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Contrôle de prévention de boucles infinies pour l'Extractor

Suppression de l'utilisation des __toString, trop "magique"
parent 776bf5b0
Loading
Loading
Loading
Loading
Loading
+8 −9
Changes for src/Axios/AxiosExtractor.php: 8 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ use Doctrine\ORM\Query;

class AxiosExtractor
{
    public static $loopControl = 50;

    const DATETIME_FORMAT = 'Y-m-d\TH:i:s.u\Z'; // timestamp ISO 8601 pour HTML5

    protected array $triggers = [];
@@ -53,6 +55,12 @@ class AxiosExtractor

    protected function extractObject($data, array $properties, string $path = ''): array
    {
        // contrôle de boucle récursive, afin de ne pas saturer la mémoire...
        if (substr_count($path, '/') >= self::$loopControl){
            //return [];
            throw new \Exception("AxiosExtractor has detected a possible infinite loop, and aborted your script with a stack depth of '".self::$loopControl."' frames");
        }

        $result = [];

        $props = ['id'];
@@ -64,10 +72,6 @@ class AxiosExtractor
                        $props[] = $prop;
                    }
                }
            } else {
                if (method_exists($data, '__toString')) {
                    $props[] = '__toString';
                }
            }
        } else {
            foreach ($properties as $prop) {
@@ -100,11 +104,6 @@ class AxiosExtractor
            }
        }

        if (array_key_exists('__toString', $result)) {
            $result['libelle'] = $result['__toString'];
            unset($result['__toString']);
        }

        return $result;
    }