Giter Site home page Giter Site logo

isometriksspambundle's Introduction

Symfony3 SpamBundle

Please feel free to send pull requests. I would like to incorporate a bunch of spam methods into this project.

Installation

Install via composer:

$ php composer.phar require isometriks/spam-bundle:dev-master

Use ~0.3.0 for Symfony 2.3-2.7, or ~1.0 for 3+

Add to AppKernel.php:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Isometriks\Bundle\SpamBundle\IsometriksSpamBundle(),
            // ...
        );

        return $bundles;
    }
}

Currently we have:

Timed Spam Prevention

Requires forms to be sent after a certain amount of time. Most bots won't wait to submit your forms, so requiring an amount of time between render and submit can help deter these bots.

A side affect of this spam prevention is that you won't be able to refresh a page to resubmit data UNLESS the view is rendered again $form->createView() This is because the event listener removes the start time of the form and when it can't find it, will cause the form to be invalid. You could set your min time to 0 to just make use of this feature

Configuration:

isometriks_spam:
    timed:
        min: 7
        max: 3600
        global: false
        message: You're doing that too quickly.

Usage:

$this->createForm(MyType:class, null, array(
    'timed_spam' => true,
    'timed_spam_min' => 3,
    'timed_spam_max' => 40,
    'timed_spam_message' => 'Please wait 3 seconds before submitting',
));

Or

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'timed_spam' => true,
        // ...
    ));
}

Honeypot Spam Prevention

A honeypot is a way to trick bots into filling out a field that should not be filled out. It is hidden and can be named something usual so that any bots / crawlers will think it is a real field.

If the field is filled out, then the form is invalid. You can optionally choose to use a class name to hide the form element as well in case the bot tries to check the style attribute.

isometriks_spam:
    honeypot:
        field: email_address
        use_class: false
        hide_class: hidden
        global: false
        message: Form fields are invalid

Usage:

$this->createForm(MyType::class, null, array(
    'honeypot' => true,
    'honeypot_field' => 'email_address',
    'honeypot_use_class' => false,
    'honeypot_hide_class' => 'hidden',
    'honeypot_message' => 'Form field are invalid',
));

Or

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'honeypot' => true,
        // ...
    ));
}

Cookie Spam Prevention

Most of spam bots can't use cookies so we could check cookie value on each request.

If there is no cookie set - then the request is invalid and set by bots. These cookies are not used for any tracking and are deleted after form is submitted and handled.

Configuration:

isometriks_spam:
    cookie:
        name: antispam_cookie
        global: false
        message: Something is wrong, please try again

Usage:

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'cookie' => true,
        // ...
    ));
}

Twig Form Error message rendering

{% if form.vars.errors is not empty %}
    <div class="alert alert-danger has-error">{{ form_errors(form) }}</div>
{% endif %}

isometriksspambundle's People

Contributors

aeyoll avatar insekticid avatar isometriks avatar thatside-zaraffa avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.