diff --git a/config/config.go b/config/config.go index 52ee9f0..15e1088 100644 --- a/config/config.go +++ b/config/config.go @@ -263,6 +263,7 @@ func saveConfig(cfg *Config) *Config { conf.Section(defaultCoreConfig.ProfileName).ReflectFrom(&defaultProfile) conf.SaveTo(cfg.ConfigFile) } + makeFileUserPrivate(cfg.ConfigFile) conf := readConfig(cfg) @@ -318,6 +319,10 @@ func saveConfig(cfg *Config) *Config { profiles = append(profiles, profile.Name()) } + if cfg.HistoryFile != "" { + makeFileUserPrivate(cfg.HistoryFile) + } + return cfg } @@ -391,6 +396,14 @@ func (c *Config) UpdateConfig(key string, value string, update bool) { } } +func makeFileUserPrivate(filePath string) { + if fi, err := os.Stat(filePath); err == nil && fi.Mode().IsRegular() { + if err := os.Chmod(filePath, 0600); err != nil { + fmt.Printf("Failed to set permissions on %s: %v\n", filePath, err) + } + } +} + // NewConfig creates or reload config and loads API cache func NewConfig(configFilePath *string) *Config { defaultConf := defaultConfig()