-
Notifications
You must be signed in to change notification settings - Fork 46
php: dangerous eval #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sanket-deepsource
merged 1 commit into
DeepSourceCorp:master
from
hrideshmg:php_injection
Feb 24, 2025
Merged
php: dangerous eval #115
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| function test_dangerous_eval() { | ||
| $user_input = $_GET['input']; | ||
|
|
||
| // These should be flagged | ||
| // <expect-error> | ||
| eval($user_input); | ||
|
|
||
| // <expect-error> | ||
| eval("echo " . $user_input . "hi"); | ||
|
|
||
| // String interpolation | ||
| // <expect-error> | ||
| eval("echo $user_input"); | ||
|
|
||
| // Superglobal (outside our control) sources | ||
| // <expect-error> | ||
| eval($_GET['username']); | ||
|
|
||
| // These are safe and should not be flagged | ||
| // constants | ||
| eval('echo "Hello, World!"'); | ||
|
|
||
| } | ||
|
|
||
| function test_edge_cases() { | ||
| // Should not flag eval in variable names | ||
| $evaluation_result = 100; | ||
|
|
||
| // Should not flag commented-out eval | ||
| // eval($user_input); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| language: php | ||
| name: dangerous_eval | ||
| message: "Avoid using eval() with dynamic inputs as it can lead to remote code execution (RCE) vulnerabilities" | ||
| category: security | ||
| severity: critical | ||
|
|
||
| pattern: | | ||
| ;; Match direct eval calls with variable input | ||
| (expression_statement | ||
| (function_call_expression | ||
| function: (name) @function (#eq? @function "eval") | ||
| arguments: (arguments | ||
| (argument | ||
| (variable_name) @user_input | ||
| ) | ||
| ) | ||
| ) | ||
| ) @dangerous_eval | ||
|
|
||
| ;; Match eval calls with string concatenation | ||
| (expression_statement | ||
| (function_call_expression | ||
| function: (name) @function (#eq? @function "eval") | ||
| arguments: (arguments | ||
| (argument | ||
| (binary_expression | ||
| left: [ | ||
| (encapsed_string) | ||
| (binary_expression) | ||
| ] | ||
| right: [ | ||
| (encapsed_string) | ||
| (variable_name) @user_input | ||
| ] | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) @dangerous_eval | ||
|
|
||
| ;; Match eval calls with interpolated strings containing variables | ||
| (expression_statement | ||
| (function_call_expression | ||
| function: (name) @function (#eq? @function "eval") | ||
| arguments: (arguments | ||
| (argument | ||
| (encapsed_string | ||
| (variable_name) @user_input | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) @dangerous_eval | ||
|
|
||
| ;; Match eval calls with superglobal input sources | ||
| (expression_statement | ||
| (function_call_expression | ||
| function: (name) @function (#eq? @function "eval") | ||
| arguments: (arguments | ||
| (argument | ||
| (subscript_expression | ||
| (variable_name (name) @superglobal) | ||
| (#match? @superglobal "^_(GET|POST|REQUEST|COOKIE|SERVER|ENV|FILES|SESSION)$") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) @dangerous_eval | ||
|
|
||
| exclude: | ||
| - "tests/**" | ||
| - "vendor/**" | ||
| - "**/test_*.php" | ||
| - "**/*_test.php" | ||
|
|
||
| description: | | ||
| The use of eval() in PHP without validating the input can lead to the execution | ||
| of arbitrary code, resulting in potential remote code execution (RCE) vulnerabilities. | ||
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.
Uh oh!
There was an error while loading. Please reload this page.