Add Redis rate limiting, login lockout, password policy and health probes
- RateLimitFilter: fixed-window counters in Redis (Lua INCR+PEXPIRE) per client IP for login, registration, refresh, check-login, post creation, uploads, chat start and public ad endpoints; 429 with Retry-After; fails open when Redis is down. Rules live in rate-limit.* in application.yaml. - Login is blocked for an account after 10 failed attempts in 15 minutes, independent of the client IP. - Registration requires a password of at least 8 characters. - server.forward-headers-strategy=native so the client IP survives a reverse proxy; graceful shutdown. - /actuator/health with liveness/readiness probes is public (no details). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
ffmpeg:
|
||||
binary-path: ${FFMPEG_PATH:C:\ffmpeg\ffmpeg-9.0.2-essentials_build\bin\ffmpeg.exe}
|
||||
|
||||
server:
|
||||
# За обратным прокси (nginx, балансировщик) IP клиента и схема берутся из
|
||||
# X-Forwarded-*: без этого лимиты считали бы все запросы с адреса прокси.
|
||||
# Tomcat доверяет заголовкам только от внутренних адресов (10/8, 172.16/12, 192.168/16, 127/8).
|
||||
forward-headers-strategy: ${FORWARD_HEADERS_STRATEGY:native}
|
||||
shutdown: graceful
|
||||
|
||||
spring:
|
||||
lifecycle:
|
||||
timeout-per-shutdown-phase: 20s
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 10MB
|
||||
@@ -96,4 +105,74 @@ jwt:
|
||||
|
||||
app:
|
||||
cors:
|
||||
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:5173,http://localhost:3000,http://192.168.1.76:3000}
|
||||
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:5173,http://localhost:3000,http://192.168.1.76:3000}
|
||||
|
||||
websocket:
|
||||
# Рассылка STOMP-сообщений во все экземпляры через Redis pub/sub (ClusterMessaging)
|
||||
cluster-broadcast: ${WS_CLUSTER_BROADCAST:true}
|
||||
|
||||
# Health-пробы для оркестратора/балансировщика: /actuator/health/liveness и /readiness
|
||||
# открыты без токена (SecurityConfig), подробности состояния наружу не отдаются
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health
|
||||
endpoint:
|
||||
health:
|
||||
probes:
|
||||
enabled: true
|
||||
show-details: never
|
||||
|
||||
# Лимиты запросов по IP (RateLimitFilter), счётчики в Redis — общие для всех экземпляров
|
||||
rate-limit:
|
||||
enabled: ${RATE_LIMIT_ENABLED:true}
|
||||
login:
|
||||
max-failures: 10 # неудачных входов в один аккаунт
|
||||
window: PT15M
|
||||
rules:
|
||||
- name: auth-login
|
||||
method: POST
|
||||
paths: [/api/v1/auth/login]
|
||||
limit: 20
|
||||
window: PT1M
|
||||
- name: auth-register
|
||||
method: POST
|
||||
paths: [/api/v1/auth/register]
|
||||
limit: 10
|
||||
window: PT1H
|
||||
- name: auth-refresh
|
||||
method: POST
|
||||
paths: [/api/v1/auth/refresh]
|
||||
limit: 60
|
||||
window: PT1M
|
||||
- name: auth-check-login
|
||||
method: GET
|
||||
paths: [/api/v1/auth/check-login]
|
||||
limit: 60
|
||||
window: PT1M
|
||||
- name: post-create
|
||||
method: POST
|
||||
paths: [/api/v1/posts]
|
||||
limit: 20
|
||||
window: PT1H
|
||||
- name: file-upload
|
||||
method: POST
|
||||
paths: [/api/v1/files]
|
||||
limit: 60
|
||||
window: PT1H
|
||||
- name: chat-start
|
||||
method: POST
|
||||
paths: [/api/v1/chats/with/**]
|
||||
limit: 30
|
||||
window: PT1M
|
||||
- name: ads-next
|
||||
method: GET
|
||||
paths: [/api/ads/next, /api/fullscreen-ad]
|
||||
limit: 120
|
||||
window: PT1M
|
||||
- name: ads-tracking
|
||||
method: POST
|
||||
paths: [/api/ads/impression, /api/ads/click]
|
||||
limit: 120
|
||||
window: PT1M
|
||||
|
||||
Reference in New Issue
Block a user