Skip to content

fix(safety): exclude PDO method calls from exec() false-positive detection - #27

Closed
elhussienysabry wants to merge 1 commit into
M9nx:mainfrom
elhussienysabry:fix/issue-19-pdo-exec-false-positive
Closed

elhussienysabry wants to merge 1 commit into
M9nx:mainfrom
elhussienysabry:fix/issue-19-pdo-exec-false-positive

Conversation

@elhussienysabry

Copy link
Copy Markdown
Contributor

Summary

Fixes #19

The PHP safety scanner was reporting false positives for legitimate PDO method calls like $pdo->exec() and PDO::exec(), flagging them as dynamic code execution findings.

Root Cause

The exec() danger pattern in _DANGEROUS_PATTERNS used a simple word-boundary regex:

(r"\bexec\s*\(", "exec() call — avoid dynamic code execution")

This matched any occurrence of exec( in a line — including PHP object method calls like $connection->exec($sql) — because it did not distinguish between the global function and method-call syntax.

Fix

Added negative lookbehinds for -> and :: operators so only standalone function invocations are flagged:

(r"(?<!->)(?<!::)\bexec\s*\(", "exec() call — avoid dynamic code execution")
Pattern Before After
exec('cmd') ⛔ flagged ⛔ flagged (correct)
exec(user_code) ⛔ flagged ⛔ flagged (correct)
$pdo->exec($sql) ❌ false positive ✅ allowed
$connection->exec($sql) ❌ false positive ✅ allowed
PDO::exec($stmt) ❌ false positive ✅ allowed

Changes

  • semantic_code_intelligence/llm/safety.py — updated the exec() regex pattern
  • semantic_code_intelligence/tests/test_phase12.py — added 6 regression tests

Resolves #19

The exec() danger pattern used a simple word-boundary regex that
matched any call whose name ended in 'exec', including PHP PDO
method calls such as $pdo->exec() and PDO::exec().

Apply negative look-behinds for '->' and '::' so that only standalone
function invocations (the global PHP exec() / Python exec()) are flagged.
Method-call forms are safe SQL-execution APIs and must not generate
false-positive safety warnings.

Changes:
- semantic_code_intelligence/llm/safety.py: update exec() pattern from
  \bexec\s*\( to (?<!->)(?<!::)\bexec\s*\(
- semantic_code_intelligence/tests/test_phase12.py: add 6 regression
  tests verifying global exec() is still caught while $pdo->exec(),
  $connection->exec(), and PDO::exec() are not flagged
@elhussienysabry

Copy link
Copy Markdown
Contributor Author

Closing to resubmit with correct author identity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PHP safety scan flags PDO::exec() as dynamic code execution

2 participants