Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion semantic_code_intelligence/llm/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"(?<!->)(?<!::)\bexec\s*\(", "exec() call — avoid dynamic code execution"),
(r"\b__import__\s*\(", "Dynamic __import__() — use explicit imports"),
# SQL injection risk
(r"DROP\s+TABLE|DROP\s+DATABASE", "SQL DROP statement — potential data loss"),
Expand Down
31 changes: 31 additions & 0 deletions semantic_code_intelligence/tests/test_phase12.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,37 @@ def test_validate_report_details(self):
assert any("XSS" in d for d in descs)
assert any("MD5" in d for d in descs)

# --- Issue #19: PDO::exec() false-positive regression tests ---

def test_exec_global_still_flagged(self):
"""Standalone exec() (global PHP / Python function) must still be caught."""
assert not self.validator.is_safe("exec('ls -la')")

def test_exec_global_python_still_flagged(self):
"""Python exec() with dynamic code must still be caught."""
assert not self.validator.is_safe("exec(user_code)")

def test_pdo_arrow_exec_not_flagged(self):
"""PHP $pdo->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
Expand Down