Skip to main content

A smart Django security package to auto-block suspicious traffic

Project description

django-secux

django-secux ( All for in one )

PyPI version Python Versions Django Versions License Stars Issues Last Commit

django-secux is a simple yet powerful Django security package that protects heavy-load pages by rate-limiting access based on real usage patterns stored in the database.


Features

  • Automatically blocks overused views for a customizable time window
  • Super easy to use with just a decorator!
  • Mininfing and Cache Your HTML / CSS / JS / Images / Fonts
  • Image compressor with size argument ( e.g www.example.com/cdn/images/example.png?size=250 )

Installation

pip install django-secux

Then add it to your Django project:

# settings.py
INSTALLED_APPS = [
    ...
    'django_secux',
]

# if you want Minify
MIDDLEWARE = [
    ...
    'django_secux.middleware.Minify',
]

and if you using Fake CDN, add this to urls.py main:

from django_secux.views import cdn_serve

urlpatterns = [
    ...
    path('cdn/<path:file_path>', cdn_serve, name='cdn'),
]

Apply migrations:

python manage.py makemigrations django_secux
python manage.py migrate

Usage

Just decorate your heavy or sensitive views with @ai_ratelimit():

from django_secux.decorator import ai_ratelimit

@ai_ratelimit()
def my_view(request):
    return HttpResponse("Hello, world!")

This view will now be monitored. If accessed too frequently within a day, it will be blocked for 5 minutes.

And for Fake CDN use /cdn before static url. e.g:

<img src="/cdn{% static 'example.png' %}">

and for manage image resoulation, add size argument after static url. e.g:

<img src="/cdn{% static 'example.png' %}?size=128">

[!NOTE] you can use Fake CDN for images - fonts - css - js as static file.

[!Warning] size in Fake CDN only for images!


Customization & Configuration

for block messages:

SECUX_MESSAGES = {
    "blocked": "This page is temporarily blocked. Please try again later.",
    "rate_exceeded": "Rate limit exceeded. This page is blocked temporarily.",
}

and for static/media files:

SECUX_STATIC = [
    STATIC_ROOT,
    *STATICFILES_DIRS,
    ...
    os.path.join(BASE_DIR, "media/uploads"),
    os.path.join(BASE_DIR, "protected/images"),
]

Ideas or Issues?

Feel free to contribute, fork or submit issues on GitHub.

Let's keep Django apps safe and clean!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_secux-0.1.98.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_secux-0.1.98-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file django_secux-0.1.98.tar.gz.

File metadata

  • Download URL: django_secux-0.1.98.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_secux-0.1.98.tar.gz
Algorithm Hash digest
SHA256 a36849ea5444423c53af3d4b3ddb359e62e3377057949ead94bcb1f9ef26025b
MD5 101bdb2a9d9a31d7b18f2d0de9703d7c
BLAKE2b-256 692f135457bc44ef94902b4379b89b38a976d78b2462ac6bbc88b7a881d0c024

See more details on using hashes here.

File details

Details for the file django_secux-0.1.98-py3-none-any.whl.

File metadata

  • Download URL: django_secux-0.1.98-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_secux-0.1.98-py3-none-any.whl
Algorithm Hash digest
SHA256 e08e491e649260c8fbb438594af0ab24475e1efcf727d5b5bc4b65d74e65eabe
MD5 9b658c5baeb9520e61d2cee701f1811f
BLAKE2b-256 6419a6f59cf7f07cf7bf5f1fcac6e4294840cbb8f042e718f9db29189fda91a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page