Skip to content

Commit 792d493

Browse files
fix(AAP): reverting usage of json helper function from libddwaf [backport 3.16] (#14886)
Backport 8235d03 from #14876 to 3.16. ## Description Reverting usage of json helper function from libddwaf due to some possibly related memory corruption errors. This is a (only partial) revert of #14215 Also: - improve a test file to ensure the waf is creating a proper handle from this file. Co-authored-by: Christophe Papazian <[email protected]>
1 parent 5aa488a commit 792d493

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

ddtrace/appsec/_ddwaf/waf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ def __init__(
5959
key_regex=obfuscation_parameter_key_regexp, value_regex=obfuscation_parameter_value_regexp
6060
)
6161
diagnostics = ddwaf_object()
62-
ruleset_map_object = ddwaf_object.from_json_bytes(ruleset_json_str)
63-
if not ruleset_map_object:
64-
raise ValueError("Invalid ruleset provided to DDWaf constructor")
62+
ruleset_map_object = None
63+
try:
64+
dct = json.loads(ruleset_json_str)
65+
except Exception:
66+
dct = {}
67+
ruleset_map_object = ddwaf_object.create_without_limits(dct)
6568
self._builder = py_ddwaf_builder_init(config)
6669
py_add_or_update_config(self._builder, ASM_DD_DEFAULT, ruleset_map_object, diagnostics)
6770
self._handle = py_ddwaf_builder_build_instance(self._builder)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
AAP: This PR is a tentative fix for rare memory problems with libddwaf that we were unable to reproduce for now.

tests/appsec/appsec/rules-rasp-disabled.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,45 @@
250250
"on_match": [
251251
"stack_trace"
252252
]
253+
},
254+
{
255+
"id": "ua0-600-56x",
256+
"name": "Datadog test scanner - blocking version: user-agent",
257+
"tags": {
258+
"type": "attack_tool",
259+
"category": "attack_attempt",
260+
"cwe": "200",
261+
"capec": "1000/118/169",
262+
"tool_name": "Datadog Canary Test",
263+
"confidence": "1",
264+
"module": "waf"
265+
},
266+
"conditions": [
267+
{
268+
"parameters": {
269+
"inputs": [
270+
{
271+
"address": "server.request.headers.no_cookies",
272+
"key_path": [
273+
"user-agent"
274+
]
275+
},
276+
{
277+
"address": "grpc.server.request.metadata",
278+
"key_path": [
279+
"dd-canary"
280+
]
281+
}
282+
],
283+
"regex": "^dd-test-scanner-log-block(?:$|/|\\s)"
284+
},
285+
"operator": "match_regex"
286+
}
287+
],
288+
"transformers": [],
289+
"on_match": [
290+
"block"
291+
]
253292
}
254293
]
255294
}

0 commit comments

Comments
 (0)