diff --git a/semantic_code_intelligence/llm/safety.py b/semantic_code_intelligence/llm/safety.py index 3b4e900..b6b9b79 100644 --- a/semantic_code_intelligence/llm/safety.py +++ b/semantic_code_intelligence/llm/safety.py @@ -23,7 +23,7 @@ (r"\brm\s+-rf\s+/", "Destructive rm -rf / command"), # Dynamic code execution (r"\beval\s*\(", "eval() call — avoid dynamic code execution"), - (r"\bexec\s*\(", "exec() call — avoid dynamic code execution"), + (r"(?)(?exec() is a PDO method call and must NOT be flagged.""" + assert self.validator.is_safe("$pdo->exec('CREATE TABLE foo (id INT)')") + + def test_connection_arrow_exec_not_flagged(self): + """PHP $connection->exec() is a PDO method call and must NOT be flagged.""" + assert self.validator.is_safe("$connection->exec($sql)") + + def test_pdo_static_exec_not_flagged(self): + """PHP PDO::exec() static call must NOT be flagged.""" + assert self.validator.is_safe("PDO::exec($statement)") + + def test_pdo_exec_multiline_not_flagged(self): + """Multi-line PHP code using PDO method calls should pass the safety check.""" + php_code = ( + "$pdo = new PDO($dsn, $user, $pass);\n" + "$pdo->exec('SET NAMES utf8mb4');\n" + "$connection->exec($migrationSql);\n" + ) + assert self.validator.is_safe(php_code) + # ========================================================================= # VSCode streaming context tests