Skip to content

Commit

Permalink
requires: add requires keyword
Browse files Browse the repository at this point in the history
Add a new rule keyword "requires" that allows a rule to require specific
Suricata versions and/or Suricata features to be enabled.

Example:

  requires: feature geoip, version >= 7.0.0, version < 8;
  requires: version >= 7.0.3 < 8
  requires: version >= 7.0.3 < 8 | >= 8.0.3

Feature: OISF#5972

Co-authored-by: Philippe Antoine <[email protected]>
  • Loading branch information
2 people authored and victorjulien committed Dec 19, 2023
1 parent 15ed51f commit 5d5b050
Show file tree
Hide file tree
Showing 13 changed files with 997 additions and 19 deletions.
47 changes: 47 additions & 0 deletions doc/userguide/rules/meta.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,50 @@ The format is::
If the value is src_ip then the source IP in the generated event (src_ip
field in JSON) is the target of the attack. If target is set to dest_ip
then the target is the destination IP in the generated event.

requires
--------

The ``requires`` keyword allows a rule to require specific Suricata
features to be enabled, or the Suricata version to match an
expression. Rules that do not meet the requirements will by ignored,
and Suricata will not treat them as errors.

When parsing rules, the parser attempts to process the ``requires``
keywords before others. This allows it to occur after keywords that
may only be present in specific versions of Suricata, as specified by
the ``requires`` statement. However, the keywords preceding it must
still adhere to the basic known formats of Suricata rules.

The format is::

requires: feature geoip, version >= 7.0.0

To require multiple features, the feature sub-keyword must be
specified multiple times::

requires: feature geoip, feature lua

Alternatively, *and* expressions may be expressed like::

requires: version >= 7.0.4 < 8

and *or* expressions may expressed with ``|`` like::

requires: version >= 7.0.4 < 8 | >= 8.0.3

to express that a rules requires version 7.0.4 or greater, but less
than 8, **OR** greater than or equal to 8.0.3. Which could be useful
if a keyword wasn't added until 7.0.4 and the 8.0.3 patch releases, as
it would not exist in 8.0.1.

This can be extended to multiple release branches::

requires: version >= 7.0.10 < 8 | >= 8.0.5 < 9 | >= 9.0.3

If no *minor* or *patch* version component is provided, it will
default to 0.

The ``version`` may only be specified once, if specified more than
once the rule will log an error and not be loaded.

1 change: 1 addition & 0 deletions rust/src/detect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ pub mod parser;
pub mod stream_size;
pub mod uint;
pub mod uri;
pub mod requires;
Loading

0 comments on commit 5d5b050

Please sign in to comment.