fix: 코드 리뷰 기반 보안·안정성 개선 2차
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:
2026-03-13 17:48:05 +09:00
parent 61cf47070d
commit cc751653c4
12 changed files with 85 additions and 19 deletions

View File

@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"github.com/tolelom/tolchain/core"
tocrypto "github.com/tolelom/tolchain/crypto"
@@ -35,11 +36,11 @@ func (s *Service) resolveUsername(username string) (string, error) {
}
userID, err := s.userResolver(username)
if err != nil {
return "", fmt.Errorf("user not found: %s", username)
return "", fmt.Errorf("user not found")
}
uw, err := s.repo.FindByUserID(userID)
if err != nil {
return "", fmt.Errorf("wallet not found for user: %s", username)
return "", fmt.Errorf("wallet not found")
}
return uw.PubKeyHex, nil
}
@@ -156,7 +157,8 @@ func (s *Service) loadUserWallet(userID uint) (*wallet.Wallet, string, error) {
}
privKey, err := s.decryptPrivKey(uw.EncryptedPrivKey, uw.EncNonce)
if err != nil {
return nil, "", err
log.Printf("WARNING: wallet decryption failed for userID=%d: %v", userID, err)
return nil, "", fmt.Errorf("wallet decryption failed")
}
return wallet.New(privKey), uw.PubKeyHex, nil
}