Honeypot type for Symfony forms

Related tags

API EoHoneypotBundle
Overview

EoHoneypotBundle

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads

Honeypot for Symfony2 forms.

What is Honey pot?

A honey pot trap involves creating a form with an extra field that is hidden to human visitors but readable by robots. The robot fills out the invisible field and submits the form, leaving you to simply ignore their spammy submission or blacklist their IP. It’s a very simple concept that can be implemented in a few minutes and it just works – add them to your contact and submission forms to help reduce spam.

Prerequisites

This version of the bundle requires Symfony 2.1+

Installation

Step 1: Download EoHoneypotBundle using Composer

Add EoHoneypotBundle to your project by running the command:

$ composer require eo/honeypot-bundle

Composer will install the bundle to your project's vendor/eo directory.

Step 2: Enable the bundle

If you use Symfony Flex - skip this step. Otherwise, enable the bundle in bundles.php:

<?php
// config/bundles.php

<?php
return [
    // ...
    Eo\HoneypotBundle\EoHoneypotBundle::class => ['all' => true],
];

Step 3 (optional): Configure bundle to use database

To save honeypot catched requests into database you have to enable it in your configuration file: All parameters are optional

# config/packages/eo_honeypot.yaml
eo_honeypot:
    storage:
        database:
            enabled: false
            driver: mongodb # orm and mongodb are supported
            class: ApplicationEoHoneypotBundle:HoneypotPrey
        # You can also use file format to store honeypot preys.
        # This may come handy if you need to parse logs with fail2ban
        # file:
            # enabled: false
            # output: /var/log/honeypot.log
    redirect:
        enabled: true
        url: "/"
        # route: homepage
        # route_parameters: ~

If you enable the database storage, you must create a class which extends the Eo\HoneypotBundle\<Entity|Document>\HoneypotPrey base class :

<?php
namespace Application\Eo\HoneypotBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eo\HoneypotBundle\Entity\HoneypotPrey as BaseHoneypotPrey;

/**
 * @ORM\Entity
 */
class HoneypotPrey extends BaseHoneypotPrey
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function getId()
    {
        return $this->id;
    }
}

or

<?php
namespace Application\Eo\HoneypotBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Eo\HoneypotBundle\Document\HoneypotPrey as BaseHoneypotPrey;

/**
 * @MongoDB\Document
 */
class HoneypotPrey extends BaseHoneypotPrey
{
    /**
     * @MongoDB\Id
     */
    protected $id;

    public function getId()
    {
        return $this->id;
    }
}

Usage

Once installed and configured you can start using Eo\HoneypotBundle\Form\Type\HoneypotType form type in your forms.

Basic usage example:

<?php

namespace Acme\DemoBundle\Form\Type;

use Eo\HoneypotBundle\Form\Type\HoneypotType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

class FooType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', TextType);
        $builder->add('email', EmailType);

        // Honeypot field
        $builder->add('SOME-FAKE-NAME', HoneypotType::class);
    }
}

Events

If the hidden honeypot field has some data bundle will dispatch a bird.in.cage event. You can create an event listener to execute custom actions. See Eo\HoneypotBundle\Event\BirdInCage and How to Register Event Listeners and Subscribers for more information.

License

This bundle is under the MIT license. See the complete license in the bundle:

Resources/meta/LICENSE

Reporting an issue or a feature request

Issues and feature requests related to this bundle are tracked in the Github issue tracker https://github.com/eymengunay/EoHoneypotBundle/issues.

