Skip to content

Commit f68d448

Browse files
author
Christian Kollross
committed
feat(ban): Add ban on print statements
1 parent d3bca55 commit f68d448

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ master
55
------
66

77
* Added rule to ban shell execution via backticks
8+
* Added rule to ban print statements
89

910
v1.0.0
1011
------

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ parameters:
6464
- system
6565
- var_dump
6666
67+
# enable detection of print statements
68+
-
69+
type: Expr_Print
70+
functions: null
71+
6772
# enable detection of shell execution by backticks
6873
-
6974
type: Expr_ShellExec

extension.neon

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ parameters:
4141
- system
4242
- var_dump
4343

44+
# enable detection of print statements
45+
-
46+
type: Expr_Print
47+
functions: null
48+
4449
# enable detection of shell execution by backticks
4550
-
4651
type: Expr_ShellExec

snippets/print.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
print 'test print';

snippets/print_r.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
print_r('');
3+
print_r('test print_r');

tests/Rules/BannedNodesRuleTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PhpParser\Node\Expr\Exit_;
2121
use PhpParser\Node\Expr\FuncCall;
2222
use PhpParser\Node\Expr\Include_;
23+
use PhpParser\Node\Expr\Print_;
2324
use PhpParser\Node\Expr\ShellExec;
2425
use PhpParser\Node\Expr\Variable;
2526
use PhpParser\Node\Name;
@@ -53,6 +54,7 @@ protected function setUp(): void
5354
['type' => 'Expr_Eval'],
5455
['type' => 'Expr_Exit'],
5556
['type' => 'Expr_FuncCall', 'functions' => ['debug_backtrace', 'dump']],
57+
['type' => 'Expr_Print'],
5658
['type' => 'Expr_ShellExec'],
5759
]);
5860
$this->scope = $this->createMock(Scope::class);
@@ -136,6 +138,7 @@ public function getHandledNodes(): \Generator
136138
{
137139
yield [new Eval_($this->createMock(Expr::class))];
138140
yield [new Exit_()];
141+
yield [new Print_($this->createMock(Expr::class))];
139142
yield [new ShellExec([''])];
140143
}
141144
}

0 commit comments

Comments
 (0)