You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-20Lines changed: 46 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
phpcs-security-audit v2
1
+
phpcs-security-audit v3
2
2
=======================
3
3
4
4
About
@@ -7,35 +7,29 @@ phpcs-security-audit is a set of [PHP_CodeSniffer](https://github.com/squizlabs/
7
7
8
8
It currently has core PHP rules as well as Drupal 7 specific rules.
9
9
10
-
The tool also checks for CVE issues and security advisories related to CMS/framework. Using it, you can follow the versioning of components during static code analysis.
10
+
The tool also checks for CVE issues and security advisories related to the CMS/framework. This enable you to follow the versioning of components during static code analysis.
11
11
12
-
The main reason of this project for being an extension of PHP_CodeSniffer is to have easy integration into continuous integration systems. It is also able to find security bugs that are not detected with object oriented analysis (like in [RIPS](http://rips-scanner.sourceforge.net/) or[PHPMD](http://phpmd.org/)).
12
+
The main reason of this project for being an extension of PHP_CodeSniffer is to have easy integration into continuous integration systems. It is also able to find security bugs that are not detected with some object oriented analysis (such as[PHPMD](http://phpmd.org/)).
13
13
14
-
phpcs-security-audit is backed by [Floe design + technologies](https://floedesign.ca/) and written by [Jonathan Marcil](https://twitter.com/jonathanmarcil).
14
+
phpcs-security-audit in its beginning was backed by Pheromone (later on named Floe design + technologies) and written by [Jonathan Marcil](https://twitter.com/jonathanmarcil).
Requires [PHP CodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/) version 3.x with PHP 5.4 or higher.
23
22
24
-
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.
25
-
26
-
The easiest way to install is to git clone and use composer that will create the symlink for you:
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.
32
+
39
33
If you want to integrate it all with Jenkins, go see http://jenkins-php.org/ for extensive help.
40
34
41
35
@@ -44,14 +38,14 @@ Usage
44
38
45
39
Simply point to any XML ruleset file and a folder:
@@ -85,7 +79,7 @@ These global parameters are used in many rules:
85
79
* ParanoiaMode: set to 1 to add more checks. 0 for less.
86
80
* CmsFramework: set to the name of a folder containings rules and Utils.php (such as Drupal7, Symfony2).
87
81
88
-
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`;
82
+
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`;
89
83
90
84
In some case you can force the paranoia mode on or off with the parameter `forceParanoia` inside the XML rule.
91
85
@@ -121,13 +115,45 @@ You are not required to do your own sniffs for the modification to be useful, si
121
115
If you implement any public cms/framework customization please make a pull request to help the project grows.
122
116
123
117
118
+
Contribute
119
+
----------
120
+
It is possible to install with a `git clone` and play with it in the same folder.
By default it should set PHPCS to look in the current folder:
127
+
```
128
+
PHP CodeSniffer Config installed_paths set to ../../../
129
+
```
130
+
131
+
If for any reason you need to change this (should work out of the box) you will need to `phpcs --config-set installed_paths` as explained in [PHP_CodeSniffer docs](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths).
132
+
133
+
Master can contain breaking changes, so people are better to rely on releases for stable versions.
134
+
135
+
Those release packages are available [here on GitHub](releases) or on [Packagist](https://packagist.org/packages/pheromone/phpcs-security-audit).
136
+
137
+
Some guidelines if you want to create new rules:
138
+
* Ensure that `ParanoiaMode` controls how verbose your sniff is
139
+
* If sometime the sniff is a valid security concern, run it when paranoia=true only
140
+
* Warnings are generally issued instead of Errors for most-of-the-time when paranoia=false
141
+
* Errors are always generated when you are use about user input being used
* paranoia=false should solve false positive, otherwise warn on anything remotely suspicious
144
+
* Include at least one test that trigger your sniff into `tests.php`
145
+
* Keep it as a one liner, doesn't need to make sense
146
+
* Don't forget to include your new sniff in the `example_base_ruleset.xml` and `example_drupal7_ruleset.xml` when it applies.
147
+
148
+
124
149
Annoyances
125
150
----------
126
151
127
152
As any security tools, this one comes with it's share of annoyance. At first a focus on finding vulnerabilities will be done, but later it is planned to have a phase where efforts will be towards reducing annoyances, in particular with the number of false positives.
128
153
129
154
* It's a generator of false positives. This can actually help you learn what are the weak functions in PHP. Paranoia mode will fix that by doing a major cut-off on warnings when set to 0.
130
-
* It's slow. On big Drupal modules and core it can take too much time (and RAM, reconfigure cli/php.ini to use 512M if needed) to run. Not sure if it's because of bugs in PHPCS or this set of rules, but will be investigated last. Meanwhile you can configure PHPCS to ignore big contrib modules (and run another instance of PHPCS for .info parsing only for them). An example is og taking hours, usually everything runs under 1-2 minutes and sometime around 5 minute. You can only use one core in PHP since no multithreading is available. Possible workaround is to use phpcs --ignore=folder to skip scanning of those parts.
155
+
* This tool was created around 10 years ago. Some of its parts might look outdated, and support for old PHP code will still be present. The reality is that many code base scanned with it might be as old as the tool.
156
+
* It's slow. On big Drupal modules and core it can take too much time (and RAM, reconfigure cli/php.ini to use 512M if needed) to run. Not sure if it's because of bugs in PHPCS or this set of rules, but will be investigated last. Meanwhile you can configure PHPCS to ignore big contrib modules (and run another instance of PHPCS for .info parsing only for them). An example is og taking hours, usually everything runs under 1-2 minutes and sometime around 5 minute. You can try using the `--parallel=8` (or another number) option to try and speed things up on supported OSes. Possible workaround is to use phpcs --ignore=folder to skip scanning of those parts.
131
157
* For Drupal advisories checking: a module with multiple versions might be secure if a lesser fixed version exists and you'll still get the error or warning. Keep everything updated at latest as recommended on Drupal's website.
if ($s && $utils::is_token_user_input($tokens[$s])) {
42
42
if (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') || !$utils::is_token_false_positive($tokens[$s], $tokens[$s+2])) {
43
43
$phpcsFile->addError('Easy RFI detected because of direct user input with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'ErrEasyRFI');
if ($s && $utils::is_token_user_input($tokens[$s])) {
58
58
$phpcsFile->addError('Easy XSS detected because of direct user input with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'EasyXSSerr');
0 commit comments