Comments
  • Updated FormType for Symfony 3.

    Updated FormType for Symfony 3.

    Removed the getName() method, updated the parent name to the fully qualified class, and changed setDefaultOptions() to configureOptions().

    The parent class name is in the format of Namespace\ClassName instead of ClassName::class for < PHP 5.5.

    opened by iisisrael 6
  • Add redirect listener

    Add redirect listener

    This PR add a RedirectListener, loaded only if redirect is enabled.

    The to option is replaced with url, and I added a route options (with route_parameters).

    opened by EmmanuelVella 6
  • Fix problem when using the web browser's autocomplete feature

    Fix problem when using the web browser's autocomplete feature

    autocomplete="off" does not work in some cases, leaving the user alone with an unsendable form. Setting autocomplete="somerandomstring" works, so I propose setting it to "nope".

    See https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

    opened by janopae 4
  • `FilterResponseEvent` renamed to ResponseEvent

    `FilterResponseEvent` renamed to ResponseEvent

    The implemented RedirectListener is not working anymore since Symfony 4.4+

    Since Symfony 4.3, most of the event classes were renamed. The following old classes were deprecated: ... FilterResponseEvent renamed to ResponseEvent

    See: https://symfony.com/doc/4.3/components/http_kernel.html#creating-an-event-listener

    Because version 2.0 suggests to support Symfony 5, this must be changed as well.

    opened by seho-nl 3
  • Template reference not found

    Template reference not found

    Using Symfony 4.2.4 and HoneypotBundle 1.2.1 I get a Twig_Error_Loader Exception because your template can't be found/resolved. Template reference "EoHoneypotBundle:Form:div_layout.html.twig" not found, did you mean "@EoHoneypot/Form/div_layout.html.twig"?

    I suggest using the @EoHoneypot/Form/div_layout.html.twig resource instead of EoHoneypotBundle:Form:div_layout.html.twig in your FormCompilerPass class.

    opened by Aricura 3
  • Add new version tag

    Add new version tag

    Since the documentation says we should add the bundle with dev-master I'm currently getting failed requirements when updating composer since the dev-master requires symfony 3.0 and my project runs on ~2.3

    opened by stefantalen 2
  • Ready for Symfony 3.0

    Ready for Symfony 3.0

    In Symfony 2.8 your Bundle throws a deprecated notice.

    You need to add the configureOptions() Function to replace the setDefaultOptions() Function in HoneypotType.

    opened by CoalaJoe 2
  • Tag release

    Tag release

    Can we get a new tagged release? I just ran into this error

      [Doctrine\Common\Annotations\AnnotationException]                                                                           
      [Semantical Error] The annotation "@Doctrine\ODM\MongoDB\Mapping\Annotations\Document" in class Eo\HoneypotBundle\Document  
      \HoneypotPrey does not exist, or could not be auto-loaded.                                                                  
    

    Locking version against dev-master fixes.

    opened by MichaelMackus 2
  • Refactored HoneypotType

    Refactored HoneypotType

    Hi,

    I just moved the form type to the request scope in order to remove the container injection. I didn't use the RequestStack to stay compatible with sf < 2.4.

    I also refactored a bit the files.

    opened by EmmanuelVella 2
  • Using $this when not in object context

    Using $this when not in object context

    An error was not solved with commit 95d297627a

    1. Using $this when not in object context in %mydir%/vendor/eo/honeypot-bundle/Eo/HoneypotBundle/Form/Type/HoneypotType.php line 44

    To solve this problem please replace row 42 with the followings two lines:

    $container = $this->container; 
    $builder->addEventListener(FormEvents::PRE_BIND, function(FormEvent $event) use ($container) {
    

    then replace every occurence of $this->container with $container (in rows 45, 46 and 52).

    This works with

    database:
         enabled: false
    

    and

    file:
         enabled: true 
    

    in config.yml (not tested with different config)

    opened by silzenna 2
  • Allow disabling form error if honeypot is filled in

    Allow disabling form error if honeypot is filled in

    Fixes #17.

    The option is set in such a way that the default remains the same as before and is backwards compatible.

    The reasoning behind not showing an error is primarily not to make bots suspicious; some bots that encounter errors after submit, will try submitting again with different combinations of data until they get a 200 status code.

    Of course, this assumes that the user handles the "bird in cage" or "honeypot triggered" event or status by himself, which is intended.

    opened by ghost 1
  • Implement time-based protection

    Implement time-based protection

    In order to complicate automated mass-submissions of forms, one possible solution would be to include a hidden field in the form that includes a timestamp, plus a second field that contains an HMAC for this timestamp value + a secret value.

    Upon submission, we could check if the timestamp is legit (the HMAC signature is correct) and falls into a configurable range – so for example, only accept form submissions for forms rendered at least 30s ago and not older than 4 hours.

    This does of course not prevent automated form submissions, but would at least require that forms be fetched periodically and kept on hold for some time before they can be ~~ab~~used.

    The timestamp + HMAC cannot prevent the same form from being submitted multiple times, but it has the advantage that we do not need to keep state in the backend.

    Another approach would be to issue unique form-IDs, but that would require some tracking mechanism (a database, key-value-store, ...) to keep the issued IDs, remove submitted and expire old ones. That would be more involved to set up.

    For sure, it's not a perfect solution – but anyway, is that something you would support in this bundle and that you would accept a PR for? Or is this outside of what this bundle tries to provide?

    opened by mpdude 0
  • Reject form if honeypot field is omitted?

    Reject form if honeypot field is omitted?

    I am under the impression that if the submitted form does not contain the honeypot field at all, it is accepted as well.

    Would it make sense to make this check more strict and also reject the form if someone tries to submit an older (cached) version of the form without the field?

    Would you accept a PR for that?

    opened by mpdude 0
  • How to use this field type in the FOSUserBundle login form?

    How to use this field type in the FOSUserBundle login form?

    The login form in FOSUserBundle does not have a LoginFormType or equivalent, is just a form HTML markup added in a twig template which I can override: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/views/Security/login_content.html.twig

    I'm still not sure how to add the Eo\HoneypotBundle\Form\Type\HoneypotType field provided by this bundle under this scenario.

    Can someone help to point me in the right direction?

    opened by elvismdev 0
  • Alternate ORM configuration

    Alternate ORM configuration

    Using the class HoneypotPrey extends BaseHoneypotPrey configuration as shown in the example, I was getting this error when running app/console doctrine:schema:update --dump-sql:

    [Doctrine\ORM\Mapping\MappingException]
    Duplicate definition of column 'id' on entity 'ExampleBundle\Entity\HoneypotPrey' in a field or discriminator column mapping.
    

    I then tried extending Eo\HoneypotBundle\Model\HoneypotPrey instead of Eo\HoneypotBundle\Entity\HoneypotPrey, and that worked as far as the schema update was concerned. I had two tables - HoneypotPrey with just the id column, and honeypot_prey with the columns id, ip, and createdAt. However, after submitting some test spam registrations with the honeypot field populated with data, I was only getting new rows in the HoneypotPrey table (and lines appended to honeypot.log), but nothing in the honeypot_prey table.

    So, instead, I mapped the schema like so (sorry, not a fan of annotations)...

    ExampleBundle\Entity\HoneypotPrey:
        type: entity
        table: HoneypotPrey
        id:
            id:
                type:   integer
                generator:
                    strategy: AUTO
        fields:
            createdAt:
                type:     datetime
            ip:
                type:     string
    

    ... generated the entities, copied the __construct() method from Eo\HoneypotBundle\Model\HoneypotPrey into my Entity class, modified my Entity class like so...

    namespace ExampleBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use Eo\HoneypotBundle\Model\HoneypotPreyInterface;
    
    /**
     * HoneypotPrey
     */
    class HoneypotPrey implements HoneypotPreyInterface
    {
        ...
    

    ... dropped the honeypot_prey table, and reran the schema update command. I'm now getting records in my HoneypotPrey table...

    mysql> select * from HoneypotPrey;
    +----+---------------------+-------------+
    | id | createdAt           | ip          |
    +----+---------------------+-------------+
    |  4 | 2015-01-14 00:05:56 | 172.16.61.1 |
    +----+---------------------+-------------+
    

    Configs are set like so:

    # Honeypot
    eo_honeypot:
        storage:
            # Record for reporting
            database:
                enabled: true
                driver:  orm
                class:   ExampleBundle:HoneypotPrey
            # Log for IP banning using fail2ban
            file:
                enabled: true
                output:  %kernel.root_dir%/logs/honeypot.log
    
    opened by iisisrael 1
Releases(v2.0.1)
  • v2.0.1(Oct 19, 2022)

    What's Changed

    • Use ResponseEvent instead of FilterResponseEvent to support Symfony 5 by @seho-nl in https://github.com/eymengunay/EoHoneypotBundle/pull/35

    New Contributors

    • @seho-nl made their first contribution in https://github.com/eymengunay/EoHoneypotBundle/pull/35

    Full Changelog: https://github.com/eymengunay/EoHoneypotBundle/compare/v2.0.0...v2.0.1

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Oct 5, 2022)

    What's Changed

    • SF 5 Compatibility by @ehibes in https://github.com/eymengunay/EoHoneypotBundle/pull/33

    New Contributors

    • @ehibes made their first contribution in https://github.com/eymengunay/EoHoneypotBundle/pull/33

    Full Changelog: https://github.com/eymengunay/EoHoneypotBundle/compare/v1.3.0...v2.0.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Nov 27, 2021)

    What's Changed

    • Fix TreeBuilder root node deprecation in Symfony 4.1+ by @AkenRoberts in https://github.com/eymengunay/EoHoneypotBundle/pull/27
    • Allow disabling form error if honeypot is filled in in https://github.com/eymengunay/EoHoneypotBundle/pull/28
    • Add support for symfony 5 by @esserj in https://github.com/eymengunay/EoHoneypotBundle/pull/32

    New Contributors

    • @AkenRoberts made their first contribution in https://github.com/eymengunay/EoHoneypotBundle/pull/27
    • @esserj made their first contribution in https://github.com/eymengunay/EoHoneypotBundle/pull/32

    Full Changelog: https://github.com/eymengunay/EoHoneypotBundle/compare/v1.2.3...v1.3.0

    Source code(tar.gz)
    Source code(zip)
OpenAPI(v3) Validators for Symfony http-foundation, using `league/openapi-psr7-validator` and `symfony/psr-http-message-bridge`.

openapi-http-foundation-validator OpenAPI(v3) Validators for Symfony http-foundation, using league/openapi-psr7-validator and symfony/psr-http-message

n1215 2 Nov 19, 2021
Fork of Symfony Rate Limiter Component for Symfony 4

Rate Limiter Component Fork (Compatible with Symfony <=4.4) The Rate Limiter component provides a Token Bucket implementation to rate limit input and

AvaiBook by idealista 4 Apr 19, 2022
Enter-to-the-Matrix-with-Symfony-Console - Reproduction of the "Matrix characterfall" effect with the Symfony Console component.

Enter to the Matrix (with Symfony Console) Reproduction of the "Matrix characterfall" effect with the Symfony Console component. Run Clone the project

Yoan Bernabeu 23 Aug 28, 2022
Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project

AmiAirbrakeBundle Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project. Prerequisites Th

Anton Minin 8 May 6, 2022
This bundle provides tools to build a complete GraphQL server in your Symfony App.

OverblogGraphQLBundle This Symfony bundle provides integration of GraphQL using webonyx/graphql-php and GraphQL Relay. It also supports: batching with

Webedia - Overblog 720 Dec 25, 2022
Pure PHP implementation of GraphQL Server – Symfony Bundle

Symfony GraphQl Bundle This is a bundle based on the pure PHP GraphQL Server implementation This bundle provides you with: Full compatibility with the

null 283 Dec 15, 2022
DataTables bundle for Symfony

Symfony DataTables Bundle This bundle provides convenient integration of the popular DataTables jQuery library for realtime Ajax tables in your Symfon

Omines Internetbureau 199 Jan 3, 2023
GraphQL Bundle for Symfony 2.

Symfony 2 GraphQl Bundle Use Facebook GraphQL with Symfony 2. This library port laravel-graphql. It is based on the PHP implementation here. Installat

Sergey Varibrus 35 Nov 17, 2022
Provides a Middleware to integration Tideways into Symfony Messenger Processing

Tideways Middleware for Symfony Messenger This package is currently under development and might be moved into the Tideways PHP Extension or stay indep

Tideways 6 Jul 5, 2022
Integration with your Symfony app & Vite

ViteBundle : Symfony integration with Vite This bundle helping you render all of the dynamic script and link tags needed. Essentially, he provide two

Hugues Tavernier 84 Dec 21, 2022
An Unleash bundle for Symfony applications to provide an easy way to use feature flags

Unleash Bundle An Unleash bundle for Symfony applications. This provide an easy way to implement feature flags using Gitlab Feature Flags Feature. Ins

Stogon 7 Oct 20, 2022
Symfony Health Check Bundle Monitoring Project Status

Symfony Health Check Bundle Version Build Status Code Coverage master develop Installation Step 1: Download the Bundle Open a command console, enter y

MacPaw Inc. 27 Jul 7, 2022
The official Symfony SDK for Sentry (sentry.io)

sentry-symfony Symfony integration for Sentry. Benefits Use sentry-symfony for: A fast Sentry setup Easy configuration in your Symfony app Automatic w

Sentry 628 Dec 29, 2022
A bundle providing routes and glue code between Symfony and a WOPI connector.

WOPI Bundle A Symfony bundle to facilitate the implementation of the WOPI endpoints and protocol. Description The Web Application Open Platform Interf

Champs-Libres 5 Aug 20, 2022
Chat room demo with Symfony UX Turbo

Symfony UX Turbo Demo Application Chat application demo on how Symfony UX Turbo can be used to make server-rendered applications more dynamic without

Druid 5 Sep 22, 2022
This small POC aims to show how Symfony is able, natively without modifications, to use subdirectories for Entities, Repositories, controllers, views…

POC - Using Sub Directories in a Symfony Project This small POC aims to show how Symfony is able, natively without modifications, to use subdirectorie

Yoan Bernabeu 2 May 12, 2022
Auto register services aliases in the Symfony container.

Service Alias Auto Register A bundle for Symfony 5. Description The S.O.L.I.D. principles are a set of five design principles intended to make softwar

(infinite) loophp 1 Feb 4, 2022
Meta package tying together all the key packages of the Symfony CMF project.

This repository is no longer maintained Due to lack of interest, we had to decide to discontinue this repository. The CMF project focusses on the Rout

Symfony CMF 733 Dec 21, 2022
This project lists all the mandatory steps I recommend to build a Website using Symfony, Twig, Doctrine.

{% raw %} <-- keep this for Jekyll to fully bypass this documents, because of the Twig tags. Symfony Website Checklist ?? Summary~~~~ Elevator pitch P

William Pinaud 6 Aug 31, 2022