安全修复: - 创建 UserSelfUpdate schema,禁止用户修改自己的 role 和 is_active - /users/me 端点现在使用 UserSelfUpdate 而非 UserUpdate 安全增强: - 添加 SecurityHeadersMiddleware 中间件 - X-Content-Type-Options: nosniff - X-Frame-Options: DENY - X-XSS-Protection: 1; mode=block - Referrer-Policy: strict-origin-when-cross-origin - Permissions-Policy: 禁用敏感功能 - Cache-Control: API响应不缓存
This commit is contained in:
@@ -98,13 +98,16 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
# 添加限流中间件
|
||||
from app.core.middleware import RateLimitMiddleware
|
||||
from app.core.middleware import RateLimitMiddleware, SecurityHeadersMiddleware
|
||||
app.add_middleware(
|
||||
RateLimitMiddleware,
|
||||
requests_per_minute=120, # 每分钟最大请求数
|
||||
burst_limit=200, # 突发请求限制
|
||||
)
|
||||
|
||||
# 添加安全响应头中间件
|
||||
app.add_middleware(SecurityHeadersMiddleware)
|
||||
|
||||
|
||||
# 健康检查端点
|
||||
@app.get("/health")
|
||||
|
||||
Reference in New Issue
Block a user