diff --git a/manifests/java.yml b/manifests/java.yml index 751f996eda8..ad41ce94106 100644 --- a/manifests/java.yml +++ b/manifests/java.yml @@ -2642,27 +2642,27 @@ manifest: tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_After_Vulnerable_Call: - weblog_declaration: "*": irrelevant (endpoint only implemented in spring-boot weblog) - spring-boot: v1.64.0-SNAPSHOT + spring-boot: v1.69.0-SNAPSHOT spring-boot-3-native: irrelevant (GraalVM. Tracing support only) tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_Registered_At_Load_Time: - weblog_declaration: "*": irrelevant (endpoint only implemented in spring-boot weblog) - spring-boot: v1.64.0-SNAPSHOT + spring-boot: v1.69.0-SNAPSHOT spring-boot-3-native: irrelevant (GraalVM. Tracing support only) tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Deduplication: - weblog_declaration: "*": irrelevant (endpoint only implemented in spring-boot weblog) - spring-boot: v1.64.0-SNAPSHOT + spring-boot: v1.69.0-SNAPSHOT spring-boot-3-native: irrelevant (GraalVM. Tracing support only) tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Dependencies_Have_Metadata: - weblog_declaration: "*": irrelevant (endpoint only implemented in spring-boot weblog) - spring-boot: v1.64.0-SNAPSHOT + spring-boot: v1.69.0-SNAPSHOT spring-boot-3-native: irrelevant (GraalVM. Tracing support only) tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_First_Hit_Wins: - weblog_declaration: "*": irrelevant (endpoint only implemented in spring-boot weblog) - spring-boot: v1.64.0-SNAPSHOT + spring-boot: v1.69.0-SNAPSHOT spring-boot-3-native: irrelevant (GraalVM. Tracing support only) tests/appsec/test_service_activation_metric.py::TestServiceActivationEnvVarConfigurationMetric: missing_feature tests/appsec/test_service_activation_metric.py::TestServiceActivationEnvVarMetric: missing_feature diff --git a/manifests/java_lambda.yml b/manifests/java_lambda.yml index 4779ab062db..89d641cab1e 100644 --- a/manifests/java_lambda.yml +++ b/manifests/java_lambda.yml @@ -158,11 +158,11 @@ manifest: tests/appsec/test_reports.py::Test_TagsFromRule: v1.67.0 tests/appsec/test_reports.py::Test_TagsFromRule::test_category: v1.68.0 tests/appsec/test_reports.py::Test_TagsFromRule::test_type: v1.68.0 - tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_After_Vulnerable_Call: v1.68.0 - tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_Registered_At_Load_Time: v1.68.0 - tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Deduplication: v1.68.0 - tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Dependencies_Have_Metadata: v1.68.0 - tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_First_Hit_Wins: v1.68.0 + tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_After_Vulnerable_Call: v1.69.0-SNAPSHOT + tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_Registered_At_Load_Time: v1.69.0-SNAPSHOT + tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Deduplication: v1.69.0-SNAPSHOT + tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Dependencies_Have_Metadata: v1.69.0-SNAPSHOT + tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_First_Hit_Wins: v1.69.0-SNAPSHOT tests/appsec/test_trace_tagging.py::Test_TraceTaggingRules: v1.67.0 tests/appsec/test_trace_tagging.py::Test_TraceTaggingRules::test_rule_with_attributes_keep_event: v1.68.0 tests/appsec/test_trace_tagging.py::Test_TraceTaggingRules::test_rule_with_attributes_keep_no_event: v1.68.0 diff --git a/manifests/python.yml b/manifests/python.yml index c37ed986967..82763af2e1c 100644 --- a/manifests/python.yml +++ b/manifests/python.yml @@ -1664,26 +1664,27 @@ manifest: tests/appsec/test_sca_reachability.py: - weblog_declaration: aiohttp: missing_feature (new weblog, tests are enabled with easy wins) + # These tests require the SCA catalog override added in dd-trace-py #21534. tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_After_Vulnerable_Call: - weblog_declaration: "*": irrelevant (endpoint only implemented in flask weblog) - *flask : v4.8.0.dev + *flask : v4.18.0-rc1 tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_CVE_Registered_At_Load_Time: - weblog_declaration: "*": irrelevant (endpoint only implemented in flask weblog) - *flask : v4.8.0.dev + *flask : v4.18.0-rc1 tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Deduplication: - weblog_declaration: "*": irrelevant (endpoint only implemented in flask weblog) - *flask : v4.8.0.dev + *flask : v4.18.0-rc1 tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_Dependencies_Have_Metadata: - weblog_declaration: "*": irrelevant (endpoint only implemented in flask weblog) - *flask : v4.8.0.dev + *flask : v4.18.0-rc1 tests/appsec/test_sca_reachability.py::Test_SCA_Reachability_First_Hit_Wins: - weblog_declaration: "*": irrelevant (endpoint only implemented in flask weblog) - *flask : v4.8.0.dev + *flask : v4.18.0-rc1 tests/appsec/test_service_activation_metric.py::TestServiceActivationEnvVarConfigurationMetric: v3.12.0.dev tests/appsec/test_service_activation_metric.py::TestServiceActivationEnvVarMetric: - declaration: irrelevant (drop support in v3.12.0.dev) diff --git a/manifests/python_lambda.yml b/manifests/python_lambda.yml index aa4fed2a8bf..aa1d518c66e 100644 --- a/manifests/python_lambda.yml +++ b/manifests/python_lambda.yml @@ -284,7 +284,7 @@ manifest: tests/appsec/test_reports.py::Test_Info: v7.112.0 tests/appsec/test_reports.py::Test_RequestHeaders: v7.112.0 tests/appsec/test_reports.py::Test_StatusCode: v7.112.0 - tests/appsec/test_sca_reachability.py: incomplete_test_app (Lambda SCA dependency fixtures and vulnerable-call endpoints are not implemented) + tests/appsec/test_sca_reachability.py: missing_feature (requires _DD_APPSEC_SCA_CVE_FILE and Lambda SCA reachability support) tests/appsec/test_trace_tagging.py::Test_TraceTaggingRules: v8.113.0 tests/appsec/test_traces.py::Test_AppSecEventSpanTags: v7.112.0 tests/appsec/test_traces.py::Test_AppSecEventSpanTags::test_header_collection: bug (APPSEC-58202) diff --git a/tests/appsec/test_sca_reachability.py b/tests/appsec/test_sca_reachability.py index aef5a54ef42..a5e5ae1b5da 100644 --- a/tests/appsec/test_sca_reachability.py +++ b/tests/appsec/test_sca_reachability.py @@ -18,23 +18,28 @@ # Only populate entries once the language's tracer supports SCA reachability # and the expected values are confirmed. Missing languages gracefully # degrade: structural assertions still run, but value comparisons are skipped. -# `cve_id` is a list to support retrocompatibility across tracer versions that -# may emit different identifiers (e.g. CVE id vs GHSA id) for the same advisory. +# Regular and Lambda scenarios use the same synthetic advisory for each language. _LANG_CONFIG: dict[str, dict[str, Any]] = { "python": { - "cve_id": ["CVE-2024-35195", "GHSA-652x-xj99-gmcc"], + "cve_id": ["system-tests-sca"], "vulnerable_dep": "requests", "path": "app.py", "symbol": "sca_requests_vulnerable_call", }, "java": { - "cve_id": ["GHSA-hf5p-q87m-crj7"], + "cve_id": ["system-tests-sca"], "vulnerable_dep": "junrar", "path": "com.datadoghq.system_tests.springboot.ScaReachability", "symbol": "junrarHit", }, + "python_lambda": { + "cve_id": ["system-tests-sca"], + "vulnerable_dep": "requests", + "path": "handler.py", + "symbol": "sca_requests_vulnerable_call", + }, "java_lambda": { - "cve_id": ["GHSA-hf5p-q87m-crj7"], + "cve_id": ["system-tests-sca"], "vulnerable_dep": "junrar", "path": "com.datadoghq.lambda.ScaReachability", "symbol": "junrarHit", diff --git a/utils/_context/_scenarios/appsec.py b/utils/_context/_scenarios/appsec.py index 9d59079b435..d3a14f225d3 100644 --- a/utils/_context/_scenarios/appsec.py +++ b/utils/_context/_scenarios/appsec.py @@ -1,3 +1,6 @@ +import json +from pathlib import Path + import pytest from ._core import DdTraceEndToEndScenario, EndToEndScenario, scenario_groups @@ -147,6 +150,38 @@ def __init__(self) -> None: ) +# Inline fixtures so edits select this scenario in CI. +_SCA_ADVISORIES = { + "java": { + "version": 1, + "entries": [ + { + "vuln_id": "system-tests-sca", + "artifact": "com.github.junrar:junrar", + "version_ranges": [">=0"], + "symbols": [{"class": "com/github/junrar/LocalFolderExtractor", "method": "createDirectory"}], + } + ], + }, + "python": { + "targets": [ + { + "id": "system-tests-sca", + "lang": "python", + "dependency_name": "requests", + "package_versions": [">=0"], + "targets": ["requests.sessions:Session.send"], + "vulnerability": { + "id": "system-tests-sca", + "severity": "LOW", + "description": "Synthetic requests target for system-tests SCA reachability coverage.", + }, + } + ] + }, +} + + class RuntimeScaReachability(DdTraceEndToEndScenario): """Scenario to test SCA telemetry events""" @@ -159,6 +194,23 @@ def __init__(self) -> None: scenario_groups=[scenario_groups.appsec], ) + def configure(self, config: pytest.Config) -> None: + super().configure(config) + if self.replay: + return + + container = self.weblog_infra.library_container + advisory = _SCA_ADVISORIES.get(container.image.labels["system-tests-library"]) + if advisory is None: + return + + catalog = Path(container.log_folder_path) / "sca-advisories.json" + catalog.write_text(json.dumps(advisory), encoding="utf-8") + + container_path = "/sca/advisories.json" + container.volumes[str(catalog)] = {"bind": container_path, "mode": "ro"} + container.environment["_DD_APPSEC_SCA_CVE_FILE"] = container_path + class IastDeduplication(DdTraceEndToEndScenario): """Iast scenario with deduplication enabled""" diff --git a/utils/_context/_scenarios/aws_lambda.py b/utils/_context/_scenarios/aws_lambda.py index bf15d58df09..742e51ef5bf 100644 --- a/utils/_context/_scenarios/aws_lambda.py +++ b/utils/_context/_scenarios/aws_lambda.py @@ -1,3 +1,6 @@ +import json +from pathlib import Path + import pytest from utils import interfaces from utils.interfaces._core import ProxyBasedInterfaceValidator @@ -240,6 +243,38 @@ def __init__(self) -> None: ) +# Inline fixtures so edits select this scenario in CI without importing appsec.py. +_SCA_ADVISORIES = { + "java_lambda": { + "version": 1, + "entries": [ + { + "vuln_id": "system-tests-sca", + "artifact": "com.github.junrar:junrar", + "version_ranges": [">=0"], + "symbols": [{"class": "com/github/junrar/LocalFolderExtractor", "method": "createDirectory"}], + } + ], + }, + "python_lambda": { + "targets": [ + { + "id": "system-tests-sca", + "lang": "python", + "dependency_name": "requests", + "package_versions": [">=0"], + "targets": ["requests.sessions:Session.send"], + "vulnerability": { + "id": "system-tests-sca", + "severity": "LOW", + "description": "Synthetic requests target for system-tests SCA reachability coverage.", + }, + } + ] + }, +} + + class AppsecLambdaSca(_LambdaScenario): """SCA dependency metadata and runtime reachability in Lambda with AppSec disabled""" @@ -250,6 +285,26 @@ def __init__(self) -> None: scenario_groups=[scenario_groups.appsec, scenario_groups.appsec_lambda], ) + def configure(self, config: pytest.Config) -> None: + super().configure(config) + if self.replay: + return + + container = self.lambda_weblog + advisory = _SCA_ADVISORIES.get(container.image.labels["system-tests-library"]) + if advisory is None: + return + + catalog = Path(container.log_folder_path) / "sca-advisories.json" + catalog.write_text(json.dumps(advisory), encoding="utf-8") + + container_path = "/sca/advisories.json" + container.volumes[str(catalog)] = {"bind": container_path, "mode": "ro"} + container.environment["_DD_APPSEC_SCA_CVE_FILE"] = container_path + + def get_libraries(self) -> set[str]: + return set(_SCA_ADVISORIES) + class AppsecLambdaRasp(_LambdaScenario): """Enable APPSEC RASP""" diff --git a/utils/build/docker/java/spring-boot/src/main/java/com/datadoghq/system_tests/springboot/ScaReachability.java b/utils/build/docker/java/spring-boot/src/main/java/com/datadoghq/system_tests/springboot/ScaReachability.java index 95c3bdc1f4a..ebbf485dad1 100644 --- a/utils/build/docker/java/spring-boot/src/main/java/com/datadoghq/system_tests/springboot/ScaReachability.java +++ b/utils/build/docker/java/spring-boot/src/main/java/com/datadoghq/system_tests/springboot/ScaReachability.java @@ -15,7 +15,7 @@ public class ScaReachability { @PostConstruct private void preloadVulnerableClass() { // Force LocalFolderExtractor class load during Spring startup so the SCA transformer can - // register GHSA-hf5p-q87m-crj7 with reached=[] before any HTTP request triggers junrarHit(). + // register system-tests-sca with reached=[] before any HTTP request triggers junrarHit(). // Without this, the class loads lazily on the first request, so registerCve() and recordHit() // fire in the same request with no heartbeat window between them. try { diff --git a/utils/build/docker/java_lambda/src/main/java/com/datadoghq/lambda/ScaReachability.java b/utils/build/docker/java_lambda/src/main/java/com/datadoghq/lambda/ScaReachability.java index dbc63c55f6b..6740a6c03f5 100644 --- a/utils/build/docker/java_lambda/src/main/java/com/datadoghq/lambda/ScaReachability.java +++ b/utils/build/docker/java_lambda/src/main/java/com/datadoghq/lambda/ScaReachability.java @@ -9,7 +9,7 @@ public class ScaReachability { public static void preloadVulnerableClass() { // Force LocalFolderExtractor class load during Lambda initialization so the SCA transformer can - // register GHSA-hf5p-q87m-crj7 with reached=[] before any HTTP request triggers junrarHit(). + // register system-tests-sca with reached=[] before any HTTP request triggers junrarHit(). // Without this, the class loads lazily on the first request, so registerCve() and recordHit() // fire in the same request with no heartbeat window between them. try { diff --git a/utils/build/docker/python/flask/app.py b/utils/build/docker/python/flask/app.py index 869250381f4..b0c8d8cf54f 100644 --- a/utils/build/docker/python/flask/app.py +++ b/utils/build/docker/python/flask/app.py @@ -2386,7 +2386,7 @@ async def llm(): @app.route("/sca/vulnerable-call") def sca_requests_vulnerable_call(): - """Trigger a call to requests.sessions.Session.send (CVE-2024-35195 target).""" + """Trigger the synthetic advisory's requests.sessions.Session.send target.""" session = requests.Session() try: session.get("http://localhost:1") @@ -2397,7 +2397,7 @@ def sca_requests_vulnerable_call(): @app.route("/sca/vulnerable-call-alt") def sca_requests_vulnerable_call_alt(): - """Alternate call site for same CVE-2024-35195 target (first-hit-wins test).""" + """Alternate call site for the same synthetic advisory (first-hit-wins test).""" session = requests.Session() try: session.post("http://localhost:1", data="x") diff --git a/utils/build/docker/python/flask/app.sh b/utils/build/docker/python/flask/app.sh index a636fdb0a57..9d23abdb9bc 100755 --- a/utils/build/docker/python/flask/app.sh +++ b/utils/build/docker/python/flask/app.sh @@ -1,10 +1,5 @@ #!/bin/bash -if [[ ${DD_APPSEC_SCA_ENABLED:-} = "1" || ${DD_APPSEC_SCA_ENABLED:-} = "true" ]]; then - # We need a requirement with a CVE to test SCA features - python -m pip install requests==2.31.0 -fi - echo "--- PIP FREEZE ---" python -m pip freeze echo "------------------" diff --git a/utils/build/docker/python/flask/uwsgi_app.sh b/utils/build/docker/python/flask/uwsgi_app.sh index e10e7b505a9..1a148a3794c 100755 --- a/utils/build/docker/python/flask/uwsgi_app.sh +++ b/utils/build/docker/python/flask/uwsgi_app.sh @@ -1,10 +1,5 @@ #!/bin/bash -if [[ ${DD_APPSEC_SCA_ENABLED:-} = "1" || ${DD_APPSEC_SCA_ENABLED:-} = "true" ]]; then - # We need a requirement with a CVE to test SCA features - python -m pip install requests==2.31.0 -fi - echo "--- PIP FREEZE ---" python -m pip freeze echo "------------------" diff --git a/utils/build/docker/python_lambda/function/handler.py b/utils/build/docker/python_lambda/function/handler.py index d507f927a20..875f4be39e4 100644 --- a/utils/build/docker/python_lambda/function/handler.py +++ b/utils/build/docker/python_lambda/function/handler.py @@ -47,6 +47,28 @@ _TRACK_CUSTOM_APPSEC_EVENT_NAME = "system_tests_appsec_event" +@app.get("/sca/vulnerable-call") +def sca_requests_vulnerable_call() -> str: + """Exercise the synthetic advisory's Session.send target.""" + with requests.Session() as session: + try: + session.send(requests.Request("GET", "http://127.0.0.1:1").prepare(), timeout=1) + except requests.exceptions.ConnectionError: + pass + return "OK" + + +@app.get("/sca/vulnerable-call-alt") +def sca_requests_vulnerable_call_alt() -> str: + """Use a distinct caller for the same target to check first-hit deduplication.""" + with requests.Session() as session: + try: + session.send(requests.Request("GET", "http://127.0.0.1:1").prepare(), timeout=1) + except requests.exceptions.ConnectionError: + pass + return "OK" + + def version_info(): return { "status": "ok",