All Projects → jamesturk → Django Honeypot

jamesturk / Django Honeypot

Licence: bsd-2-clause
🍯 Generic honeypot utilities for use in django projects.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Honeypot

Acra
Database security suite. Database proxy with field-level encryption, search through encrypted data, SQL injections prevention, intrusion detection, honeypots. Supports client-side and proxy-side ("transparent") encryption. SQL, NoSQL.
Stars: ✭ 726 (+155.63%)
Mutual labels:  django, honeypot
Chatire
💬 Real time Chat application built with Vue, Django, RabbitMQ and uWSGI WebSockets.
Stars: ✭ 278 (-2.11%)
Mutual labels:  django
Django Reversion Compare
Add compare view to django-reversion for comparing two versions of a reversion model.
Stars: ✭ 269 (-5.28%)
Mutual labels:  django
Wagtailmenus
An app to help you manage and render menus in your Wagtail projects more effectively
Stars: ✭ 275 (-3.17%)
Mutual labels:  django
Fms
运维故障管理系统
Stars: ✭ 270 (-4.93%)
Mutual labels:  django
Django Page Cms
Official Django page CMS git repository
Stars: ✭ 277 (-2.46%)
Mutual labels:  django
Django Swingtime
📆 Event and occurrence scheduling application for Django
Stars: ✭ 268 (-5.63%)
Mutual labels:  django
Djangocms Admin Style
django CMS Admin Style is a Django Theme tailored to the needs of django CMS.
Stars: ✭ 282 (-0.7%)
Mutual labels:  django
Django Schema Graph
An interactive graph of your Django model structure
Stars: ✭ 278 (-2.11%)
Mutual labels:  django
Openciviwiki
Building a Better Democracy for the Internet Age
Stars: ✭ 275 (-3.17%)
Mutual labels:  django
Admin Dashboards
Admin Dashboards - Open-Source and Free | AppSeed
Stars: ✭ 275 (-3.17%)
Mutual labels:  django
Adminset
自动化运维平台:CMDB、CD、DevOps、资产管理、任务编排、持续交付、系统监控、运维管理、配置管理
Stars: ✭ 2,985 (+951.06%)
Mutual labels:  django
Longclaw
A shop for Wagtail CMS
Stars: ✭ 278 (-2.11%)
Mutual labels:  django
Zappa
Serverless Python
Stars: ✭ 224 (-21.13%)
Mutual labels:  django
Django Querycount
Middleware that Prints the number of DB queries to the runserver console.
Stars: ✭ 280 (-1.41%)
Mutual labels:  django
Drfx
A framework for launching new Django Rest Framework projects quickly.
Stars: ✭ 267 (-5.99%)
Mutual labels:  django
Djblets
A collection of useful extensions for Django.
Stars: ✭ 275 (-3.17%)
Mutual labels:  django
Djangoforprofessionals
Source code for Django for Professionals
Stars: ✭ 274 (-3.52%)
Mutual labels:  django
Django Datatable View
Server-side datatable representations for Django querysets for automatic rendering in templates
Stars: ✭ 282 (-0.7%)
Mutual labels:  django
Socialhome
A federated social home
Stars: ✭ 282 (-0.7%)
Mutual labels:  django

=============== django-honeypot

.. image:: https://github.com/jamesturk/django-honeypot/workflows/Test/badge.svg

.. image:: https://img.shields.io/pypi/v/django-honeypot.svg :target: https://pypi.python.org/pypi/django-honeypot

Django application that provides utilities for preventing automated form spam.

Provides template tags, view decorators, and middleware to add and verify honeypot fields to forms.

Written by James Turk with contributions by Flavio Curella and Daniel Greenfeld.

Source: https://github.com/jamesturk/django-honeypot/

Requirements

  • python >= 3.6
  • django >= 2.2

(django-honeypot 0.7 supports Django 1.11 and Python 2.7)

Usage

settings.py

Be sure to add honeypot to INSTALLED_APPS in settings.py.

You will almost always need to define HONEYPOT_FIELD_NAME which is the name to use for the honeypot field. Some sophisticated bots will attempt to avoid fields named honeypot, so it may be wise to name the field something slightly more realistic such as "phonenumber" or "body2".

HONEYPOT_VALUE is an option that you can specify to populate the honeypot field, by default the honeypot field will be empty and any text entered into it will result in a failed POST. HONEYPOT_VALUE can be a string or a callable that takes no arguments.

HONEYPOT_VERIFIER is an advanced option that you can specify to validate the honeypot. The default verifier ensures that the contents of the honeypot field matches HONEYPOT_VALUE. Using a combination of a callable for HONEYPOT_VALUE and HONEYPOT_VERIFIER it is possible to implement a more advanced technique such as using timestamps.

Adding honeypot fields to specific forms and views

It is possible to add honeypot fields to specific forms and ensure that specific views check for a valid honeypotin request.POST. This can be accomplished by using the render_honeypot_field template tag:

At the top of a template file include the line::

{% load honeypot %}

And then within any form including the tag::

{% render_honeypot_field "field_name" %}

will render a honeypot field named "field_name" that is hidden by default. The name of the honeypot field will default to HONEYPOT_FIELD_NAME if one is not provided.

To ensure that the honeypot field is both present and correct you will need to use check_honeypot decorator from honeypot.decorators:

.. code:: python

from honeypot.decorators import check_honeypot

@check_honeypot(field_name='hp_field_name')
def post_comment(request):
    ...

@check_honeypot
def other_post_view(request):
    ...

This decorator will ensure that a field exists in request.POST that is named 'field_name'. @check_honeypot without arguments will use the default HONEYPOT_FIELD_NAME.

Adding honeypot fields site-wide

Sometimes it is desirable to add honeypots to all forms site-wide. This is particularly useful when dealing with apps that render their own forms. For this purpose three middlewares are provided, similar in functionality to django's own CSRF middleware.

All of these middleware live in honeypot.middleware.

HoneypotResponseMiddleware analyzes the output of all responses and rewrites any forms that use method="POST" to contain a honeypot field, just as if they had started with {% render_honeypot_field %}. Borrowing heavily from django.contrib.csrf.middleware.CsrfResponseMiddleware this middleware only rewrites responses with Content-Type text/html or application/xhtml+xml.

HoneypotViewMiddleware ensures that for all incoming POST requests to views request.POST contains a valid honeypot field as defined by the HONEYPOT_FIELD_NAME, HONEYPOT_VALUE, and HONEYPOT_VERIFIER settings. The result is the same as if every view in your project were decorated with @check_honeypot.

HoneypotMiddleware is a combined middleware that applies both HoneypotResponseMiddleware and HoneypotViewMiddleware, this is the easiest way to get honeypot fields site-wide and can be used in many if not most cases.

Customizing honeypot display

There are two templates used by django-honeypot that can be used to control various aspects of how the honeypot functionality is presented to the user.

honeypot/honeypot_field.html is used to render the honeypot field. It is given two context variables fieldname and value, corresponding to HONEYPOT_FIELD_NAME and HONEYPOT_VALUE or any overrides in effect (such as a custom field name passed to the template tag).

honeypot/honeypot_error.html is the error page rendered when a bad request is intercepted. It is given the context variable fieldname representing the name of the honeypot field.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].