Skip to content

Commit b69df97

Browse files
Ompragashclaude
andcommitted
fix: improve PLUGIN_CONFIG handling with JSON-first validation
- Use JSON validation to distinguish between config content and file paths - Prevents sensitive data exposure in error logs - Provides clearer, user-friendly error messages - Maintains full backward compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 2acd230 commit b69df97

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

docker.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,21 @@ func (p Plugin) Exec() error {
203203

204204
path := filepath.Join(dockerHome, "config.json")
205205
var content []byte
206-
// Check if PLUGIN_CONFIG is a file path by attempting to stat it
207-
if _, err := os.Stat(p.Login.Config); err == nil {
208-
// File exists, read it
206+
// Try to parse as JSON first to determine if it's content or file path
207+
var jsonTest interface{}
208+
if json.Unmarshal([]byte(p.Login.Config), &jsonTest) == nil {
209+
// Valid JSON, treat as content
210+
content = []byte(p.Login.Config)
211+
} else if _, err := os.Stat(p.Login.Config); err == nil {
212+
// Not JSON but file exists, read it
209213
data, err := os.ReadFile(p.Login.Config)
210214
if err != nil {
211-
return fmt.Errorf("Error reading docker config file %s: %s", p.Login.Config, err)
215+
return fmt.Errorf("Error reading docker config file '%s': %s", p.Login.Config, err)
212216
}
213217
content = data
214-
} else if os.IsNotExist(err) {
215-
// Not a file, treat as JSON content (backward compatible)
216-
content = []byte(p.Login.Config)
217218
} else {
218-
// Some other error (permissions, etc.)
219-
return fmt.Errorf("Error checking docker config %s: %s", p.Login.Config, err)
219+
// Neither valid JSON nor existing file
220+
return fmt.Errorf("Docker config must be either valid JSON content or a path to an existing config file")
220221
}
221222
if err := os.WriteFile(path, content, 0600); err != nil {
222223
return fmt.Errorf("Error writing config.json: %s", err)

0 commit comments

Comments
 (0)