Skip to main content

Secure masonite apps from spamming Bots, IP's and SQL injections.

Project description

Masonite Package GitHub Workflow Status (branch) PyPI Python Version GitHub release (latest by date including pre-releases) License Code style: black

Masonite Security

Secure masonite apps from spamming Bots, IP's and SQL injections.

Features

  • Block IP's
  • Block Bots
  • Throttle Requests
  • Block SQL Injections

Installation

pip install masonite-security

Configuration

Add SecurityProvider to your project in config/providers.py:

# config/providers.py
# ...
from security import SecurityProvider

# ...
PROVIDERS = [
    # ...
    # Third Party Providers
    SecurityProvider,
    # ...
]

Then you can publish the package resources by doing:

python craft package:publish security

Register Middleware.

You can setup the security middleware globally or per route basis.

Global Setup

Open Kernal.py file and add SecurityMiddleware in "route_middleware" section:

route_middleware = {
      "web": [SessionMiddleware, LoadUserMiddleware, VerifyCsrfToken, SecurityMiddleware],
      "auth": [AuthenticationMiddleware],
  }

Per Route Setup

In your routes add protect middleware like this:

Route.get("/", "WelcomeController@show").middleware("protect")

Configure Security Config

Update your config/security.py file based on your needs:

# config/security.py
# ...
BLOCK_IP = True
BLOCK_BOTS = True
THROTTLE_REQUESTS = True

MAX_REQUESTS = 20 # Max requests per IP (default: 20)
IP_BLOCK_DURATION = 60  # seconds (default: 60)

# list of IP addresses to block (default: [])
BLOCKED_IPS = [
  #...
]

# list of Bot Agents to block
BLOCKED_BOTS = [
    #...
]
# ...

Contributing

Please read the Contributing Documentation here.

Maintainers

License

security is open-sourced software licensed under the MIT license.

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

masonite-security-0.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

masonite_security-0.0.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file masonite-security-0.0.1.tar.gz.

File metadata

  • Download URL: masonite-security-0.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for masonite-security-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4e42e9baaeb4b75c97c9389bd81e47ad63b1a08ab7cf7c5079eb2410f903c80e
MD5 bd7a81a0e5fd68f1cbec88e925b26d21
BLAKE2b-256 f29c7b72e7c1837cbe7f60bbea554fed2d21ff5abb563b23f052bf8f53b5b561

See more details on using hashes here.

File details

Details for the file masonite_security-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for masonite_security-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a90ec13f89359cb7216a1c6e7448d72f9607c27a79860230605c94a2f97d1090
MD5 85008c4681d988c60690e3fa1f019f39
BLAKE2b-256 4b289967d12083844244e5431c08b91f356b32422363591835a5f1da63d53885

See more details on using hashes here.

Supported by

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