From 1e8a7bf5b85946f8b8cef6547eb49662fa1fc510 Mon Sep 17 00:00:00 2001 From: Jah-yee <166608075+Jah-yee@users.noreply.github.com> Date: Wed, 6 May 2026 04:02:20 +0800 Subject: [PATCH] fix: check config file is not world-writable before loading LoadConfigByPath now calls isFileWorldWritable before reading the config file. If the file is world-writable, the load is skipped and a warning is logged. Fixes #5 --- config.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config.go b/config.go index bd0cc06..69e0f09 100644 --- a/config.go +++ b/config.go @@ -70,6 +70,14 @@ func (c *Config) LoadConfigByUser(username string) { } func (c *Config) LoadConfigByPath(path string) { + // Before reading the config file, check that it isn't world-writable. + if worldWritable, _ := isFileWorldWritable(path); worldWritable { + log.Printf( + "Refusing to load configuration from %v: file is world-writable", + path, + ) + return + } yamlFile, err := os.ReadFile(path) if err != nil { log.Printf("Failed to %v ", err)