Skip to content

Commit

Permalink
Fix compliance with PHPCS
Browse files Browse the repository at this point in the history
PHPCS has specific naming and directory layout requirements for external standards which the `Security` standard did not comply with.

While things sort of worked with the symlink hack, the net effect was:
- The PHPCS autoloader did not work.
- None of the PHPCS ruleset configuration options worked as PHPCS could not match sniffs to files.
- Some sniffs would never load.

This PR fixes this by:
1. Setting the base namespace to `PHPCS_SecurityAudit\Security` and annotating this in the `ruleset.xml` file in the correct manner.
2. Fixing all namespaces and uses thereof throughout the codebase.
3. Fixing the `Drupal8/Utils.php` file which was missing the namespace and was still referring to an out-of-date class name to extend.
4. Fixing the namespace names and file names of the CVE sniffs.
    - The namespace of a sniff has to reflect its path in the standard.
    - The file name has to reflect the name of the sniff.
5. Fixing the names of the CVE sniffs in the example rulesets
6. Removing the symlink file and all references to it.
    Instead `require` the [DealerDirect Composer PHPCS plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer) which will sort out the `installed_paths` for PHPCS .
7. Setting the minimum PHPCS version to `3.0.2` as prior to that external standards weren't fully supported in the 3.x branch.
8. Removing the `autoload` section in `composer.json`. This is no longer needed and in certain situations can cause conflicts/fatal errors.

References:
* https://github.com/squizlabs/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial
* https://github.com/squizlabs/PHP_CodeSniffer/wiki/Version-3.0-Upgrade-Guide
* squizlabs/PHP_CodeSniffer#2481 (comment)
* squizlabs/PHP_CodeSniffer#2606
* squizlabs/PHP_CodeSniffer#1469
* https://github.com/Dealerdirect/phpcodesniffer-composer-installer

Fixes 47
  • Loading branch information
jrfnl committed Feb 18, 2020
1 parent 68a6c53 commit c36e8c6
Show file tree
Hide file tree
Showing 44 changed files with 99 additions and 125 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ RUN addgroup -S tool && adduser -S -G tool tool && \
# Install phpcs-security-audit
RUN composer global require pheromone/phpcs-security-audit
WORKDIR /tmp
RUN sh ./vendor/pheromone/phpcs-security-audit/symlink.sh

# change user
USER tool
Expand Down
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@ Install

Requires [PHP CodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/) version 3.x with PHP 5.4 or higher.

Because of the way PHP CodeSniffer works, you need to put the `Security/` folder from phpcs-security-audit in `/usr/share/php/PHP/CodeSniffer/Standards` or do a symlink to it.

The easiest way to install is to git clone and use composer that will create the symlink for you:
```
composer install
./vendor/bin/phpcs --standard=example_base_ruleset.xml tests.php
```

