Skip to content

Commit

Permalink
ensure files are unable to escape the capture directory
Browse files Browse the repository at this point in the history
  • Loading branch information
davemay99 committed Nov 25, 2020
1 parent 9685b84 commit 215a67f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion command/operator_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,15 @@ func (c *OperatorDebugCommand) path(paths ...string) string {

// mkdir creates directories in the tmp root directory
func (c *OperatorDebugCommand) mkdir(paths ...string) error {
return os.MkdirAll(c.path(paths...), 0755)
joinedPath := c.path(paths...)

// Ensure path doesn't escape the sandbox of the capture directory
escapes := helper.PathEscapesSandbox(c.collectDir, joinedPath)
if escapes {
return fmt.Errorf("file path escapes capture directory")
}

return os.MkdirAll(joinedPath, 0755)
}

// startMonitors starts go routines for each node and client
Expand Down Expand Up @@ -808,6 +816,12 @@ func (c *OperatorDebugCommand) writeBytes(dir, file string, data []byte) error {
return err
}

// Ensure filename doesn't escape the sandbox of the capture directory
escapes := helper.PathEscapesSandbox(c.collectDir, filePath)
if escapes { //&& sandboxEnabled {
return fmt.Errorf("file path escapes capture directory")
}

// Create the file
fh, err := os.Create(filePath)
if err != nil {
Expand Down

0 comments on commit 215a67f

Please sign in to comment.