Skip to content

Commit 63d99e6

Browse files
fix(asm): fix 403 response being inadequatly replaced by datadog response block response (1.9) (#5328)
Fix 403 response being inadequatly replaced by datadog response block response in 1.9 branch. This bug was automatically fixed in 1.10rc2 by suspicious request blocking PRs. Patch to solve tickets #1131460 and #1132841 ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Author is aware of the performance implications of this PR as reported in the benchmarks PR comment. ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer is aware of, and discussed the performance implications of this PR as reported in the benchmarks PR comment.
1 parent 0318a23 commit 63d99e6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ddtrace/contrib/django/patch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,11 @@ def traced_get_response(django, pin, func, instance, args, kwargs):
384384
)
385385
else:
386386
response = func(*args, **kwargs)
387-
if isinstance(response, HttpResponseForbidden):
387+
if (
388+
config._appsec_enabled
389+
and _context.get_item("http.request.blocked", span=span)
390+
and isinstance(response, HttpResponseForbidden)
391+
):
388392
# Add our custom block template
389393
response.content = appsec_utils._get_blocked_template(request_headers.get("Accept"))
390394
return response
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
ASM: This fix resolves an issue where some 403 body responses in Django where wrongly replaced by datadog 403 block response body.

0 commit comments

Comments
 (0)