leonardini/brontosaurus

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP security auditor for websites

v0.0.5 2020-07-19 12:51 UTC

README

687474703a2f2f62726f6e746f7361757275732e6c656f6e617264696e692e6465762f6c6f676f2e737667

 Brontosaurus 68747470733a2f2f7472617669732d63692e6f72672f4c6f72656e7a6f4c656f6e617264696e692f42726f6e746f7361757275732e7376673f6272616e63683d6d6173746572 68747470733a2f2f636f6465636f762e696f2f67682f4c6f72656e7a6f4c656f6e617264696e692f42726f6e746f7361757275732f6272616e63682f6d61737465722f67726170682f62616467652e737667 68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f4c6f72656e7a6f4c656f6e617264696e692f42726f6e746f7361757275732e737667 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d3963662e7376673f6c6f676f3d70617970616c


Brontosaurus is a security tool for your PHP website.

Current features include:

  • Form tokens validation

Table of Contents

Installation

The easiest way to install Brontosaurus is with Composer:

composer require leonardini/brontosaurus

If you prefer you can download the latest release and manually add the files to your project. Keep in mind that this is discouraged as you won't be able to easily update the library.

WARNING: Make sure to require_once every file inside the src folder

Getting Started

NOTICE: this tutorial assumes that you've installed Brontosaurus using Composer, if you haven't you can still follow this, but some parts would be different

To be able to use Brontosaurus you have to require_once the autoload.php file inside Composer's vendor folder.

require_once("vendor/autoload.php");

This is actually the only thing you need to do to get Brontosaurus and all its tools up and running. For an usage example see the next section about Form Tokens

Form Tokens

When your website has a form, you usually want to receive submissions only from your legit page and not from other sources, such as unauthorized third-parties services.

Keeping in mind that this problem cannot be completely solved, Brontosaurus has a nice tool to help you make your forms a little bit more secure.

This works by generating a hidden random token every time the form page is loaded. The token is than sent to the server together with the form data and checked if its the same one saved in session. The user could have multiple browser tabs opened and to support that the last 20 tokens are saved in session (that number is customizable, check the configuration section).

The code you need on the form page is the following:

// It is extremely important that a descriptive form name is provided as parameter, because tokens must be strictly linked to every form of your website
$token = \Brontosaurus\FormToken\generateToken("form_name");

// The token must be sent to the server in a 'form_token' parameter, for security only POST request are supported
echo "<input type=\"hidden\" name=\"form_token\" value=\"$token\">";
// The form name must be sent in a 'form_name' parameter, too
echo "<input type=\"hidden\" name=\"form_name\" value=\"form_name\">";

To check the validity of the token you will use:

$validation = \Brontosaurus\FormToken\validateToken("form_name");

if($validation->isSuccessful()) {
    // The token comes from your form
} else {
    // The token has not passed the check
}

Major info about the validation process could be obtained with $validation->getCode(). Give a look to ValidationCode enum.

Configuration

Brontosaurus can be configured through a yml file. To load the config file use

\Brontosaurus\Config::loadFromFile(__DIR__."/config.yml");

You can also unload your custom configs (default ones would be restored)

\Brontosaurus\Config::unloadConfig();

This is an example config file:

form_token:
    maximum_tokens: 40