The package is also on [Packagist](https://packagist.org/packages/pheromone/phpcs-security-audit):
The easiest way to install is using [Composer](https://getcomposer.org/):
```
composer require pheromone/phpcs-security-audit
sh vendor/pheromone/phpcs-security-audit/symlink.sh
composer require --dev pheromone/phpcs-security-audit
./vendor/bin/phpcs --standard=./vendor/pheromone/phpcs-security-audit/example_base_ruleset.xml ./vendor/pheromone/phpcs-security-audit/tests.php
```

This will also install the [DealerDirect Composer PHPCS plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer/) which will register the `Security` standard with PHP_CodeSniffer.

It is also possible to install this based on a git clone. In that case, you will need to [register the package with PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths) yourself.

If you want to integrate it all with Jenkins, go see http://jenkins-php.org/ for extensive help.


Expand All @@ -44,14 +39,14 @@ Usage

Simply point to any XML ruleset file and a folder:
```
phpcs --extensions=php,inc,lib,module,info --standard=example_base_ruleset.xml /your/php/files/
phpcs --extensions=php,inc,lib,module,info --standard=./vendor/pheromone/phpcs-security-audit/example_base_ruleset.xml /your/php/files/
```

Specifying extensions is important since for example PHP code is within .module files in Drupal.

To have a quick example of output you can use the provided tests.php file:
```
$ phpcs --extensions=php,inc,lib,module,info --standard=example_base_ruleset.xml tests.php
$ phpcs --extensions=php,inc,lib,module,info --standard=./vendor/pheromone/phpcs-security-audit/example_base_ruleset.xml ./vendor/pheromone/phpcs-security-audit/tests.php
FILE: tests.php
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -85,7 +80,7 @@ These global parameters are used in many rules:
* ParanoiaMode: set to 1 to add more checks. 0 for less.
* CmsFramework: set to the name of a folder containings rules and Utils.php (such as Drupal7, Symfony2).

They can be setted in the XML files or in command line for permanent config with `--config-set` or at runtime with `--runtime-set`. Note that the XML override all CLI options so remove it if you want to use it. The CLI usage is as follow `phpcs --runtime-set ParanoiaMode 0 --extensions=php --standard=example_base_ruleset.xml tests.php`;
They can be set in a custom ruleset `phpcs.xml[.dist]` XML file or from the command line for permanent config with `--config-set` or at runtime with `--runtime-set`. Note that the XML override all CLI options so remove it if you want to use it. The CLI usage is as follow `phpcs --runtime-set ParanoiaMode 0 --extensions=php --standard=./vendor/pheromone/phpcs-security-audit/example_base_ruleset.xml tests.php`;

In some case you can force the paranoia mode on or off with the parameter `forceParanoia` inside the XML rule.

Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/AssertsSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -27,13 +27,13 @@ public function register() {
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();

if ($tokens[$stackPtr]['content'] == 'assert') {
$opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
$closer = $tokens[$opener]['parenthesis_closer'];
$s = $stackPtr + 1;
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
if ($s) {
$msg = 'Assert eval function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter';
if ($utils::is_token_user_input($tokens[$s])) {
Expand Down
4 changes: 2 additions & 2 deletions Security/Sniffs/BadFunctions/BackticksSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -26,7 +26,7 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
$tokens = $phpcsFile->getTokens();
$closer = $phpcsFile->findNext(T_BACKTICK, $stackPtr + 1, null, false, null, true);
if (!$closer) {
Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/CallbackFunctionsSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -27,7 +27,7 @@ public function register() {
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();

if (in_array($tokens[$stackPtr]['content'], $utils::getCallbackFunctions())) {
$opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
Expand All @@ -41,7 +41,7 @@ public function process(File $phpcsFile, $stackPtr) {
}
}
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens,
\PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
\PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
$msg = 'Function ' . $tokens[$stackPtr]['content'] . '() that supports callback detected';
if ($s) {
if ($utils::is_token_user_input($tokens[$s])) {
Expand Down
4 changes: 2 additions & 2 deletions Security/Sniffs/BadFunctions/CryptoFunctionsSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -25,7 +25,7 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
$tokens = $phpcsFile->getTokens();
if (preg_match("/^mcrypt_/", $tokens[$stackPtr]['content']) || in_array($tokens[$stackPtr]['content'], $utils::getCryptoFunctions())) {
$tokstr = $tokens[$stackPtr]['content'];
Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/EasyRFISniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -26,7 +26,7 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
$tokens = $phpcsFile->getTokens();
$s = $phpcsFile->findNext(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, $stackPtr, null, true, null, true);

Expand All @@ -37,7 +37,7 @@ public function process(File $phpcsFile, $stackPtr) {
$s = $stackPtr;
}
while ($s) {
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens), $s + 1, $closer, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens), $s + 1, $closer, true);
if ($s && $utils::is_token_user_input($tokens[$s])) {
if (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') || !$utils::is_token_false_positive($tokens[$s], $tokens[$s+2])) {
$phpcsFile->addError('Easy RFI detected because of direct user input with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'ErrEasyRFI');
Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/EasyXSSSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -33,7 +33,7 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
if ($this->forceParanoia >= 0) {
$parano = $this->forceParanoia ? 1 : 0;
} else {
Expand All @@ -53,7 +53,7 @@ public function process(File $phpcsFile, $stackPtr) {

$warn = false;
while ($s) {
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens), $s + 1, $closer, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens), $s + 1, $closer, true);
if ($s && $utils::is_token_user_input($tokens[$s])) {
$phpcsFile->addError('Easy XSS detected because of direct user input with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'EasyXSSerr');
} elseif ($s && $utils::is_XSS_mitigation($tokens[$s]['content'])) {
Expand Down
4 changes: 2 additions & 2 deletions Security/Sniffs/BadFunctions/ErrorHandlingSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -27,7 +27,7 @@ public function register() {
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$utils = new \PHPCS_SecurityAudit\Sniffs\Utils();
$utils = new \PHPCS_SecurityAudit\Security\Sniffs\Utils();

if ($tokens[$stackPtr]['content'] == 'error_reporting') {
$p = $utils::get_param_tokens($phpcsFile, $stackPtr, 1);
Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/FilesystemFunctionsSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -25,7 +25,7 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();

$tokens = $phpcsFile->getTokens();
if (in_array($tokens[$stackPtr]['content'], $utils::getFilesystemFunctions())) {
Expand All @@ -48,7 +48,7 @@ public function process(File $phpcsFile, $stackPtr) {
}

$closer = $tokens[$opener]['parenthesis_closer'];
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens), $s, $closer, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens), $s, $closer, true);
if ($s) {
$msg = 'Filesystem function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter';
if ($utils::is_token_user_input($tokens[$s])) {
Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/FringeFunctionsSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -27,13 +27,13 @@ public function register() {
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();

if (preg_match("/^ftp_/", $tokens[$stackPtr]['content'])) {
$opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
$closer = $tokens[$opener]['parenthesis_closer'];
$s = $stackPtr + 1;
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
$msg = 'Unusual function ' . $tokens[$stackPtr]['content'] . '() detected';
if ($s) {
if ($utils::is_token_user_input($tokens[$s])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -26,14 +26,14 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
$tokens = $phpcsFile->getTokens();

if (in_array($tokens[$stackPtr]['content'], $utils::getFunctionhandlingFunctions())) {
$opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
$closer = $tokens[$opener]['parenthesis_closer'];
$s = $stackPtr + 1;
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
if ($s) {
$msg = 'Function handling function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter';
if ($utils::is_token_user_input($tokens[$s])) {
Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/MysqliSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -26,7 +26,7 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
$tokens = $phpcsFile->getTokens();

// http://www.php.net/manual/en/book.mysqli.php
Expand Down Expand Up @@ -66,7 +66,7 @@ public function process(File $phpcsFile, $stackPtr) {
} elseif ($tokens[$stackPtr]['code'] == T_STRING && in_array($tokens[$stackPtr]['content'],array_map(function($v) { return 'mysqli_' . $v; }, $mysqlifunctions))) {
// The first parameter is always the link
$p2 = $utils::get_param_tokens($phpcsFile, $stackPtr, 2);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $p2[0]['stackPtr'], end($p2)['stackPtr']+1, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $p2[0]['stackPtr'], end($p2)['stackPtr']+1, true);
if ($s) {
$msg = 'MYSQLi function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter ';
if ($utils::is_token_user_input($tokens[$s])) {
Expand Down
2 changes: 1 addition & 1 deletion Security/Sniffs/BadFunctions/NoEvalsSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand Down
4 changes: 2 additions & 2 deletions Security/Sniffs/BadFunctions/PhpinfosSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -27,7 +27,7 @@ public function register() {
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();

if ($tokens[$stackPtr]['content'] == 'phpinfo') {
$phpcsFile->addWarning('phpinfo() function detected', $stackPtr, 'WarnPhpinfo');
Expand Down
4 changes: 2 additions & 2 deletions Security/Sniffs/BadFunctions/PregReplaceSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -26,7 +26,7 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();

$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['content'] == 'preg_replace') {
Expand Down
6 changes: 3 additions & 3 deletions Security/Sniffs/BadFunctions/SQLFunctionsSniff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace PHPCS_SecurityAudit\Sniffs\BadFunctions;
namespace PHPCS_SecurityAudit\Security\Sniffs\BadFunctions;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
Expand All @@ -26,15 +26,15 @@ public function register() {
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
$utils = \PHPCS_SecurityAudit\Security\Sniffs\UtilsFactory::getInstance();
$tokens = $phpcsFile->getTokens();

// http://www.php.net/manual/en/book.mysql.php
if ($tokens[$stackPtr]['content'] == 'mysql_query') {
$opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
$closer = $tokens[$opener]['parenthesis_closer'];
$s = $stackPtr + 1;
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Security\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
if ($s) {
$msg = 'SQL function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter ';
if ($utils::is_token_user_input($tokens[$s])) {
Expand Down
Loading

0 comments on commit c36e8c6

Please sign in to comment.