URL spam security for Flask.
Project description
IpBan is a Flask extension that can help protect against ip locations spamming url requests against unknown pages. Often this is to search for security issues.
The default configuration:
50 attempts before ban
1 hour blocking period
Once an ip address is banned any attempt to access a web address will result in a 403 forbidden result. After the default 1 hour blocking period of no access attempts the ban will be lifted. Any access attempt during the ban period will extend the ban period.
Ip addresses can be manually entered for banning. Url patterns can be configured to be excluded from ban calculations.
Installation & Basic Usage
Install via pip:
pip install flask-ipban
After installing, wrap your Flask app with an IpBan, or call ip_ban.init_app(app):
from flask import Flask
from flask_ipban import IpBan
app = Flask(__name__)
IpBan(app)
Enclosed is a small example application
Options
ban_count, default 50, Number of observations before banning
ban_seconds, default 60, Number of seconds ip address is banned
Methods
block(ip_address, permanent=False) - block the specific address optionally forever
add(reason='404') - increase the observations for the current request ip
url_pattern_add('reg-ex-pattern') - exclude any url matching the pattern from checking
url_pattern_remove('reg-ex-pattern') - remove pattern from the url whitelist
url_block_pattern_add('reg-ex-pattern', match_type='regex') - add any url matching the pattern to the block list. match_type can be ‘string’ or ‘regex’. String is direct match. Regex is a regex pattern.
url_block_pattern_remove('reg-ex-pattern') - remove pattern from the url block list
ip_whitelist_add('ip-address') - exclude the given ip from checking
ip_whitelist_remove('ip-address') - remove the given ip from the ip whitelist
load_nuisances(file_name=None) - add a list of nuisances to url pattern block list from a file. See below for more information.
Example code
from flask import Flask
from flask_ipban import IpBan
app = Flask(__name__)
ip_ban = IpBan(app)
@app.route('/normal')
def normal():
return 'Normal'
Nuisance file
ip_ban includes a file of common web nuisances that should not be allowed on a flask site. It includes:
Blocking any non flask extension such as .jsp, .asp etc.
Known hacking urls.
Load them by calling ip_ban.load_nuisances()
You can add your own nuisance file by calling with the parameter file_name=.
See the nuisance.txt file in the source for formatting and details.
Licensing
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file flask_ipban-0.1.8-py2.py3-none-any.whl
.
File metadata
- Download URL: flask_ipban-0.1.8-py2.py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74f1c2ea25640391669969e826577cc75a06d7eadf8493c84b62cfe022d97e92 |
|
MD5 | 9d5121a778dd64c8ac80b2a2d0d9d532 |
|
BLAKE2b-256 | f5830f5cc1e1b4ec30ea45ef7244874373c6ba0cd132efdb1650fe44fe4f53de |