Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 1.86 KB

flask.md

File metadata and controls

63 lines (48 loc) · 1.86 KB

Flask

  1. Install aikido_zen package with pip :
pip install aikido_zen
  1. Add the following snippet to the top of your app.py file :
import aikido_zen
aikido_zen.protect()

Make sure this is above any other import, including above builtin package imports.

  1. Setting your environment variables : Make sure to set your token in order to communicate with Aikido's servers
AIKIDO_TOKEN="AIK_RUNTIME_YOUR_TOKEN_HERE"

Using gUnicorn

If you're using gunicorn, please check our docs on that first : Click Here

Blocking mode

By default, the firewall will run in non-blocking mode. When it detects an attack, the attack will be reported to Aikido and continue executing the call.

You can enable blocking mode by setting the environment variable AIKIDO_BLOCKING to true:

AIKIDO_BLOCKING=true

It's recommended to enable this on your staging environment for a considerable amount of time before enabling it on your production environment (e.g. one week).

Rate limiting and user blocking

If you want to add the rate limiting feature to your app, modify your code like this:

from aikido_zen.middleware import AikidoFlaskMiddleware

app = Flask(__name__)
# ...
app.wsgi_app = AikidoFlaskMiddleware(app.wsgi_app)
# ...
# Authorization middleware here (Make sure aikido middleware runs after this)
# ...

As soon as you identify the user in you authorization middleware, pass the identity info to Aikido.

from aikido_zen import set_user

# Set a user (presumably in middleware) :
set_user({"id": "123", "name": "John Doe"})

Debug mode

If you need to debug the firewall, you can run your code with the environment variable AIKIDO_DEBUG set to true:

AIKIDO_DEBUG=true

This will output debug information to the console (e.g. no token was found, unsupported packages, extra information, ...).