- 입력 검증 강화 (로그인/체인 핸들러 전체) - boss raid 비관적 잠금으로 동시성 문제 해결 - SSAFY 사용자명 sanitize + 트랜잭션 처리 - constant-time API 키 비교, 보안 헤더, graceful shutdown - 안전하지 않은 기본값 경고 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
19
main.go
19
main.go
@@ -2,6 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"a301_server/internal/announcement"
|
||||
"a301_server/internal/auth"
|
||||
@@ -12,8 +16,8 @@ import (
|
||||
"github.com/tolelom/tolchain/core"
|
||||
"a301_server/pkg/config"
|
||||
"a301_server/pkg/database"
|
||||
"a301_server/pkg/middleware"
|
||||
"a301_server/routes"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
@@ -23,6 +27,7 @@ import (
|
||||
|
||||
func main() {
|
||||
config.Load()
|
||||
config.WarnInsecureDefaults()
|
||||
|
||||
if err := database.ConnectMySQL(); err != nil {
|
||||
log.Fatalf("MySQL 연결 실패: %v", err)
|
||||
@@ -101,6 +106,7 @@ func main() {
|
||||
BodyLimit: 4 * 1024 * 1024 * 1024, // 4GB
|
||||
})
|
||||
app.Use(logger.New())
|
||||
app.Use(middleware.SecurityHeaders)
|
||||
app.Use(cors.New(cors.Config{
|
||||
AllowOrigins: "https://a301.tolelom.xyz",
|
||||
AllowHeaders: "Origin, Content-Type, Authorization, Idempotency-Key, X-API-Key",
|
||||
@@ -133,5 +139,16 @@ func main() {
|
||||
|
||||
routes.Register(app, authHandler, annHandler, dlHandler, chainHandler, brHandler, authLimiter, apiLimiter)
|
||||
|
||||
// Graceful shutdown
|
||||
go func() {
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
||||
sig := <-sigCh
|
||||
log.Printf("수신된 시그널: %v — 서버 종료 중...", sig)
|
||||
if err := app.ShutdownWithTimeout(10 * time.Second); err != nil {
|
||||
log.Printf("서버 종료 실패: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
log.Fatal(app.Listen(":" + config.C.AppPort))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user