mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(eventbridge): enforce \$or negation in event pattern matching (#1068)
\$or was silently ignored — the key was never read from the parsed pattern, so rules using \$or routed every source/detail-type-matched event regardless of the OR conditions. Add \$or handling to both matchesPattern (top-level) and matchesDetailNode (detail-level): - iterate each sub-pattern; return false if none match - skip the \$or key in the regular field-by-field AND loop Top-level \$or sub-patterns are full event patterns, so each is evaluated via recursive matchesPattern call. Detail-level sub-patterns are field-match objects, evaluated via recursive matchesDetailNode on the same actual node.
This commit is contained in:
1 parent
76edd1f78b
commit
34084fef87
2 files changed
+95
No files matched your search
@@ -741,6 +741,19 @@ public class EventBridgeService {
|
||||
}
|
||||
try {
|
||||
JsonNode pattern = objectMapper.readTree(eventPattern);
|
||||
JsonNode orClauses = pattern.get("$or");
|
||||
if (orClauses != null && orClauses.isArray()) {
|
||||
boolean anyMatches = false;
|
||||
for (JsonNode subPattern : orClauses) {
|
||||
if (matchesPattern(event, objectMapper.writeValueAsString(subPattern))) {
|
||||
anyMatches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!anyMatches) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
JsonNode sourceField = pattern.get("source");
|
||||
if (sourceField != null && sourceField.isArray()) {
|
||||
String eventSource = (String) event.get("Source");
|
||||
@@ -806,9 +819,25 @@ public class EventBridgeService {
|
||||
}
|
||||
|
||||
private boolean matchesDetailNode(JsonNode actual, JsonNode pattern) {
|
||||
JsonNode orClauses = pattern.get("$or");
|
||||
if (orClauses != null && orClauses.isArray()) {
|
||||
boolean anyMatches = false;
|
||||
for (JsonNode subPattern : orClauses) {
|
||||
if (matchesDetailNode(actual, subPattern)) {
|
||||
anyMatches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!anyMatches) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var fields = pattern.fields();
|
||||
while (fields.hasNext()) {
|
||||
var field = fields.next();
|
||||
if ("$or".equals(field.getKey())) {
|
||||
continue;
|
||||
}
|
||||
JsonNode expected = field.getValue();
|
||||
JsonNode actualField = actual.get(field.getKey());
|
||||
if (expected.isArray()) {
|
||||
|
||||
Reference in new issue
Block a user