Skip to content

Commit

Permalink
fix(iast): check context is enable in request and builtins patched fu…
Browse files Browse the repository at this point in the history
…ncions [backport 2.17] (#11755)

Backport a4f0e38 from #11752 to 2.17.

This fix resolves an issue where AppSec was using a patched request and
builtins functions, creating telemetry errors.
## 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: Alberto Vara <alberto.vara@datadoghq.com>
  • Loading branch information
github-actions[bot] and avara1986 authored Dec 18, 2024
1 parent 533f225 commit 7a275e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ddtrace/appsec/_common_module_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ def wrapped_read_F3E51D71B4EC16EF(original_read_callable, instance, args, kwargs
"""
wrapper for _io.BytesIO and _io.StringIO read function
"""
from ddtrace.appsec._iast._iast_request_context import is_iast_request_enabled

result = original_read_callable(*args, **kwargs)
if asm_config._iast_enabled:
if asm_config._iast_enabled and is_iast_request_enabled():
from ddtrace.appsec._iast._taint_tracking import OriginType
from ddtrace.appsec._iast._taint_tracking import Source
from ddtrace.appsec._iast._taint_tracking import get_tainted_ranges
Expand All @@ -87,7 +89,9 @@ def wrapped_open_CFDDB7ABBA9081B6(original_open_callable, instance, args, kwargs
"""
wrapper for open file function
"""
if asm_config._iast_enabled:
from ddtrace.appsec._iast._iast_request_context import is_iast_request_enabled

if asm_config._iast_enabled and is_iast_request_enabled():
try:
from ddtrace.appsec._iast.taint_sinks.path_traversal import check_and_report_path_traversal

Expand Down Expand Up @@ -176,7 +180,9 @@ def wrapped_request_D8CB81E472AF98A2(original_request_callable, instance, args,
wrapper for third party requests.request function
https://requests.readthedocs.io
"""
if asm_config._iast_enabled:
from ddtrace.appsec._iast._iast_request_context import is_iast_request_enabled

if asm_config._iast_enabled and is_iast_request_enabled():
from ddtrace.appsec._iast.taint_sinks.ssrf import _iast_report_ssrf

_iast_report_ssrf(original_request_callable, *args, **kwargs)
Expand Down Expand Up @@ -216,7 +222,9 @@ def wrapped_system_5542593D237084A7(original_command_callable, instance, args, k
"""
command = args[0] if args else kwargs.get("command", None)
if command is not None:
if asm_config._iast_enabled:
from ddtrace.appsec._iast._iast_request_context import is_iast_request_enabled

if asm_config._iast_enabled and is_iast_request_enabled():
from ddtrace.appsec._iast.taint_sinks.command_injection import _iast_report_cmdi

_iast_report_cmdi(command)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
ASM: This fix resolves an issue where AppSec was using a patched request and builtins functions,
creating telemetry errors.

0 comments on commit 7a275e6

Please sign in to comment.