devtoolboxuk/cerberus

PHP 的另一个安全包

0.0.2 2019-06-22 09:10 UTC

This package is auto-updated.

Last update: 2024-09-29 05:02:36 UTC


README

Build Status Scrutinizer Code Quality Coveralls CodeCov

Latest Stable Version Total Downloads License

Maintenance

PHP

目录

背景

检测系统是否受到各种威胁。然后为每个威胁给出一个分数。您可以根据这个分数决定要采取的行动。

功能

  • 检测字符串中是否存在任何威胁。
  • 为找到的任何威胁给出一个分数。
  • 清除字符串中的任何威胁。

用法

$ composer require devtoolboxuk/cerberus

然后包括 Composer 生成的 vendor/autoload.php 以启用自动加载

require 'vendor/autoload.php';
use devtoolboxuk\cerberus;

$this->cerberus = new Cerberus();

设置选项

$cerberus->setOptions($this->getOptions());

示例 - 检测可疑网站注册

另请参阅 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;
}    

获取引用

为每个引用获取输入

foreach ($detection->getReferences() as $reference)
{
    $reference->getInput();
}

为每个引用获取输出

foreach ($detection->getReferences() as $reference)
{
    $reference->getOutPut();
}

按名称获取输出

  • 如果没有分配名称,您将无法查找它... 嘿
$detection->getOutputByName('Name');
# eg: 'Visit my website'

帮助支持此项目

Help Support This Project

维护者

@DevToolboxUk.

许可

MIT © DevToolboxUK