Skip to content

Support fieldref combined with contains, startswith, and endswith - #506

Merged
mostafa merged 12 commits into
mainfrom
fix/fieldref-string-modifiers
Sep 25, 2026
Merged

mostafa merged 12 commits into
mainfrom
fix/fieldref-string-modifiers

Conversation

@mostafa

@mostafa mostafa commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #505.

  • fieldref may be followed by one of contains, startswith, or endswith. The comparison is case-insensitive unless |cased is set. A wildcard in the referenced name is rejected, and a string modifier before fieldref is rejected. Thanks to @Karib0u for reporting these three combinations.
  • PostgreSQL renders the substring forms with strpos and right, so % and _ stay literal, and fieldref equality compares lower() of both sides unless |cased is set. Fibratus renders equality with ~= and the substring forms with icontains, istartswith, and iendswith.
  • |neq negates the whole detection item, as pySigma does. Field|neq: [a, b] matches when the field is neither a nor b; before, it matched when the field differed from either value. re|neq, cidr|neq, fieldref|neq, and neq with a timestamp part also compiled without the negation before.
  • |neq converts. A missing referenced field counts as not equal when the left field is present; PostgreSQL expresses that as (comparison) IS NOT TRUE AND "field" IS NOT NULL. LynxDB negates its deferred where clauses (!~, NOT cidrmatch).
  • incompatible_modifiers accepts the new combinations and warns on the ones that still conflict. neq combines with string comparisons as well as with numbers.
  • FieldRef carries the string operator. The HIR cache schema is 2, so a cache written by an older build is rejected and recompiled.

Test plan

  • cargo test --workspace --exclude rstix --no-fail-fast --lib --tests
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • npm run docs:build and npm run docs:validate from docs/
  • CI

Rules such as fieldref|contains failed to compile because fieldref was equality only. Follow pySigma: the string modifier must follow fieldref, and the referenced name cannot contain wildcards.
The lint ignored fieldref, so combinations the compiler rejects stayed quiet, and it treated neq as a numeric comparison even though neq negates any value.
Postgres compares the referenced text with strpos and right so percent
and underscore stay literal. Fibratus equality is case-insensitive, and
substring comparisons use the matching icontains, istartswith, and
iendswith operators.
Field references render with ~=, so a cross-process guard such as
evt.pid != thread.pid arrives as not (evt.pid ~= thread.pid). The macro
recognizer now accepts that form and still folds create_remote_thread.
A missing referenced field counts as not equal when the left field is
present. PostgreSQL uses IS NOT TRUE together with an IS NOT NULL check
on the left field so a NULL comparison still matches. Other backends
negate the comparison directly.
Document the contains, startswith, and endswith combinations, the
PostgreSQL and Fibratus renderings, and the lint rule that accepts them.
The neq wrap ran after the regex, cidr, numeric, and timestamp branches
returned, so those combinations compiled without the negation. Negate
first, then compile the remaining modifiers.
LynxDB renders regex and cidr as deferred where clauses. Negating only
the inline part dropped the negation, so neq now negates the deferred
parts it produced.
Field|neq: [a, b] matched when the field differed from either value,
which is almost always. pySigma negates the whole item, so the list now
matches only when the field is none of the values. Backends render the
negated list as one grouped NOT, and Fibratus negates its collapsed
list clause.
Sigma string comparison is case-insensitive, and the evaluator and the
substring forms already fold case. Equality now compares lower() of both
sides unless |cased is set.
@mostafa
mostafa merged commit 7af9f9a into main Sep 25, 2026
22 checks passed
@mostafa
mostafa deleted the fix/fieldref-string-modifiers branch September 25, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support fieldref combined with contains, startswith, and endswith

1 participant