fix: 아키텍처 리뷰 HIGH/MEDIUM 이슈 10건 수정
All checks were successful
Server CI/CD / lint-and-build (push) Successful in 34s
Server CI/CD / deploy (push) Successful in 50s

HIGH (3건):
- 런처 파일 업로드 시 PE 헤더 검증 + 500MB 크기 제한 추가
- 체인 노드 URL 파싱 시 scheme/host 유효성 검증
- Dockerfile 비루트 사용자(app:1000) 실행

MEDIUM (7건):
- SSAFY username 충돌 시 랜덤 suffix로 최대 3회 재시도
- 내부 API username 검증 validID(256자) → validUsername(3~50자) 분리
- 동시 업로드 경합 방지 sync.Mutex 추가
- 프로덕션 환경변수 검증 강화 (DB_PASSWORD, OPERATOR_KEY_HEX, INTERNAL_API_KEY)
- Redis 에러 시 멱등성 요청 통과 → 503 거부로 변경
- CORS AllowOrigins 환경변수화 (CORS_ALLOW_ORIGINS)
- Refresh 엔드포인트 rate limiting 추가 (IP당 5 req/min)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-20 15:56:58 +09:00
parent e16e1b5e0a
commit cc9884bdfe
9 changed files with 140 additions and 47 deletions

View File

@@ -49,6 +49,10 @@ func validID(s string) bool {
return s != "" && len(s) <= maxIDLength
}
func validUsername(s string) bool {
return len(s) >= 3 && len(s) <= 50
}
// chainError classifies chain errors into appropriate HTTP responses.
// TxError (on-chain execution failure) maps to 422 with the chain's error detail.
// Other errors (network, timeout, build failures) remain 500.
@@ -640,8 +644,8 @@ func (h *Handler) InternalGrantReward(c *fiber.Ctx) error {
if err := c.BodyParser(&req); err != nil {
return apperror.ErrBadRequest
}
if !validID(req.Username) {
return apperror.BadRequest("username은 필수입니다")
if !validUsername(req.Username) {
return apperror.BadRequest("username은 3~50자여야 합니다")
}
result, err := h.svc.GrantRewardByUsername(req.Username, req.TokenAmount, req.Assets)
if err != nil {
@@ -672,8 +676,8 @@ func (h *Handler) InternalMintAsset(c *fiber.Ctx) error {
if err := c.BodyParser(&req); err != nil {
return apperror.ErrBadRequest
}
if !validID(req.TemplateID) || !validID(req.Username) {
return apperror.BadRequest("templateId와 username은 필수입니다")
if !validID(req.TemplateID) || !validUsername(req.Username) {
return apperror.BadRequest("templateId와 username은 필수입니다 (username: 3~50자)")
}
result, err := h.svc.MintAssetByUsername(req.TemplateID, req.Username, req.Properties)
if err != nil {
@@ -695,8 +699,8 @@ func (h *Handler) InternalMintAsset(c *fiber.Ctx) error {
// @Router /api/internal/chain/balance [get]
func (h *Handler) InternalGetBalance(c *fiber.Ctx) error {
username := c.Query("username")
if !validID(username) {
return apperror.BadRequest("username은 필수입니다")
if !validUsername(username) {
return apperror.BadRequest("username은 3~50자여야 합니다")
}
result, err := h.svc.GetBalanceByUsername(username)
if err != nil {
@@ -720,8 +724,8 @@ func (h *Handler) InternalGetBalance(c *fiber.Ctx) error {
// @Router /api/internal/chain/assets [get]
func (h *Handler) InternalGetAssets(c *fiber.Ctx) error {
username := c.Query("username")
if !validID(username) {
return apperror.BadRequest("username은 필수입니다")
if !validUsername(username) {
return apperror.BadRequest("username은 3~50자여야 합니다")
}
offset, limit := parsePagination(c)
result, err := h.svc.GetAssetsByUsername(username, offset, limit)
@@ -745,8 +749,8 @@ func (h *Handler) InternalGetAssets(c *fiber.Ctx) error {
// @Router /api/internal/chain/inventory [get]
func (h *Handler) InternalGetInventory(c *fiber.Ctx) error {
username := c.Query("username")
if !validID(username) {
return apperror.BadRequest("username은 필수입니다")
if !validUsername(username) {
return apperror.BadRequest("username은 3~50자여야 합니다")
}
result, err := h.svc.GetInventoryByUsername(username)
if err != nil {