From f2d836159de4b170b4386767072cc563a3c25e4d Mon Sep 17 00:00:00 2001 From: Cesura Date: Thu, 15 Apr 2021 16:04:05 +0300 Subject: [PATCH] Fix rate limiting issue --- app.py | 1 - pastey/routes.py | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index b0ea61e..e5a8a07 100644 --- a/app.py +++ b/app.py @@ -26,7 +26,6 @@ config.listen_port = environ["PASTEY_LISTEN_PORT"] if "PASTEY_LISTEN_PORT" in en config.use_whitelist = bool(strtobool(environ["PASTEY_USE_WHITELIST"])) if "PASTEY_USE_WHITELIST" in environ else config.use_whitelist config.restrict_pasting = bool(strtobool(environ["PASTEY_RESTRICT_PASTING"])) if "PASTEY_RESTRICT_PASTING" in environ else config.restrict_pasting config.restrict_raw_pasting = bool(strtobool(environ["PASTEY_RESTRICT_RAW_PASTING"])) if "PASTEY_RESTRICT_RAW_PASTING" in environ else config.restrict_raw_pasting -config.rate_limit = environ["PASTEY_RATE_LIMIT"] if "PASTEY_RATE_LIMIT" in environ else config.rate_limit config.guess_threshold = float(environ["PASTEY_GUESS_THRESHOLD"]) if "PASTEY_GUESS_THRESHOLD" in environ else config.guess_threshold config.recent_pastes = int(environ["PASTEY_RECENT_PASTES"]) if "PASTEY_RECENT_PASTES" in environ else config.recent_pastes config.whitelist_cidr = environ["PASTEY_WHITELIST_CIDR"].split(",") if "PASTEY_WHITELIST_CIDR" in environ else config.whitelist_cidr diff --git a/pastey/routes.py b/pastey/routes.py index ef13fea..e90f4d1 100644 --- a/pastey/routes.py +++ b/pastey/routes.py @@ -4,10 +4,15 @@ from . import config, common, functions from flask import Flask, render_template, request, redirect, abort from urllib.parse import quote from datetime import datetime +from os import environ # Load themes loaded_themes = common.get_themes() +# Set rate limit +# Workaround for @limiter annotations being parsed early +config.rate_limit = environ["PASTEY_RATE_LIMIT"] if "PASTEY_RATE_LIMIT" in environ else config.rate_limit + ########## Routes ########## # Home page