@@ -17,6 +17,7 @@ import com.datadog.appsec.event.data.MapDataBundle
17
17
import com.datadog.appsec.gateway.AppSecRequestContext
18
18
import com.datadog.appsec.gateway.GatewayContext
19
19
import com.datadog.appsec.report.AppSecEvent
20
+ import datadog.trace.api.telemetry.RuleType
20
21
import datadog.trace.util.stacktrace.StackTraceEvent
21
22
import com.datadog.appsec.test.StubAppSecConfigService
22
23
import datadog.communication.monitor.Monitoring
@@ -959,7 +960,7 @@ class PowerWAFModuleSpecification extends DDSpecification {
959
960
assert ! flow. blocking
960
961
}
961
962
962
- void ' timeout is honored' () {
963
+ void 'timeout is honored ( waf ) ' () {
963
964
setup:
964
965
injectSysConfig(' appsec. waf. timeout' , ' 1 ' )
965
966
PowerWAFModule.createLimitsObject()
@@ -981,8 +982,13 @@ class PowerWAFModuleSpecification extends DDSpecification {
981
982
ctx.getOrCreateAdditive(_, true) >> {
982
983
pwafAdditive = it[0].openAdditive() }
983
984
assert !flow.blocking
984
- 1 * ctx. increaseTimeouts()
985
+ 1 * ctx.isAdditiveClosed()
986
+ 1 * ctx.getOrCreateAdditive(_, true, false) >> {
987
+ pwafAdditive = it[0].openAdditive() }
988
+ 1 * ctx.getWafMetrics()
989
+ 1 * ctx.increaseWafTimeouts()
985
990
1 * mockWafMetricCollector.get().wafRequestTimeout()
991
+ 0 * _
986
992
987
993
when:
988
994
pp.processTraceSegment(segment, ctx, [])
@@ -996,6 +1002,53 @@ class PowerWAFModuleSpecification extends DDSpecification {
996
1002
PowerWAFModule.createLimitsObject()
997
1003
}
998
1004
1005
+ void ' timeout is honored (rasp)' () {
1006
+ setup:
1007
+ injectSysConfig(' appsec. waf. timeout' , ' 1 ' )
1008
+ PowerWAFModule.createLimitsObject()
1009
+ setupWithStubConfigService()
1010
+ DataBundle db = MapDataBundle.of(KnownAddresses.HEADERS_NO_COOKIES,
1011
+ new CaseInsensitiveMap<List<String>>([' user- agent' : ' Arachni / v' + (' a' * 4000)]))
1012
+ ChangeableFlow flow = new ChangeableFlow()
1013
+
1014
+ TraceSegment segment = Mock()
1015
+ TraceSegmentPostProcessor pp = service.traceSegmentPostProcessors.last()
1016
+
1017
+ def mockWafMetricCollector = Mock(WafMetricCollector)
1018
+ WafMetricCollector.INSTANCE = mockWafMetricCollector
1019
+
1020
+ gwCtx = new GatewayContext(false, RuleType.SQL_INJECTION)
1021
+
1022
+ when:
1023
+ dataListener.onDataAvailable(flow, ctx, db, gwCtx)
1024
+
1025
+ then:
1026
+ ctx.getOrCreateAdditive(_, true) >> {
1027
+ pwafAdditive = it[0].openAdditive() }
1028
+ assert !flow.blocking
1029
+ 1 * ctx.isAdditiveClosed()
1030
+ 1 * ctx.getOrCreateAdditive(_, true, true) >> {
1031
+ pwafAdditive = it[0].openAdditive() }
1032
+ 1 * ctx.getRaspMetrics()
1033
+ 1 * ctx.getRaspMetricsCounter()
1034
+ 1 * ctx.increaseRaspTimeouts()
1035
+ 1 * mockWafMetricCollector.get().raspTimeout(gwCtx.raspRuleType)
1036
+ 1 * mockWafMetricCollector.raspRuleEval(RuleType.SQL_INJECTION)
1037
+ 0 * _
1038
+
1039
+ when:
1040
+ pp.processTraceSegment(segment, ctx, [])
1041
+
1042
+ then:
1043
+ 1 * segment.setTagTop(' _dd. appsec. rasp. timeout' , 1L)
1044
+ _ * segment.setTagTop(_, _)
1045
+
1046
+ cleanup:
1047
+ injectSysConfig(' appsec. waf. timeout' , ConfigDefaults.DEFAULT_APPSEC_WAF_TIMEOUT as String)
1048
+ PowerWAFModule.createLimitsObject()
1049
+ gwCtx = new GatewayContext(false)
1050
+ }
1051
+
999
1052
void ' configuration can be given later' () {
1000
1053
def cfgService = new StubAppSecConfigService([waf: null])
1001
1054
AppSecModuleConfigurer.Reconfiguration reconf = Mock()
@@ -1112,7 +1165,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1112
1165
1 * ctx.getWafMetrics()
1113
1166
1 * ctx.isAdditiveClosed() >> false
1114
1167
1 * ctx.closeAdditive() >> { pwafAdditive.close() }
1115
- _ * ctx. increaseTimeouts()
1168
+ _ * ctx.increaseWafTimeouts()
1169
+ _ * ctx.increaseRaspTimeouts()
1116
1170
0 * _
1117
1171
1118
1172
when: ' removing data and override config'
@@ -1136,7 +1190,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1136
1190
1 * ctx.isAdditiveClosed() >> false
1137
1191
1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1138
1192
1 * reconf.reloadSubscriptions()
1139
- _ * ctx. increaseTimeouts()
1193
+ _ * ctx.increaseWafTimeouts()
1194
+ _ * ctx.increaseRaspTimeouts()
1140
1195
0 * _
1141
1196
1142
1197
when: ' data is readded'
@@ -1162,7 +1217,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1162
1217
1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1163
1218
1 * flow.isBlocking()
1164
1219
1 * ctx.isThrottled(null)
1165
- _ * ctx. increaseTimeouts()
1220
+ _ * ctx.increaseWafTimeouts()
1221
+ _ * ctx.increaseRaspTimeouts()
1166
1222
0 * _
1167
1223
1168
1224
when: ' toggling the rule off'
@@ -1184,7 +1240,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1184
1240
1 * ctx.getWafMetrics()
1185
1241
1 * ctx.isAdditiveClosed() >> false
1186
1242
1 * ctx.closeAdditive()
1187
- _ * ctx. increaseTimeouts()
1243
+ _ * ctx.increaseWafTimeouts()
1244
+ _ * ctx.increaseRaspTimeouts()
1188
1245
0 * _
1189
1246
}
1190
1247
@@ -1214,7 +1271,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1214
1271
1 * ctx.getWafMetrics()
1215
1272
1 * ctx.isAdditiveClosed() >> false
1216
1273
1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1217
- _ * ctx. increaseTimeouts()
1274
+ _ * ctx.increaseWafTimeouts()
1275
+ _ * ctx.increaseRaspTimeouts()
1218
1276
0 * _
1219
1277
1220
1278
when: ' rule enabled in config a has no effect'
@@ -1238,7 +1296,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1238
1296
1 * ctx.getWafMetrics()
1239
1297
1 * ctx.isAdditiveClosed() >> false
1240
1298
1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1241
- _ * ctx. increaseTimeouts()
1299
+ _ * ctx.increaseWafTimeouts()
1300
+ _ * ctx.increaseRaspTimeouts()
1242
1301
0 * _
1243
1302
1244
1303
when: ' rule enabled in config c overrides b'
@@ -1266,7 +1325,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1266
1325
1 * ctx.reportEvents(_ as Collection<AppSecEvent>)
1267
1326
1 * ctx.isAdditiveClosed() >> false
1268
1327
1 * ctx.closeAdditive() >> {pwafAdditive.close()}
1269
- _ * ctx. increaseTimeouts()
1328
+ _ * ctx.increaseWafTimeouts()
1329
+ _ * ctx.increaseRaspTimeouts()
1270
1330
1 * ctx.isThrottled(null)
1271
1331
0 * _
1272
1332
@@ -1289,7 +1349,8 @@ class PowerWAFModuleSpecification extends DDSpecification {
1289
1349
1 * ctx.getWafMetrics()
1290
1350
1 * ctx.isAdditiveClosed() >> false
1291
1351
1 * ctx.closeAdditive()
1292
- _ * ctx. increaseTimeouts()
1352
+ _ * ctx.increaseWafTimeouts()
1353
+ _ * ctx.increaseRaspTimeouts()
1293
1354
0 * _
1294
1355
}
1295
1356
0 commit comments