Skip to content

Commit 52037dc

Browse files
authored
chore(iast): fix api version to send metastruct data if appsec is disabled (#13465)
### Description This PR addresses an issue in the Interactive Application Security Testing (IAST) module where metastruct data was not being sent if Application Security (AppSec) was disabled. **Key Changes:** * Updated the API version handling to ensure metastruct data is transmitted regardless of the AppSec enablement status. * Refactored the metastruct data sending logic to decouple it from AppSec's state. * Added tests to validate the correct behavior when AppSec is disabled. These changes ensure that IAST continues to function correctly and send necessary data even when AppSec is turned off. ## 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)
1 parent 88cbdc8 commit 52037dc

File tree

7 files changed

+176
-96
lines changed

7 files changed

+176
-96
lines changed

ddtrace/appsec/_iast/taint_sinks/code_injection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def unpatch():
4949

5050

5151
def _iast_coi(wrapped, instance, args, kwargs):
52-
if len(args) >= 1 and asm_config.is_iast_request_enabled:
52+
if len(args) >= 1:
5353
_iast_report_code_injection(args[0])
5454

5555
caller_frame = None

ddtrace/internal/writer/writer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,13 @@ def __init__(
479479
is_windows = sys.platform.startswith("win") or sys.platform.startswith("cygwin")
480480

481481
default_api_version = "v0.5"
482-
if is_windows or in_gcp_function() or in_azure_function() or asm_config._asm_enabled:
482+
if (
483+
is_windows
484+
or in_gcp_function()
485+
or in_azure_function()
486+
or asm_config._asm_enabled
487+
or asm_config._iast_enabled
488+
):
483489
default_api_version = "v0.4"
484490

485491
self._api_version = api_version or config._trace_api or default_api_version

tests/appsec/app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ def iast_header_injection_vulnerability():
217217
return resp
218218

219219

220+
@app.route("/iast-code-injection", methods=["GET"])
221+
def iast_code_injection_vulnerability():
222+
filename = request.args.get("filename")
223+
a = "" # noqa: F841
224+
c = eval("a + '" + filename + "'")
225+
resp = Response(f"OK:{tracer._span_aggregator.writer._api_version}:{c}")
226+
return resp
227+
228+
220229
@app.route("/shutdown", methods=["GET"])
221230
def shutdown_view():
222231
tracer._span_aggregator.writer.flush_queue()

tests/appsec/appsec_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def gunicorn_server(
4444
@contextmanager
4545
def flask_server(
4646
python_cmd="python",
47-
appsec_enabled="true",
47+
appsec_enabled="false",
4848
remote_configuration_enabled="true",
4949
iast_enabled="false",
5050
tracer_enabled="true",

tests/appsec/integrations/django_tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,17 @@ def tracer():
6767

6868
@pytest.fixture
6969
def test_spans(tracer):
70+
container = TracerSpanContainer(tracer)
71+
yield container
72+
container.reset()
73+
74+
75+
@pytest.fixture
76+
def iast_span(tracer):
7077
with override_global_config(
7178
dict(
7279
_iast_enabled=True,
80+
_appsec_enabled=False,
7381
_iast_deduplication_enabled=False,
7482
_iast_request_sampling=100.0,
7583
)

0 commit comments

Comments
 (0)