@@ -640,6 +640,50 @@ class RulesCompatTest implements WafTrait {
640640 assert result. attributes[' _dd.appsec.trace.agent' ] == ' TraceTagging/v1'
641641 }
642642
643+ @Test
644+ void ' test trace tagging rule with attributes, no keep and event' () {
645+ def rulesetWithTraceTaggingEvent = TRACE_TAGGING_EVENT_RULESET
646+
647+ wafDiagnostics = builder. addOrUpdateConfig(' test' , rulesetWithTraceTaggingEvent)
648+
649+ // Check if configuration was accepted
650+ assert wafDiagnostics. numConfigOK == 1 , " WAF configuration was not accepted. numConfigOK = ${ wafDiagnostics?.numConfigOK} "
651+
652+ handle = builder. buildWafHandleInstance()
653+ context = new WafContext (handle)
654+
655+ // Test with input that should match the rule
656+ def params = [
657+ ' server.request.headers.no_cookies' : [
658+ ' user-agent' : ' TraceTagging/v4'
659+ ]
660+ ]
661+
662+ def result = context. run(params, limits, metrics)
663+ assert result. result == Waf.Result . MATCH
664+
665+ // Since the rule has event: true, result.data should contain event information
666+ assert result. data != null
667+
668+ // Parse the event data
669+ def jsonResult = new JsonSlurper (). parseText(result. data)
670+ assert jsonResult. any { it. rule?. id == ' ttr-000-004' }
671+
672+ // Assert that both attributes are present
673+ assert result. attributes. containsKey(' _dd.appsec.trace.integer' ), ' Missing _dd.appsec.trace.integer attribute'
674+ assert result. attributes. containsKey(' _dd.appsec.trace.agent' ), ' Missing _dd.appsec.trace.agent attribute'
675+
676+ // Assert the values
677+ assert result. attributes[' _dd.appsec.trace.integer' ] == 1729L
678+ assert result. attributes[' _dd.appsec.trace.agent' ] == ' TraceTagging/v4'
679+
680+ // Assert that keep is false (should not have USER_KEEP sampling priority)
681+ assert ! result. keep
682+
683+ // Assert that events flag is true
684+ assert result. events
685+ }
686+
643687 @Test
644688 void ' test waf should block but returns ok instead of match' () {
645689 def rulesetWithBlockingRule = [
@@ -1218,4 +1262,74 @@ class RulesCompatTest implements WafTrait {
12181262 ]
12191263 ]
12201264 ]
1265+
1266+ private static final Map TRACE_TAGGING_EVENT_RULESET = [
1267+ version : ' 2.1' ,
1268+ metadata : [
1269+ rules_version : ' 1.2.7'
1270+ ],
1271+ rules : [
1272+ [
1273+ id : ' arachni_rule' ,
1274+ name : ' Arachni' ,
1275+ tags : [
1276+ type : ' security_scanner' ,
1277+ category : ' attack_attempt'
1278+ ],
1279+ conditions : [
1280+ [
1281+ parameters : [
1282+ inputs : [
1283+ [
1284+ address : ' server.request.headers.no_cookies' ,
1285+ key_path : [' user-agent' ]
1286+ ]
1287+ ],
1288+ regex : ' ^Arachni\\ /v'
1289+ ],
1290+ operator : ' match_regex'
1291+ ]
1292+ ],
1293+ transformers : [],
1294+ on_match : [' block' ]
1295+ ]
1296+ ],
1297+ rules_compat : [
1298+ [
1299+ id : ' ttr-000-004' ,
1300+ name : ' Trace Tagging Rule: Attributes, No Keep, Event' ,
1301+ tags : [
1302+ type : ' security_scanner' ,
1303+ category : ' attack_attempt'
1304+ ],
1305+ conditions : [
1306+ [
1307+ parameters : [
1308+ inputs : [
1309+ [
1310+ address : ' server.request.headers.no_cookies' ,
1311+ key_path : [' user-agent' ]
1312+ ]
1313+ ],
1314+ regex : ' ^TraceTagging\\ /v4'
1315+ ],
1316+ operator : ' match_regex'
1317+ ]
1318+ ],
1319+ output : [
1320+ event : true ,
1321+ keep : false ,
1322+ attributes : [
1323+ ' _dd.appsec.trace.integer' : [
1324+ value : 1729
1325+ ],
1326+ ' _dd.appsec.trace.agent' : [
1327+ value : ' TraceTagging/v4'
1328+ ]
1329+ ]
1330+ ],
1331+ on_match : []
1332+ ]
1333+ ]
1334+ ]
12211335}
0 commit comments