feat(güvenlik): giriş ve kayıtta Cloudflare Turnstile, IP başına 3 hatalı denemede 15 dk kilit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 00:29:00 +03:00
parent 5cbf97d884
commit a2eff1a984
27 changed files with 1247 additions and 164 deletions
+15 -2
View File
@@ -5,7 +5,7 @@ use std::{sync::Arc, time::Duration};
use mongodb::Database;
use crate::{
auth::{jwt::Jwt, limiter::LoginLimiter},
auth::{captcha::Captcha, guard::AttemptGuard, jwt::Jwt, limiter::LoginLimiter},
config::Config,
};
@@ -15,7 +15,11 @@ pub struct AppState {
pub db: Database,
pub config: Arc<Config>,
pub jwt: Arc<Jwt>,
/// Şifre değiştirmede mevcut şifre denemeleri (kullanıcı başına)
pub login_limiter: Arc<LoginLimiter>,
/// Giriş / kayıt: IP başına üst üste 3 hata → 15 dk kilit
pub guard: Arc<AttemptGuard>,
pub captcha: Arc<Captcha>,
}
impl AppState {
@@ -23,9 +27,18 @@ impl AppState {
Self {
db,
jwt: Arc::new(Jwt::new(&config.jwt_secret)),
// Aynı e-postaya 15 dakikada en fazla 5 hatalı giriş denemesi
login_limiter: Arc::new(LoginLimiter::new(5, Duration::from_secs(15 * 60))),
guard: Arc::new(AttemptGuard::default()),
captcha: Arc::new(Captcha::from_secret(config.turnstile_secret_key.as_deref())),
config: Arc::new(config),
}
}
}
impl AppState {
/// Testler: bot doğrulamasını ağsız sabit sonuçla değiştir
pub fn with_captcha(mut self, captcha: Captcha) -> Self {
self.captcha = Arc::new(captcha);
self
}
}