Skip to content

Commit e290457

Browse files
authored
waf: allow glob when including seclang files (#3948)
1 parent c2ce760 commit e290457

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

pkg/appsec/appsec_rules_collection.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,38 @@ func LoadCollection(pattern string, logger *log.Entry) ([]AppsecCollection, erro
7777
if appsecRule.SecLangFilesRules != nil {
7878
for _, rulesFile := range appsecRule.SecLangFilesRules {
7979
logger.Debugf("Adding rules from %s", rulesFile)
80-
fullPath := filepath.Join(hub.GetDataDir(), rulesFile)
80+
globPattern := filepath.Join(hub.GetDataDir(), rulesFile)
81+
82+
matches, err := filepath.Glob(globPattern)
8183

82-
c, err := os.ReadFile(fullPath)
8384
if err != nil {
84-
logger.Errorf("unable to read file %s : %s", rulesFile, err)
85+
logger.Errorf("unable to glob %s : %s", rulesFile, err)
8586
continue
8687
}
8788

88-
for line := range strings.SplitSeq(string(c), "\n") {
89-
if strings.HasPrefix(line, "#") {
90-
continue
91-
}
89+
if len(matches) == 0 {
90+
logger.Warnf("no file matched pattern %s", globPattern)
91+
continue
92+
}
9293

93-
if strings.TrimSpace(line) == "" {
94+
for _, fullPath := range matches {
95+
c, err := os.ReadFile(fullPath)
96+
if err != nil {
97+
logger.Errorf("unable to read file %s : %s", rulesFile, err)
9498
continue
9599
}
96100

97-
appsecCol.NativeRules = append(appsecCol.NativeRules, line)
101+
for line := range strings.SplitSeq(string(c), "\n") {
102+
if strings.HasPrefix(line, "#") {
103+
continue
104+
}
105+
106+
if strings.TrimSpace(line) == "" {
107+
continue
108+
}
109+
110+
appsecCol.NativeRules = append(appsecCol.NativeRules, line)
111+
}
98112
}
99113
}
100114
}

pkg/hubops/download.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func downloadDataSet(ctx context.Context, dataFolder string, force bool, reader
135135
d := downloader.
136136
New().
137137
WithHTTPClient(cwhub.HubClient).
138+
WithMakeDirs(true).
138139
ToFile(destPath).
139140
CompareContent().
140141
BeforeRequest(func(req *http.Request) {

0 commit comments

Comments
 (0)