Composer is a brilliant tool and coupled with the thousands and thousands of packages you can install with it, it reduces how much work we have to do to develop software, considerably.
Naturally, with that, comes risks. From time to time, vulnerabilities are found in packages and consequently, this can leave your applications in danger too. All is not lost, however, for fortunately we have wonderful services such as the SensioLabs Security Checker which collate found security problems and make those lists available for others. I’m going to show you how to install a vulnerability checker in your PHP application and have it run each time you install or update packages using composer.
Let’s start by creating an empty folder and installing something I know has vulnerabilities: PHP Mailer version 5.2.0. You can see where they fixed it here and also some details about the problem there.
> mkdir security-checker
Now, that version is way behind what is available, so don’t be using it in your projects, OK?!
Next, let’s download the PHAR file and place that in the root of the folder. You can grab it from this location.
Let’s now manually check our packages:
> php security-checker.phar security:check --format=simple
Eek! Pretty scary. I don’t really want to keep doing that each time I add packages though so let’s make a change to our composer.json file and get that check happening automatically. Edit composer.json and add the following:
Now run composer update and see the magic:
> composer update
If you want to find out more about which events you can tag commands onto, you can look here.
Keep safe, folks.
Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com