Skip to content

Commit bada84d

Browse files
committed
fix: Golang security checks by gosec #304
1 parent c309f0a commit bada84d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/updater/updater.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ func ScanFiles(rootDir string) ([]string, error) {
7777
if info.IsDir() {
7878
return nil
7979
}
80-
if strings.HasSuffix(path, ".conf") {
80+
81+
file := filepath.Clean(path)
82+
if strings.HasPrefix(file, rootDir) && strings.HasSuffix(file, ".conf") {
8183
_, err := os.ReadFile(path)
8284
if err != nil {
8385
return err
@@ -97,12 +99,18 @@ func UpdateConfInDir(rootDir string, outputDir string, indent int, indentChar st
9799
if err != nil {
98100
return err
99101
}
100-
for _, file := range files {
102+
for _, src := range files {
103+
file := filepath.Clean(src)
104+
if !strings.HasPrefix(file, rootDir) {
105+
continue
106+
}
107+
101108
buf, err := os.ReadFile(file)
102109
if err != nil {
103110
fmt.Printf("Formatter Nginx Conf %s failed, can not open the file\n", err)
104111
return err
105112
}
113+
106114
modifiedData, err := fn(FixVars(FixReturn(EncodeEscapeChars(string(buf)))), indent, indentChar)
107115
if err != nil {
108116
fmt.Printf("Formatter Nginx Conf %s failed, can not format the file\n", err)

0 commit comments

Comments
 (0)