fix(waf): handle empty rule bindings

Encode empty site bindings as arrays and normalize legacy JSON null values in the OpenResty runtime to prevent request-time Lua failures.
This commit is contained in:
ryan
2026-07-13 16:43:02 +08:00
parent 0c2961ae6d
commit 46941f65d5
9 changed files with 62 additions and 12 deletions
@@ -370,7 +370,7 @@ func buildSnapshotWAFDocument(ctx context.Context, routes []*model.ProxyRoute) (
bindings = append(bindings, snapshotWAFBinding{
RouteID: routeID,
SiteName: siteName,
RuleGroupIDs: groupIDsByRoute[routeID],
RuleGroupIDs: nonNilUintSlice(groupIDsByRoute[routeID]),
})
}
sort.Slice(bindings, func(i, j int) bool {
@@ -382,6 +382,13 @@ func buildSnapshotWAFDocument(ctx context.Context, routes []*model.ProxyRoute) (
return snapshotWAFDocument{RuleGroups: ruleGroups, IPGroups: ipGroups, Bindings: bindings}, nil
}
func nonNilUintSlice(values []uint) []uint {
if values == nil {
return make([]uint, 0)
}
return values
}
func validateSnapshotWAFIPGroupSize(groups []snapshotWAFIPGroup) error {
runtimeGroups := make(map[string]protocol.WAFIPGroup, len(groups))
for _, group := range groups {