-
Notifications
You must be signed in to change notification settings - Fork 1
fix: resolve 11 CodeQL path-injection alerts in Go CLI #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -181,7 +181,11 @@ | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func writeInitFiles(state config.State) error { | ||||||||||||||
| if err := config.EnsureDir(state.DataDir); err != nil { | ||||||||||||||
| safeDir, err := config.SecurePath(state.DataDir) | ||||||||||||||
| if err != nil { | ||||||||||||||
| return err | ||||||||||||||
| } | ||||||||||||||
| if err := config.EnsureDir(safeDir); err != nil { | ||||||||||||||
| return fmt.Errorf("creating data directory: %w", err) | ||||||||||||||
| } | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a small redundancy here. You get a To avoid this, you could call
Suggested change
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
|
|
@@ -191,7 +195,7 @@ | |||||||||||||
| return fmt.Errorf("generating compose file: %w", err) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| composePath := filepath.Join(state.DataDir, "compose.yml") | ||||||||||||||
| composePath := filepath.Join(safeDir, "compose.yml") | ||||||||||||||
| if err := os.WriteFile(composePath, composeYAML, 0o600); err != nil { | ||||||||||||||
| return fmt.Errorf("writing compose file: %w", err) | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -228,7 +232,8 @@ | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func fileExists(path string) bool { | ||||||||||||||
| _, err := os.Stat(path) | ||||||||||||||
| clean := filepath.Clean(path) | ||||||||||||||
| _, err := os.Stat(clean) | ||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||||||||||
| return err == nil | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,8 +41,12 @@ | |||||||||||||
| // Load reads State from disk. Returns a default state with the given dataDir | ||||||||||||||
| // if the file does not exist (so --data-dir is respected on bootstrap). | ||||||||||||||
| func Load(dataDir string) (State, error) { | ||||||||||||||
| path := StatePath(dataDir) | ||||||||||||||
| data, err := os.ReadFile(path) | ||||||||||||||
| safeDir, err := SecurePath(dataDir) | ||||||||||||||
| if err != nil { | ||||||||||||||
| return State{}, err | ||||||||||||||
| } | ||||||||||||||
| path := StatePath(safeDir) | ||||||||||||||
| data, err := os.ReadFile(path) //nolint:gosec // path validated by SecurePath | ||||||||||||||
|
|
||||||||||||||
| if err != nil { | ||||||||||||||
| if errors.Is(err, os.ErrNotExist) { | ||||||||||||||
| defaults := DefaultState() | ||||||||||||||
|
|
@@ -73,12 +77,16 @@ | |||||||||||||
|
|
||||||||||||||
| // Save writes State to disk as indented JSON. | ||||||||||||||
| func Save(s State) error { | ||||||||||||||
| if err := EnsureDir(s.DataDir); err != nil { | ||||||||||||||
| safeDir, err := SecurePath(s.DataDir) | ||||||||||||||
| if err != nil { | ||||||||||||||
| return err | ||||||||||||||
| } | ||||||||||||||
| if err := EnsureDir(safeDir); err != nil { | ||||||||||||||
| return err | ||||||||||||||
| } | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a redundant call to You can call
Suggested change
|
||||||||||||||
| data, err := json.MarshalIndent(s, "", " ") | ||||||||||||||
| if err != nil { | ||||||||||||||
| return err | ||||||||||||||
| } | ||||||||||||||
| return os.WriteFile(StatePath(s.DataDir), data, 0o600) | ||||||||||||||
| return os.WriteFile(StatePath(safeDir), data, 0o600) //nolint:gosec // path validated by SecurePath | ||||||||||||||
|
Comment on lines
75
to
+88
|
||||||||||||||
| } | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.