chore(ops): nommer le stockage du rate limiting au lieu de le subir

SEC-WEB-004. Limiter() ne nommait aucun stockage, donc Flask-Limiter
retombait sur memory://. Le choix n'avait jamais ete fait : c'etait
simplement ce qui arrivait.

Pour un seul processus Waitress, memory:// est la bonne reponse -- ce qui
est precisement pourquoi il fallait l'ecrire. Un deuxieme worker laisserait
passer deux fois chaque limite, en silence, avec une configuration qui a
l'air inchangee. RATELIMIT_STORAGE_URI rend la valeur lisible dans .env,
modifiable en une ligne le jour ou le deploiement gagne un processus, et le
demarrage journalise laquelle est active.

La part qui reste bloquee est nommee dans le code : un stockage partage ne
rend pas les limites solides tant qu'elles sont indexees sur une adresse IP
falsifiable, c'est-a-dire tant qu'OPS-002 / SEC-WEB-002 n'est pas tranche
avec le developpeur. C'est pour cela que celui-la est le prerequis et pas
celui-ci.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
GGThed
2026-08-11 18:35:27 -04:00
co-authored by Claude Opus 5
parent 06d6ad7eaa
commit 8d7de75e99
3 changed files with 76 additions and 1 deletions
+38
View File
@@ -75,3 +75,41 @@ class TestTemplateEscaping:
with app.app_context():
assert nl2br('') == ''
assert nl2br(None) == ''
class TestRateLimitStorage:
"""SEC-WEB-004 — the counters were in process memory by accident.
Flask-Limiter falls back to `memory://` when nothing names a storage, so
the choice was never made: it was simply what happened. For one Waitress
process that answer is correct, which is exactly why it needed writing
down — a second worker would double every limit, silently, and the
configuration would look untouched.
"""
def test_the_storage_is_named_rather_than_defaulted(self, app):
assert app.config['RATELIMIT_STORAGE_URI'] == 'memory://'
def test_the_environment_can_move_it(self, monkeypatch, tmp_path):
"""The point of naming it: the day the deployment gains a second
process, this is a one-line change and not a code change."""
from app.app import create_app
monkeypatch.setenv('RATELIMIT_STORAGE_URI', 'redis://cache.example.test:6379')
application = create_app(
{
'SECRET_KEY': 'test-secret-not-used-anywhere-real',
'SQLALCHEMY_DATABASE_URI': f'sqlite:///{tmp_path / "t.sqlite"}',
'TESTING': True,
'WTF_CSRF_ENABLED': False,
'FORCE_HTTPS': False,
'SESSION_COOKIE_SECURE': False,
'ENABLE_DISCORD_BOT': False,
'AUTO_CREATE_TABLES': False,
'CORS_ALLOWED_ORIGINS': '',
'RATELIMIT_ENABLED': False,
}
)
assert application.config['RATELIMIT_STORAGE_URI'] == 'redis://cache.example.test:6379'