Skip to content

Commit 647e5e8

Browse files
fix(aap): path fix for django view arguments [backport 3.11] (#14272)
Backport 280d881 from #14268 to 3.11. fixing issue #14258 Also little change to the django app for threats tests to have a regression test. APPSEC-58632 ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Christophe Papazian <[email protected]> Co-authored-by: Christophe Papazian <[email protected]>
1 parent d35e0bb commit 647e5e8

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

ddtrace/contrib/internal/django/patch.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -684,17 +684,17 @@ def _instrument_view(django, view, path=None):
684684
def traced_urls_path(django, pin, wrapped, instance, args, kwargs):
685685
"""Wrapper for url path helpers to ensure all views registered as urls are traced."""
686686
try:
687-
from_args = False
688-
view = kwargs.pop("view", None)
689-
path = kwargs.pop("path", None)
690-
if view is None:
687+
view_from_args = False
688+
view = kwargs.get("view", None)
689+
path = kwargs.get("route", None)
690+
if view is None and len(args) > 1:
691691
view = args[1]
692-
from_args = True
693-
if path is None:
692+
view_from_args = True
693+
if path is None and args:
694694
path = args[0]
695695

696696
core.dispatch("service_entrypoint.patch", (unwrap(view),))
697-
if from_args:
697+
if view_from_args:
698698
args = list(args)
699699
args[1] = instrument_view(django, view, path=path)
700700
args = tuple(args)
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 fix resolves an issue where the ``route`` parameter was not being correctly handled in the Django path function.

tests/appsec/contrib_appsec/django_app/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def shutdown(request):
286286
path("new_service/<str:service_name>", new_service, name="new_service"),
287287
path("rasp/<str:endpoint>/", rasp, name="rasp"),
288288
path("rasp/<str:endpoint>", rasp, name="rasp"),
289-
path("login/", login_user, name="login"),
289+
path(route="login/", view=login_user, name="login"),
290290
path("login", login_user, name="login"),
291291
path("login_sdk/", login_user_sdk, name="login_sdk"),
292292
path("login_sdk", login_user_sdk, name="login_sdk"),

0 commit comments

Comments
 (0)