fix(safety): exclude PDO method calls from exec() false-positive detection - #27
Closed
elhussienysabry wants to merge 1 commit into
Closed
elhussienysabry wants to merge 1 commit into
elhussienysabry wants to merge 1 commit into
Conversation
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
Contributor
Author
|
Closing to resubmit with correct author identity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #19
The PHP safety scanner was reporting false positives for legitimate PDO method calls like
$pdo->exec()andPDO::exec(), flagging them as dynamic code execution findings.Root Cause
The
exec()danger pattern in_DANGEROUS_PATTERNSused a simple word-boundary regex: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:exec('cmd')exec(user_code)$pdo->exec($sql)$connection->exec($sql)PDO::exec($stmt)Changes
semantic_code_intelligence/llm/safety.py— updated theexec()regex patternsemantic_code_intelligence/tests/test_phase12.py— added 6 regression tests