Skip to content

Commit 81f221c

Browse files
committed
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.
1 parent c5bdc4b commit 81f221c

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

cmd/interactsh-client/main.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ func main() {
8686
flagSet.BoolVarP(&healthcheck, "hc", "health-check", false, "run diagnostic check up"),
8787
)
8888

89+
// If a custom config path is provided via -config, tell goflags before
90+
// Parse() so it doesn't try to create/read the default config location.
91+
for i := 1; i < len(os.Args); i++ {
92+
if (os.Args[i] == "-config" || os.Args[i] == "--config") && i+1 < len(os.Args) {
93+
flagSet.SetConfigFilePath(os.Args[i+1])
94+
break
95+
}
96+
if strings.HasPrefix(os.Args[i], "-config=") || strings.HasPrefix(os.Args[i], "--config=") {
97+
flagSet.SetConfigFilePath(strings.SplitN(os.Args[i], "=", 2)[1])
98+
break
99+
}
100+
}
101+
89102
if err := flagSet.Parse(); err != nil {
90103
gologger.Fatal().Msgf("Could not parse options: %s\n", err)
91104
}
@@ -133,12 +146,6 @@ func main() {
133146
}
134147
}
135148

136-
if fileutil.FileExists(cliOptions.Config) {
137-
if err := flagSet.MergeConfigFile(cliOptions.Config); err != nil {
138-
gologger.Fatal().Msgf("Could not read config: %s\n", err)
139-
}
140-
}
141-
142149
var outputFile *os.File
143150
var err error
144151
if cliOptions.Output != "" {

cmd/interactsh-server/main.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ func main() {
110110
flagSet.BoolVarP(&cliOptions.Verbose, "verbose", "v", false, "display verbose interaction"),
111111
)
112112

113+
// If a custom config path is provided via -config, tell goflags before
114+
// Parse() so it doesn't try to create/read the default config location.
115+
for i := 1; i < len(os.Args); i++ {
116+
if (os.Args[i] == "-config" || os.Args[i] == "--config") && i+1 < len(os.Args) {
117+
flagSet.SetConfigFilePath(os.Args[i+1])
118+
break
119+
}
120+
if strings.HasPrefix(os.Args[i], "-config=") || strings.HasPrefix(os.Args[i], "--config=") {
121+
flagSet.SetConfigFilePath(strings.SplitN(os.Args[i], "=", 2)[1])
122+
break
123+
}
124+
}
125+
113126
if err := flagSet.Parse(); err != nil {
114127
gologger.Fatal().Msgf("Could not parse options: %s\n", err)
115128
}
@@ -136,12 +149,6 @@ func main() {
136149
}
137150
}
138151

139-
if cliOptions.Config != defaultConfigLocation {
140-
if err := flagSet.MergeConfigFile(cliOptions.Config); err != nil {
141-
gologger.Fatal().Msgf("Could not read config: %s\n", err)
142-
}
143-
}
144-
145152
if len(cliOptions.Domains) == 0 {
146153
gologger.Fatal().Msgf("No domains specified\n")
147154
}

0 commit comments

Comments
 (0)