Skip to content

Commit 16d9b2b

Browse files
feat: Implement flask limiter on password-reset route
1 parent 3678dad commit 16d9b2b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

app/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from flask_script import Manager
1212
from flask_login import current_user
1313
from flask_jwt import JWT
14+
from flask_limiter import Limiter
1415
from datetime import timedelta
1516
from flask_cors import CORS
1617
from flask_rest_jsonapi.errors import jsonapi_errors
@@ -50,6 +51,7 @@
5051
static_dir = os.path.dirname(os.path.dirname(__file__)) + "/static"
5152
template_dir = os.path.dirname(__file__) + "/templates"
5253
app = Flask(__name__, static_folder=static_dir, template_folder=template_dir)
54+
limiter = Limiter(app)
5355
env.read_envfile()
5456

5557

app/api/auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from app.api.helpers.storage import generate_hash
1414

1515
from app import get_settings
16+
from app import limiter
1617
from app.api.helpers.db import save_to_db, get_count
1718
from app.api.helpers.errors import ForbiddenError, UnprocessableEntityError, NotFoundError, BadRequestError
1819
from app.api.helpers.files import make_frontend_url
@@ -29,7 +30,6 @@
2930
from app.models.user import User
3031
from app.api.helpers.storage import UPLOAD_PATHS
3132

32-
3333
authorised_blueprint = Blueprint('authorised_blueprint', __name__, url_prefix='/')
3434
ticket_blueprint = Blueprint('ticket_blueprint', __name__, url_prefix='/v1')
3535
auth_routes = Blueprint('auth', __name__, url_prefix='/v1/auth')
@@ -207,6 +207,9 @@ def resend_verification_email():
207207

208208

209209
@auth_routes.route('/reset-password', methods=['POST'])
210+
@limiter.limit(
211+
'3/hour', key_func=lambda: request.json['data']['email'], error_message='Limit for this action exceeded'
212+
)
210213
def reset_password_post():
211214
try:
212215
email = request.json['data']['email']

requirements/common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pycparser==2.14 # Only 2.14 works.
22
Flask~=1.0.3
3+
Flask-Limiter~=1.0.1
34
Flask-Script~=2.0.6
45
Flask-SQLAlchemy~=2.1
56
Flask-Migrate~=2.5

0 commit comments

Comments
 (0)