From ca63b871238ff8c5ee08bfee4f34727b5c567e39 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 16 Mar 2026 20:23:18 -0300 Subject: [PATCH] implement CSRF protection by adding token generation, validation, and cookie management in login flows --- .../auth-gateway/auth_gateway/settings.py | 1 + .../templates/login_password.html | 1 + .../auth_gateway/templates/login_totp.html | 1 + .../auth_gateway/templates/session.html | 1 + .../auth_gateway/web/dependencies.py | 28 ++++ .../auth_gateway/web/login_routes.py | 126 +++++++++++++++--- .../tests/test_config_and_policy.py | 42 ++++++ containers/caddy/process_config.py | 38 +++++- 8 files changed, 214 insertions(+), 24 deletions(-) diff --git a/containers/auth-gateway/auth_gateway/settings.py b/containers/auth-gateway/auth_gateway/settings.py index 9d0717d..724f6bf 100644 --- a/containers/auth-gateway/auth_gateway/settings.py +++ b/containers/auth-gateway/auth_gateway/settings.py @@ -10,6 +10,7 @@ class Settings(BaseSettings): config_dir: Path = Field(default=Path("/caddy_json_export")) database_path: Path = Field(default=Path("/data/auth-gateway.sqlite3")) cookie_name: str = Field(default="auth_gateway_session") + csrf_cookie_name: str = Field(default="auth_gateway_csrf") external_path: str = Field(default="/auth-gateway") secure_cookies: bool = Field(default=True) session_default_minutes: int = Field(default=720) diff --git a/containers/auth-gateway/auth_gateway/templates/login_password.html b/containers/auth-gateway/auth_gateway/templates/login_password.html index 21873f9..2ec7031 100644 --- a/containers/auth-gateway/auth_gateway/templates/login_password.html +++ b/containers/auth-gateway/auth_gateway/templates/login_password.html @@ -7,6 +7,7 @@
{{ error }}
{% endif %}
+