devtoolboxuk / cerberus
Another Security Package for PHP
0.0.2
2019-06-22 09:10 UTC
Requires
- php: >=5.4.16
- devtoolboxuk/ip-address: ^1.0.1
- devtoolboxuk/lists: ^1.0.0
- devtoolboxuk/soteria: ^2.1.6
- devtoolboxuk/utilitybundle: ^1.0.12
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-29 05:11:06 UTC
README
Table of Contents
-
[Help Support This Project](#Help Support This Project)
Background
Detects if various threats are placed against the system. A score is then given to each threat. You can then decide what you want to action based on that score.
Features
- Detects if any threats are in the string.
- Gives a score to any threats found.
- Cleans the string of any threats.
Usage
$ composer require devtoolboxuk/cerberus
Then include Composer's generated vendor/autoload.php to enable autoloading:
require 'vendor/autoload.php';
use devtoolboxuk\cerberus; $this->cerberus = new Cerberus();
Set Options
$cerberus->setOptions($this->getOptions());
Example - Detection of a dodgy website registration
Also see tests/test-registration.php
function testDodgyRegistration() { $cerberus = new CerberusService(); $cerberus->setOptions($this->getOptions()); $login_array = [ 'email' => 'rob@shotmail.ru', 'name' => 'Visit my website http://www.doajob.org?redirect=https://www.google.com', 'address' => 'Some Street', 'postcode' => 'GL1 1AA', 'country' => 'MX', ]; $detection = $cerberus ->resetHandlers() ->pushHandler($this->createLoginStringHandler('Name', $login_array['name'])) ->pushHandler($this->createLoginStringHandler('Address', $login_array['address'])) ->pushHandler(new EmailHandler($login_array['email'])) ->pushHandler(new CountryHandler($login_array['country'])); $detection->getScore(); //Returns a Score $detection->getOutputByName('Name'); //Returns the cleaned sanitised output of Name; $detection->getResult(); //Returns a result } private function createLoginStringHandler($name, $data) { $handler = new DefaultHandler($name, $data); $handler->pushWrapper(new HtmlWrapper()); $handler->pushWrapper(new UrlWrapper()); $handler->pushWrapper(new XssWrapper()); return $handler; }
Get References
Get Input for each reference
foreach ($detection->getReferences() as $reference) { $reference->getInput(); }
Get Output for each reference
foreach ($detection->getReferences() as $reference) { $reference->getOutPut(); }
Get Output by name assigned
- If a name is not assigned, you wont be able to look it up... duh
$detection->getOutputByName('Name'); # eg: 'Visit my website'
Help Support This Project
Maintainers
License
MIT © DevToolboxUK