Skip to content

Commit adc0d6f

Browse files
authored
feat(appsec): enable urllib3 patches by default (#15101)
## Description Apply AppSec patches for urllib3 when AppSec is enabled regardless of wether urllib3 is patched or not. ## Testing - removed explicit urllib3 patching from riotfiles ## Risks None ## Additional Notes <!-- Any other information that would be helpful for reviewers -->
1 parent f54cb51 commit adc0d6f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

ddtrace/appsec/_common_module_patches.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def _(module):
4949
if _is_patched:
5050
return
5151

52+
try_wrap_function_wrapper(
53+
"urllib3.connectionpool", "HTTPConnectionPool._make_request", wrapped_urllib3_make_request
54+
)
55+
try_wrap_function_wrapper("urllib3._request_methods", "RequestMethods.request", wrapped_request_D8CB81E472AF98A2)
56+
try_wrap_function_wrapper("urllib3.request", "RequestMethods.request", wrapped_request_D8CB81E472AF98A2)
5257
try_wrap_function_wrapper("builtins", "open", wrapped_open_CFDDB7ABBA9081B6)
5358
try_wrap_function_wrapper("urllib.request", "OpenerDirector.open", wrapped_open_ED4CF71136E15EBF)
5459
try_wrap_function_wrapper("http.client", "HTTPConnection.request", wrapped_request)
@@ -62,6 +67,9 @@ def unpatch_common_modules():
6267
if not _is_patched:
6368
return
6469

70+
try_unwrap("urllib3.connectionpool", "HTTPConnectionPool._make_request")
71+
try_unwrap("urllib3._request_methods", "RequestMethods.request")
72+
try_unwrap("urllib3.request", "RequestMethods.request")
6573
try_unwrap("builtins", "open")
6674
try_unwrap("urllib.request", "OpenerDirector.open")
6775
try_unwrap("_io", "BytesIO.read")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
AAP: AppSec instrumentation for downstream request is now enabled by default for `urllib3` and `requests`. It does not require enabling APM instrumentation for `urllib3` anymore.

riotfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,7 +3694,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
36943694
"AGENT_VERSION": "testagent",
36953695
"DD_REMOTE_CONFIGURATION_ENABLED": "true",
36963696
"DD_API_SECURITY_SAMPLE_DELAY": "0",
3697-
"DD_PATCH_MODULES": "unittest:false,urllib3:true",
3697+
"DD_PATCH_MODULES": "unittest:false",
36983698
},
36993699
venvs=[
37003700
Venv(
@@ -3748,7 +3748,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
37483748
"AGENT_VERSION": "testagent",
37493749
"DD_REMOTE_CONFIGURATION_ENABLED": "true",
37503750
"DD_API_SECURITY_SAMPLE_DELAY": "0",
3751-
"DD_PATCH_MODULES": "unittest:false,urllib3:true",
3751+
"DD_PATCH_MODULES": "unittest:false",
37523752
},
37533753
venvs=[
37543754
Venv(
@@ -3799,7 +3799,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
37993799
"DD_REMOTE_CONFIGURATION_ENABLED": "true",
38003800
"DD_IAST_DEDUPLICATION_ENABLED": "false",
38013801
"DD_API_SECURITY_SAMPLE_DELAY": "0",
3802-
"DD_PATCH_MODULES": "unittest:false,urllib3:true",
3802+
"DD_PATCH_MODULES": "unittest:false",
38033803
},
38043804
venvs=[
38053805
Venv(

0 commit comments

Comments
 (0)