Skip to content

Commit

Permalink
feat(ban): Add ban on print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kollross committed Feb 25, 2022
1 parent d3bca55 commit f68d448
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ master
------

* Added rule to ban shell execution via backticks
* Added rule to ban print statements

v1.0.0
------
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ parameters:
- system
- var_dump
# enable detection of print statements
-
type: Expr_Print
functions: null
# enable detection of shell execution by backticks
-
type: Expr_ShellExec
Expand Down
5 changes: 5 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ parameters:
- system
- var_dump

# enable detection of print statements
-
type: Expr_Print
functions: null

# enable detection of shell execution by backticks
-
type: Expr_ShellExec
Expand Down
3 changes: 3 additions & 0 deletions snippets/print.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

print 'test print';
2 changes: 1 addition & 1 deletion snippets/print_r.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

print_r('');
print_r('test print_r');
3 changes: 3 additions & 0 deletions tests/Rules/BannedNodesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PhpParser\Node\Expr\Exit_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Include_;
use PhpParser\Node\Expr\Print_;
use PhpParser\Node\Expr\ShellExec;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
Expand Down Expand Up @@ -53,6 +54,7 @@ protected function setUp(): void
['type' => 'Expr_Eval'],
['type' => 'Expr_Exit'],
['type' => 'Expr_FuncCall', 'functions' => ['debug_backtrace', 'dump']],
['type' => 'Expr_Print'],
['type' => 'Expr_ShellExec'],
]);
$this->scope = $this->createMock(Scope::class);
Expand Down Expand Up @@ -136,6 +138,7 @@ public function getHandledNodes(): \Generator
{
yield [new Eval_($this->createMock(Expr::class))];
yield [new Exit_()];
yield [new Print_($this->createMock(Expr::class))];
yield [new ShellExec([''])];
}
}

0 comments on commit f68d448

Please sign in to comment.