Skip to content

Commit

Permalink
Fix gosec assertion G304 (CWE-22): sanitize filename
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Oct 18, 2021
1 parent dd8b6c3 commit 88e60be
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions examples/falcon_intel_rules_download/main.go
Expand Up @@ -5,6 +5,8 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/crowdstrike/gofalcon/falcon"
"github.com/crowdstrike/gofalcon/falcon/client"
Expand Down Expand Up @@ -55,8 +57,13 @@ Falcon Client Secret`)
}
}

func DownloadLatestRuleFile(client *client.CrowdStrikeAPISpecification, filepath, intelType string) error {
file, err := os.OpenFile(filepath, os.O_CREATE|os.O_WRONLY, 0600)
func DownloadLatestRuleFile(client *client.CrowdStrikeAPISpecification, filename, intelType string) error {
safeLocation := filepath.Clean(filename)
if strings.Contains(safeLocation, "/") || strings.Contains(safeLocation, "\\") || strings.Contains(safeLocation, "..") {
panic("Suspicious file location: " + safeLocation)
}

file, err := os.OpenFile(safeLocation, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return err
}
Expand Down

0 comments on commit 88e60be

Please sign in to comment.