feat: 添加安全中间件、优化限流器与API密钥验证

1. 新增安全响应头中间件强化请求安全性
2. 使用恒定时间比较修复API密钥验证时序漏洞
3. 新增限流器条目上限配置与自动清理逻辑
4. 优化CORS日志与客户端IP获取逻辑
5. 升级Go构建环境与基础镜像版本
6. 新增非root用户运行容器增强安全性
This commit is contained in:
sun
2026-05-24 15:33:27 +08:00
parent 9c35f780db
commit 9b2a1d1531
8 changed files with 53 additions and 13 deletions
+8 -3
View File
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine AS builder
FROM golang:1.23-alpine AS builder
WORKDIR /app
@@ -9,15 +9,20 @@ COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o tts-api .
FROM alpine:3.18
FROM alpine:3.21
RUN apk --no-cache add ca-certificates tzdata
RUN apk --no-cache add ca-certificates tzdata \
&& addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
COPY --from=builder /app/tts-api .
COPY --from=builder /app/health.html .
RUN chown -R appuser:appgroup /app
USER appuser
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \