1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-25 02:57:22 +00:00

Bugfix ratelimiter kobo

This commit is contained in:
Ozzieisaacs 2022-09-05 18:45:24 +02:00
parent 6598c4d259
commit 2472e03a69
3 changed files with 10 additions and 3 deletions

View File

@ -64,11 +64,12 @@ from datetime import datetime
from os import urandom from os import urandom
from functools import wraps from functools import wraps
from flask import g, Blueprint, url_for, abort, request from flask import g, Blueprint, abort, request
from flask_login import login_user, current_user, login_required from flask_login import login_user, current_user, login_required
from flask_babel import gettext as _ from flask_babel import gettext as _
from flask_limiter import RateLimitExceeded
from . import logger, config, calibre_db, db, helper, ub, lm from . import logger, config, calibre_db, db, helper, ub, lm, limiter
from .render_template import render_title_template from .render_template import render_title_template
log = logger.create() log = logger.create()
@ -151,6 +152,10 @@ def requires_kobo_auth(f):
def inner(*args, **kwargs): def inner(*args, **kwargs):
auth_token = get_auth_token() auth_token = get_auth_token()
if auth_token is not None: if auth_token is not None:
try:
limiter.check()
except RateLimitExceeded:
return abort(429)
user = ( user = (
ub.session.query(ub.User) ub.session.query(ub.User)
.join(ub.RemoteAuthToken) .join(ub.RemoteAuthToken)

View File

@ -44,6 +44,7 @@ def main():
try: try:
from .kobo import kobo, get_kobo_activated from .kobo import kobo, get_kobo_activated
from .kobo_auth import kobo_auth from .kobo_auth import kobo_auth
from flask_limiter.util import get_remote_address
kobo_available = get_kobo_activated() kobo_available = get_kobo_activated()
except (ImportError, AttributeError): # Catch also error for not installed flask-WTF (missing csrf decorator) except (ImportError, AttributeError): # Catch also error for not installed flask-WTF (missing csrf decorator)
kobo_available = False kobo_available = False
@ -73,6 +74,7 @@ def main():
if kobo_available: if kobo_available:
app.register_blueprint(kobo) app.register_blueprint(kobo)
app.register_blueprint(kobo_auth) app.register_blueprint(kobo_auth)
limiter.limit("10/minute", key_func=get_remote_address)(kobo)
if oauth_available: if oauth_available:
app.register_blueprint(oauth) app.register_blueprint(oauth)
success = web_server.start() success = web_server.start()

View File

@ -483,7 +483,7 @@ def check_auth(username, password):
try: try:
limiter.check() limiter.check()
except RateLimitExceeded: except RateLimitExceeded:
return False return abort(429) # False
try: try:
username = username.encode('windows-1252') username = username.encode('windows-1252')
except UnicodeEncodeError: except UnicodeEncodeError: