Skip to content

Commit

Permalink
feat(usage-view): address security issues from linter
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Wasilewski <[email protected]>
  • Loading branch information
mwasilew2 committed Jan 24, 2024
1 parent a4b3ac0 commit b89d328
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ key.*
*.asc

completions

*.csv
11 changes: 6 additions & 5 deletions internal/cmd/profile/usage_view_csv_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"

"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -65,13 +66,13 @@ func usageViewCSVCommand() *cli.Command {
}

// save response to a file
var filename string
var filePath string
if !ctx.IsSet(flagUsageViewCSVFile.Name) {
filename = fmt.Sprintf("usage-%s-%s-%s.csv", args.aspect, args.since, args.until)
filePath = fmt.Sprintf("./usage-%s-%s-%s.csv", args.aspect, args.since, args.until)
} else {
filename = ctx.String(flagUsageViewCSVFile.Name)
filePath = filepath.Clean(ctx.String(flagUsageViewCSVFile.Name))
}
fd, err := os.OpenFile("./"+filename, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0644)
fd, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0600)

Check failure

Code scanning / gosec

Potential file inclusion via variable Error

Potential file inclusion via variable
if err != nil {
return fmt.Errorf("failed to open a file descriptor: %w", err)
}
Expand All @@ -82,7 +83,7 @@ func usageViewCSVCommand() *cli.Command {
if err != nil {
return fmt.Errorf("failed to write the response to a file: %w", err)
}
log.Println("Usage data saved to", filename)
log.Println("Usage data saved to", filePath)
return nil
},
}
Expand Down

0 comments on commit b89d328

Please sign in to comment.