From 94aa8dc572207efefe4ac5dc1eeff6e97bb30697 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 13 Jun 2025 19:30:14 +0000 Subject: [PATCH] fix: harden log directory creation and path resolution (#61) - Ensure the log directory is created with secure permissions, falling back to the temp directory if creation fails - Update log file path to use the resolved log directory fix https://gitea.com/gitea/gitea-mcp/issues/58 Signed-off-by: Bo-Yi Wu Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/61 Reviewed-by: Lunny Xiao Co-authored-by: Bo-Yi Wu Co-committed-by: Bo-Yi Wu --- pkg/log/log.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/log/log.go b/pkg/log/log.go index 46eefdf..1f2abe1 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -32,8 +32,14 @@ func Default() *zap.Logger { home = os.TempDir() } + logDir := fmt.Sprintf("%s/.gitea-mcp", home) + if err := os.MkdirAll(logDir, 0o700); err != nil { + // Fallback to temp directory if creation fails + logDir = os.TempDir() + } + wss = append(wss, zapcore.AddSync(&lumberjack.Logger{ - Filename: fmt.Sprintf("%s/.gitea-mcp/gitea-mcp.log", home), + Filename: fmt.Sprintf("%s/gitea-mcp.log", logDir), MaxSize: 100, MaxBackups: 10, MaxAge: 30,