Drop the array marker and use json_meta_contains on sid 5004770 - #729
Conversation
The rule reads
json_meta_content:!".properties.riskEventTypes[]",unfamiliarFeatures; json_contains;
and neither of those two spellings does what it looks like.
src/parsers/json.c builds each stored key with snprintf("%s.%s") and
compares it with strcmp, so [] is two characters of the key name and
not a marker. The rule names a key no Entra document carries. Its
condition is negated, and the engine needs the key to be present to
satisfy a negation, so the rule cannot alert at all.
json_contains sets the substring flag for json_content. The
json_meta_content branch reads json_meta_contains, so the modifier on
this line qualifies nothing and the value stored for the key, which is
the serialised array, is compared whole.
Both have to change. Dropping [] alone turns a dead rule into one that
alerts on the very risk type it excludes, because the stored value
["unfamiliarFeatures"] is not equal to unfamiliarFeatures.
Measured against Sagan built from 3b9b0fa, one document per row, every
other condition of the rule satisfied:
properties.riskEventTypes ships [] only patched
["unfamiliarFeatures"] silent alert silent
["unfamiliarFeatures","anonymized..."] silent alert silent
["anonymizedIPAddress"] silent alert alert
absent silent silent silent
a key spelled riskEventTypes[] alert - silent
The last row is the only thing the rule matches today: a document whose
key name ends in two brackets.
rev incremented.
|
One sentence in the commit message is wrong, and it is the sentence describing the mechanism rather than the fix. Posting the correction here rather than force-pushing, so the review history stays readable. Correction to my own commit message, before anyone spends time on it. I wrote that the if ( !strcmp(rulesplit, "json_contains") )
{
...
rulestruct[counters->rulecount].json_content_strstr[json_content_count-1] = 1;
}It sets the substring flag on the last Measured on a reduced rule, one document per row:
So in sid 5004770 that modifier is not idle: it makes What this changes about the patch, and what it does not:
Everything else in the description is unaffected: the |
The rule reads
json_meta_content:!".properties.riskEventTypes[]",unfamiliarFeatures; json_contains;
and neither of those two spellings does what it looks like.
src/parsers/json.c builds each stored key with snprintf("%s.%s") and compares it with strcmp, so [] is two characters of the key name and not a marker. The rule names a key no Entra document carries. Its condition is negated, and the engine needs the key to be present to satisfy a negation, so the rule cannot alert at all.
json_contains sets the substring flag for json_content. The json_meta_content branch reads json_meta_contains, so the modifier on this line qualifies nothing and the value stored for the key, which is the serialised array, is compared whole.
Both have to change. Dropping [] alone turns a dead rule into one that alerts on the very risk type it excludes, because the stored value ["unfamiliarFeatures"] is not equal to unfamiliarFeatures.
Measured against Sagan built from 3b9b0fa, one document per row, every other condition of the rule satisfied:
properties.riskEventTypes ships [] only patched
["unfamiliarFeatures"] silent alert silent
["unfamiliarFeatures","anonymized..."] silent alert silent
["anonymizedIPAddress"] silent alert alert
absent silent silent silent
a key spelled riskEventTypes[] alert - silent
The last row is the only thing the rule matches today: a document whose key name ends in two brackets.
rev incremented.