First plug an application to Sqreen and enable the webhook notifications (create a free account on https://my.sqreen.io).
We want to create a Python/Flask application that listen for webhook notifications from Sqreen.
On receiving a notification the application should:
- Check that the signature is correct
- Redispatch the notification to multiple targets (e.g. log, email, HTTP, SMS, Slack).
Requirements:
- Have a generic interface for target backends
- Two target backends
- Have relevant tests
Hints:
- The application that is receiving webhook can itself be Sqreened
- Detected attacks are batched 5-minutely between a running agent and Sqreen own backend (the first one will fire directly, then they are aggregated).
- One can easily generate a notification by calling: curl -A Arachni/v1.2.1 http://sqreened_application
Notes:
- You need to specify env. vars. in the
.env
file. - You can use
ngrok
to be able to expose the server to Sqreen. - The project uses
Github CI
instead ofCircleCI
orTravisCI
(which I already know so I wanted to testGithub CI
). - A pre-release of
black
is used until its installation requirements are fixed.
Installation:
poetry install
Test:
poetry run black --check .
poetry run pylint app.py sqreentest
poetry run mypy app.py sqreentest
env $(cat .env | xargs) poetry run pytest
Launch application:
FLASK_DEBUG=1 poetry run flask run
Implemented targets:
-
Currently if a webhook is not handled (bug in code, a target is unavailable, etc.) then it disappears as it is not stored in this application for retry (in a database for example). But I think in case of webhooks, it is the responsibility of the origin server to retry (possibly up to N times for example) until the destination returns a successful response (for example the infrastructure powering the destination server might be down). Did I miss something?
-
In the application, sample webhook payload is a JSON object while
curl
command is a JSON array as well as the data sent:
Same issue with the webhook sent when clicking on "Save Webhook", it also misses some keys defined in the specification:
- Sqreen does not seem to expose typings, which cause
mypy
to fail with:
> poetry run mypy app.py sqreentest
app.py:2: error: Cannot find module named 'sqreen'
app.py:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Current workaround is to replace:
import sqreen
by
import sqreen # type: ignore