fix: 코드 리뷰 기반 보안·안정성 개선 2차
All checks were successful
Server CI/CD / deploy (push) Successful in 1m26s
All checks were successful
Server CI/CD / deploy (push) Successful in 1m26s
보안: - RPC 응답 HTTP 상태코드 검증 (chain/client) - SSAFY OAuth 에러 응답 내부 로깅으로 변경 (제3자 상세 노출 제거) - resolveUsername에서 username 노출 제거 - LIKE 쿼리 특수문자 이스케이프 (bossraid/repository) - 파일명 경로 순회 방지 + 길이 제한 (download/handler) - ServerAuth 실패 로깅 추가 안정성: - AutoMigrate 에러 시 서버 종료 - GetLatest() 에러 시 nil 반환 (초기화 안 된 포인터 방지) - 멱등성 캐시 저장 시 새 context 사용 - SSAFY HTTP 클라이언트 타임아웃 10s - io.ReadAll/rand.Read 에러 처리 - Login에서 DB 에러/Not Found 구분 검증 강화: - 중복 플레이어 검증 (bossraid/service) - username 길이 제한 50자 (auth/handler, bossraid/handler) - 역할 변경 시 세션 무효화 - 지갑 복호화 실패 로깅 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"a301_server/pkg/config"
|
||||
@@ -72,6 +73,7 @@ func AdminOnly(c *fiber.Ctx) error {
|
||||
func ServerAuth(c *fiber.Ctx) error {
|
||||
key := c.Get("X-API-Key")
|
||||
if key == "" || config.C.InternalAPIKey == "" || key != config.C.InternalAPIKey {
|
||||
log.Printf("ServerAuth 실패: IP=%s, Path=%s, KeyPresent=%v", c.IP(), c.Path(), key != "")
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "유효하지 않은 API 키입니다"})
|
||||
}
|
||||
return c.Next()
|
||||
|
||||
@@ -58,7 +58,9 @@ func Idempotency(c *fiber.Ctx) error {
|
||||
if status >= 200 && status < 300 {
|
||||
cr := cachedResponse{StatusCode: status, Body: c.Response().Body()}
|
||||
if data, err := json.Marshal(cr); err == nil {
|
||||
if err := database.RDB.Set(ctx, redisKey, data, idempotencyTTL).Err(); err != nil {
|
||||
writeCtx, writeCancel := context.WithTimeout(context.Background(), redisTimeout)
|
||||
defer writeCancel()
|
||||
if err := database.RDB.Set(writeCtx, redisKey, data, idempotencyTTL).Err(); err != nil {
|
||||
log.Printf("WARNING: idempotency cache write failed (key=%s): %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user