Skip to content

Commit

Permalink
1.0.8 Final. Improve doco. Increase default timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew rowe committed May 2, 2019
1 parent 19bf7a4 commit ca92446
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
26 changes: 15 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ IpBan: HTTP spam security for Flask

|PyPI Version|

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.
IpBan is a Flask extension that can help protect against ip sources spamming url requests
against unknown pages or attempts to exploit URLs. Often this is to search for security issues.

The default configuration:

- 20 attempts before ban
- 1 hour blocking period
- 1 day blocking period

Once an ip address is banned any attempt to access a web address on your site from that ip will
result in a 403 forbidden status response. 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.
result in a 403 forbidden status response. After the default 1 day blocking period of no access
attempts the ban will be lifted. Any access attempt during the ban period will extend the ban period
by the `ban_seconds` amount.

Ip addresses can be entered for banning by the api.

Expand Down Expand Up @@ -49,13 +50,13 @@ Options

- ``app``, Flask application to monitor. Use ip_ban.init_app(app) to intialise later on.
- ``ban_count``, default ``20``, Number of observations before banning.
- ``ban_seconds``, default ``60``, Number of seconds ip address is banned.
- ``ban_seconds``, default ``3600*24 (one day)``, Number of seconds ip address is banned.
- ``persist``, default ``False``, Persist ban list between restarts, using records in the report_dir folder.
- ``report_dir``, default ``None``, Override the location of persistence and report files.
- ``ipc``, default ``False``, Allow multiple instances of ip_ban to cross communicate using the ``report_dir``.
- ``secret_key``, default ``flask secret key``, Key to sign reports in the ``report_dir``.
- ``ip_header``, default ``None``, Optional name of request header that contains the ip for use behind proxies when in a docker/kube hosted env.
- ``abuse_IPDB_config``, default ``None``, config {key=,report=False,load=False} to a AbuseIPDB.com account. Blocked ip addresses via url nuisance matching will be reported.
- ``abuse_IPDB_config``, default ``None``, config {key=, report=False, load=False} to a AbuseIPDB.com account. Blocked ip addresses via url nuisance matching will be reported.

Config by env variable overrides options
########################################
Expand All @@ -70,7 +71,7 @@ Methods
-------

- ``init_app(app)`` - Initialise and start ip_ban with the given Flask application.
- ``block(ip_address, permanent=False)`` - block the specific address optionally forever
- ``block(ip_address, permanent=False)`` - block the specific address, optionally forever
- ``add(ip=None, url=None, reason='404')`` - increase the observations for the current request ip or given ip address

Example for add:
Expand Down Expand Up @@ -196,16 +197,19 @@ Then when initializing ip_ban set the header name using the parameter ``ip_heade
Abuse IPDB
----------
You can setup so that flask-ipban will auto report url hacking attempts to the Abuse IPDB. Or you can
load the Abuse IPDB list of blocked ip address on start. Warning! This takes a while to load 10000 records.
see: https://docs.abuseipdb.com/#introduction
You can setup flask-ipban so it will auto report url hacking attempts to the Abuse IPDB. Or you can
load the Abuse IPDB list of blocked ip address on start. Warning! Loading takes a while for the default 10000 records.
*Config*
abuse_IPDB_config = {key=,report=False,load=False}
abuse_IPDB_config = {key=, report=False, load=False, debug=False}
* key - your abuse IPDB api v2 key
* report - True/False (default is False) - report hack attempts to the DB.
* load - True/False (default is False) - load and block already blocked ip addresses from the DB on startup
* debug - True/False (default is False) - debug mode, uses ip 127.0.0.1.
Licensing
Expand Down
2 changes: 1 addition & 1 deletion example_app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flask>=1.0.2
flask-ipban>=1.0.7
flask-ipban>=1.0.8
2 changes: 1 addition & 1 deletion flask_ipban/abuse_ipdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def report_ip(self, ip, reason, categories=None):
"""
:param ip: the address being reported
:param reason: reason for report
:param categories: numbered list of report categories. 21 is web app attack
:param categories: numbered list of report categories. default 21 is web app attack
:return success code: ['already','error','ok','']
"""
if not self.report:
Expand Down
4 changes: 2 additions & 2 deletions flask_ipban/ip_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class IpBan:
"""

def __init__(self, app=None, ban_count=20, ban_seconds=3600, persist=False, record_dir=None, ipc=False,
def __init__(self, app=None, ban_count=20, ban_seconds=3600*24, persist=False, record_dir=None, ipc=False,
secret_key=None, ip_header=None, abuse_IPDB_config=None):
"""
start
Expand Down Expand Up @@ -334,7 +334,7 @@ def add(self, ip=None, url=None, reason='404', no_write=False, timestamp=None):
self.block([ip], no_write=no_write)
if not no_write and url and self.abuse_IPDB_config.get('key'):
# report if this is the first time ip seen and not a report from another instance
self.abuse_reporter.report_ip(ip, reason='flask_ip_ban. Exploit URL requested:{}'.format(url))
self.abuse_reporter.report_ip(ip, reason='Flask-IPban - exploit URL requested:{}'.format(url))
return True

if timestamp and timestamp > datetime.now():
Expand Down
4 changes: 2 additions & 2 deletions pypar.commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pip install twine

python3 setup.py sdist bdist_wheel
#
twine check dist/flask_ipban-1.0.7*
twine check dist/flask_ipban-1.0.8*
# test
# pip install -e .
# twine upload --repository-url https://test.pypi.org/legacy/ dist/* -u martlark
# prod pypi
# add release in git hub to match the version
twine upload dist/flask_ipban-1.0.7* -u martlark
twine upload dist/flask_ipban-1.0.8* -u martlark
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flask>=1.0.7
flask>=1.0.8
pytest
tox
twine
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
# limitations under the License.

from codecs import open

from setuptools import setup

long_description = open('README.rst', 'r', encoding='utf-8').read()
VERSION = '1.0.8'
LONG_DESCRIPTION = open('README.rst', 'r', encoding='utf-8').read()

setup(
name='flask-ipban',

version='1.0.7',
version=VERSION,

description='URL spam security for Flask.',
long_description=open('README.rst','r',encoding='utf-8').read(),
long_description=LONG_DESCRIPTION,
long_description_content_type='text/x-rst',

url='https://github.com/Martlark/flask-ipban',
download_url='https://github.com/Martlark/flask-ipban/archive/1.0.7.tar.gz',
download_url='https://github.com/Martlark/flask-ipban/archive/{version}.tar.gz'.format(VERSION),

author='Andrew Rowe',
author_email='[email protected]',
Expand Down Expand Up @@ -61,5 +61,5 @@

packages=['flask_ipban'],
include_package_data=True,
install_requires=['flask>=0.11','pyyaml', 'itsdangerous', 'requests'],
install_requires=['flask>=0.11', 'pyyaml', 'itsdangerous', 'requests'],
)

0 comments on commit ca92446

Please sign in to comment.