From 81f221c12de8b08fb03b2ed1e42c249c3eb6e6fc Mon Sep 17 00:00:00 2001 From: Mike Jensen Date: Fri, 13 Mar 2026 13:59:32 -0600 Subject: [PATCH] fix: Consistently use overriden config paths with -config flag When -config is provided, goflags' Parse() still attempts to read the default config path first, causing errors like: [FTL] Could not parse options: open /home/USER/.config/interactsh-server/config.yaml: read-only file system This change scans os.Args for -config before Parse() and call SetConfigFilePath() so goflags uses the custom path from the start. The post-parse MergeConfigFile/FileExists checks are removed since Parse() already performs the same existence check and merge internally. Applied to both interactsh-server and interactsh-client. --- cmd/interactsh-client/main.go | 19 +++++++++++++------ cmd/interactsh-server/main.go | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cmd/interactsh-client/main.go b/cmd/interactsh-client/main.go index 8a749c43..b116092c 100644 --- a/cmd/interactsh-client/main.go +++ b/cmd/interactsh-client/main.go @@ -86,6 +86,19 @@ func main() { flagSet.BoolVarP(&healthcheck, "hc", "health-check", false, "run diagnostic check up"), ) + // If a custom config path is provided via -config, tell goflags before + // Parse() so it doesn't try to create/read the default config location. + for i := 1; i < len(os.Args); i++ { + if (os.Args[i] == "-config" || os.Args[i] == "--config") && i+1 < len(os.Args) { + flagSet.SetConfigFilePath(os.Args[i+1]) + break + } + if strings.HasPrefix(os.Args[i], "-config=") || strings.HasPrefix(os.Args[i], "--config=") { + flagSet.SetConfigFilePath(strings.SplitN(os.Args[i], "=", 2)[1]) + break + } + } + if err := flagSet.Parse(); err != nil { gologger.Fatal().Msgf("Could not parse options: %s\n", err) } @@ -133,12 +146,6 @@ func main() { } } - if fileutil.FileExists(cliOptions.Config) { - if err := flagSet.MergeConfigFile(cliOptions.Config); err != nil { - gologger.Fatal().Msgf("Could not read config: %s\n", err) - } - } - var outputFile *os.File var err error if cliOptions.Output != "" { diff --git a/cmd/interactsh-server/main.go b/cmd/interactsh-server/main.go index e7344f55..a4412cbb 100644 --- a/cmd/interactsh-server/main.go +++ b/cmd/interactsh-server/main.go @@ -110,6 +110,19 @@ func main() { flagSet.BoolVarP(&cliOptions.Verbose, "verbose", "v", false, "display verbose interaction"), ) + // If a custom config path is provided via -config, tell goflags before + // Parse() so it doesn't try to create/read the default config location. + for i := 1; i < len(os.Args); i++ { + if (os.Args[i] == "-config" || os.Args[i] == "--config") && i+1 < len(os.Args) { + flagSet.SetConfigFilePath(os.Args[i+1]) + break + } + if strings.HasPrefix(os.Args[i], "-config=") || strings.HasPrefix(os.Args[i], "--config=") { + flagSet.SetConfigFilePath(strings.SplitN(os.Args[i], "=", 2)[1]) + break + } + } + if err := flagSet.Parse(); err != nil { gologger.Fatal().Msgf("Could not parse options: %s\n", err) } @@ -136,12 +149,6 @@ func main() { } } - if cliOptions.Config != defaultConfigLocation { - if err := flagSet.MergeConfigFile(cliOptions.Config); err != nil { - gologger.Fatal().Msgf("Could not read config: %s\n", err) - } - } - if len(cliOptions.Domains) == 0 { gologger.Fatal().Msgf("No domains specified\n") }