From f68d4486261f8e99f7a1bebb94d6cbf06fd4543d Mon Sep 17 00:00:00 2001 From: Christian Kollross Date: Fri, 25 Feb 2022 15:06:11 +0100 Subject: [PATCH] feat(ban): Add ban on print statements --- CHANGELOG.md | 1 + README.md | 5 +++++ extension.neon | 5 +++++ snippets/print.php | 3 +++ snippets/print_r.php | 2 +- tests/Rules/BannedNodesRuleTest.php | 3 +++ 6 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 snippets/print.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aca616..77aa2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ master ------ * Added rule to ban shell execution via backticks +* Added rule to ban print statements v1.0.0 ------ diff --git a/README.md b/README.md index 13060c4..03642a6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/extension.neon b/extension.neon index 9bdad7b..1ebe93b 100644 --- a/extension.neon +++ b/extension.neon @@ -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 diff --git a/snippets/print.php b/snippets/print.php new file mode 100644 index 0000000..813bc16 --- /dev/null +++ b/snippets/print.php @@ -0,0 +1,3 @@ + 'Expr_Eval'], ['type' => 'Expr_Exit'], ['type' => 'Expr_FuncCall', 'functions' => ['debug_backtrace', 'dump']], + ['type' => 'Expr_Print'], ['type' => 'Expr_ShellExec'], ]); $this->scope = $this->createMock(Scope::class); @@ -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([''])]; } }