diff --git a/docs/understand/weblogs/end-to-end_weblog.md b/docs/understand/weblogs/end-to-end_weblog.md index bf72194e014..261c3b6d39c 100644 --- a/docs/understand/weblogs/end-to-end_weblog.md +++ b/docs/understand/weblogs/end-to-end_weblog.md @@ -546,6 +546,10 @@ This endpoint should set a cookie with empty cookie value without SameSite=Stric This endpoint should set a cookie with the name and value coming from the request body (using the cookieName and cookieValue properties), with all security flags except SameSite=Strict, to detect only the NO_SAMESITE_COOKIE vulnerability. +### POST /iast/path_traversal/test_insecure + +The IAST smoke test sends the weblog’s existing `/var/log/system-tests` directory in the `path` form field. Each request should exercise the filesystem operation and return HTTP 200, including repeated requests for that directory. + ### GET /iast/header_injection/reflected/exclusion This endpoint should set the header whose name comes in the `reflected` field of the query string, with the reflected value of another header whose name comes in the `origin` field of the query string. diff --git a/manifests/cpp_nginx.yml b/manifests/cpp_nginx.yml index dd3fa63dd57..2cbfd4dfe93 100644 --- a/manifests/cpp_nginx.yml +++ b/manifests/cpp_nginx.yml @@ -101,7 +101,9 @@ manifest: tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_Threats: '>=1.19.1' # TODO: a lower version might be supported tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_Threats::test_waf_monitoring_smoke: missing_feature (WAF monitoring tags not implemented) tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_UserEvents: missing_feature + tests/appsec/smoke_tests/test_apm_standalone.py::Test_Standalone_Iast: irrelevant (The nginx module does not implement IAST) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_ApiSecurity: '>=1.19.1' + tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Iast: irrelevant (The nginx module does not implement IAST) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp: missing_feature tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_RemoteConfig: '>=1.19.1' tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_RemoteConfig::test_rasp_blocking_smoke: missing_feature diff --git a/manifests/golang.yml b/manifests/golang.yml index 97d0185a51c..f3f86e1a73d 100644 --- a/manifests/golang.yml +++ b/manifests/golang.yml @@ -736,10 +736,12 @@ manifest: - declaration: missing_feature (Fiber v2 has no HTTP AppSec integration) weblog: fiber-v2-orchestrion tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_UserEvents: missing_feature + tests/appsec/smoke_tests/test_apm_standalone.py::Test_Standalone_Iast: missing_feature (IAST path reports and vulnerability stacks are not supported) tests/appsec/smoke_tests/test_security.py: v2.7.0 tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_ApiSecurity: # Easy win for fiber-v2-orchestrion and version 2.12.0 - declaration: missing_feature (Fiber v2 has no HTTP AppSec integration) weblog: fiber-v2-orchestrion + tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Iast: missing_feature (IAST path reports and vulnerability stacks are not supported) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp: # Easy win for fiber-v2-orchestrion and version 2.12.0 - declaration: missing_feature (Fiber v2 has no HTTP AppSec integration) weblog: fiber-v2-orchestrion diff --git a/manifests/java.yml b/manifests/java.yml index 9103d2916e4..abf267af23c 100644 --- a/manifests/java.yml +++ b/manifests/java.yml @@ -1695,10 +1695,16 @@ manifest: resteasy-netty3: missing_feature (login endpoints not implemented) vertx3: missing_feature (login endpoints not implemented) vertx4: missing_feature (login endpoints not implemented) + tests/appsec/smoke_tests/test_apm_standalone.py::Test_Standalone_Iast: + - weblog_declaration: + play, ratpack: incomplete_test_app (The weblog does not implement the IAST path endpoint) tests/appsec/smoke_tests/test_security.py: - weblog_declaration: "*": v1.60.3 spring-boot-3-native: irrelevant (GraalVM. Tracing support only) + tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Iast: + - weblog_declaration: + play, ratpack: incomplete_test_app (The weblog does not implement the IAST path endpoint) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp: - weblog_declaration: spring-boot-payara: v1.66.0 diff --git a/manifests/nodejs.yml b/manifests/nodejs.yml index c54218552ab..c2ed4490636 100644 --- a/manifests/nodejs.yml +++ b/manifests/nodejs.yml @@ -1132,7 +1132,13 @@ manifest: - weblog_declaration: fastify: missing_feature nextjs: missing_feature + tests/appsec/smoke_tests/test_apm_standalone.py::Test_Standalone_Iast: + - weblog_declaration: + nextjs: incomplete_test_app (The weblog does not implement the IAST path endpoint) tests/appsec/smoke_tests/test_security.py: v5.92.0 + tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Iast: + - weblog_declaration: + nextjs: incomplete_test_app (The weblog does not implement the IAST path endpoint) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp: - weblog_declaration: nextjs: v6.19.0 diff --git a/manifests/php.yml b/manifests/php.yml index e1d041dff59..f342ffe7226 100644 --- a/manifests/php.yml +++ b/manifests/php.yml @@ -490,7 +490,9 @@ manifest: weblog: [apache-mod-8.1-zts, apache-mod-7.4-zts, apache-mod-7.2-zts, php-fpm-8.1, apache-mod-8.2-zts, apache-mod-8.2, php-fpm-7.0, apache-mod-7.0, php-fpm-8.0, apache-mod-7.2, apache-mod-7.1-zts, apache-mod-7.3-zts, apache-mod-7.1, php-fpm-7.3, apache-mod-8.1, symfony7x, apache-mod-7.4, apache-mod-7.3, php-fpm-7.1, apache-mod-8.0, php-fpm-8.5, php-fpm-8.6, php-fpm-8.2, apache-mod-8.0-zts, php-fpm-7.4, apache-mod-7.0-zts, laravel11x, php-fpm-7.2] - declaration: bug (APPSEC-69429) excluded_weblog: [apache-mod-8.1-zts, apache-mod-7.4-zts, apache-mod-7.2-zts, php-fpm-8.1, apache-mod-8.2-zts, apache-mod-8.2, php-fpm-7.0, apache-mod-7.0, php-fpm-8.0, apache-mod-7.2, apache-mod-7.1-zts, apache-mod-7.3-zts, apache-mod-7.1, php-fpm-7.3, apache-mod-8.1, symfony7x, apache-mod-7.4, apache-mod-7.3, php-fpm-7.1, apache-mod-8.0, php-fpm-8.5, php-fpm-8.6, php-fpm-8.2, apache-mod-8.0-zts, php-fpm-7.4, apache-mod-7.0-zts, laravel11x, php-fpm-7.2] + tests/appsec/smoke_tests/test_apm_standalone.py::Test_Standalone_Iast: missing_feature (IAST path reports and vulnerability stacks are not supported) tests/appsec/smoke_tests/test_security.py: v1.18.0 + tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Iast: missing_feature (IAST path reports and vulnerability stacks are not supported) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp::test_shi_smoke: missing_feature tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp::test_sqli_smoke: - weblog_declaration: diff --git a/manifests/python.yml b/manifests/python.yml index d1899416d0e..2a457944223 100644 --- a/manifests/python.yml +++ b/manifests/python.yml @@ -1183,10 +1183,18 @@ manifest: tests/appsec/smoke_tests/test_apm_standalone.py::Test_AppSecStandaloneAPMStandalone_Threats: - weblog_declaration: aiohttp: v4.17.0-rc1 + tests/appsec/smoke_tests/test_apm_standalone.py::Test_Standalone_Iast: + - weblog_declaration: + aiohttp: v4.18.0-rc1 + tornado: incomplete_test_app (The weblog does not implement the IAST path endpoint) tests/appsec/smoke_tests/test_security.py: v4.6.0 tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_ApiSecurity: - weblog_declaration: aiohttp: v4.17.0-rc1 + tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Iast: + - weblog_declaration: + aiohttp: v4.18.0-rc1 + tornado: incomplete_test_app (The weblog does not implement the IAST path endpoint) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp: - weblog_declaration: aiohttp: v4.17.0-rc1 diff --git a/manifests/ruby.yml b/manifests/ruby.yml index feff569168c..00c53814a71 100644 --- a/manifests/ruby.yml +++ b/manifests/ruby.yml @@ -1295,7 +1295,9 @@ manifest: sinatra32: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack) sinatra41: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack) uds-sinatra: missing_feature (no instrumentation of authentication frameworks that work with sinatra or rack) + tests/appsec/smoke_tests/test_apm_standalone.py::Test_Standalone_Iast: missing_feature (IAST path reports and vulnerability stacks are not supported) tests/appsec/smoke_tests/test_security.py: v2.30.0 + tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Iast: missing_feature (IAST path reports and vulnerability stacks are not supported) tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp::test_lfi_smoke: missing_feature tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp::test_shi_smoke: missing_feature tests/appsec/smoke_tests/test_security.py::Test_SecuritySmoke_Rasp::test_sqli_smoke: diff --git a/tests/appsec/iast/test_vulnerability_schema.py b/tests/appsec/iast/test_vulnerability_schema.py index f2a446ea0d1..f2a51dd0397 100644 --- a/tests/appsec/iast/test_vulnerability_schema.py +++ b/tests/appsec/iast/test_vulnerability_schema.py @@ -1,15 +1,13 @@ import jsonschema import json -from pathlib import Path +from tests.appsec.utils import IAST_VULNERABILITY_SCHEMA_PATH from utils import interfaces, features @features.iast_schema class TestIastVulnerabilitySchema: def test_vulnerability_schema(self) -> None: - schema_path = Path(__file__).parent / "vulnerability_schema.json" - with open(schema_path, "r") as f: - schema = json.load(f) + schema = json.loads(IAST_VULNERABILITY_SCHEMA_PATH.read_text(encoding="utf-8")) validator = jsonschema.Draft7Validator(schema) spans = [s for _, s in interfaces.library.get_root_spans()] for span in spans: diff --git a/tests/appsec/smoke_tests/test_apm_standalone.py b/tests/appsec/smoke_tests/test_apm_standalone.py index dfe3df4c5b5..6aa6d7ffc38 100644 --- a/tests/appsec/smoke_tests/test_apm_standalone.py +++ b/tests/appsec/smoke_tests/test_apm_standalone.py @@ -8,6 +8,7 @@ from tests.appsec.smoke_tests.utils import ( BaseApiSecuritySmokeTests, + BaseIastSmokeTests, BaseRaspSmokeTests, BaseRemoteConfigSmokeTests, BaseTelemetrySmokeTests, @@ -108,3 +109,16 @@ class Test_AppSecStandaloneAPMStandalone_ApiSecurity(BaseApiSecuritySmokeTests): @scenarios.appsec_standalone_apm_standalone class Test_AppSecStandaloneAPMStandalone_UserEvents(BaseUserEventsSmokeTests): pass + + +# --- IAST across all standalone scenarios --------------------------------- + + +@apm_standalone_rfc +@features.appsec_apm_standalone +@features.iast_standalone +@scenarios.appsec_apm_standalone +@scenarios.appsec_standalone_apm_standalone +@scenarios.iast_standalone +class Test_Standalone_Iast(BaseIastSmokeTests): + pass diff --git a/tests/appsec/smoke_tests/test_security.py b/tests/appsec/smoke_tests/test_security.py index abc3e463cd6..05b58b8bf59 100644 --- a/tests/appsec/smoke_tests/test_security.py +++ b/tests/appsec/smoke_tests/test_security.py @@ -3,6 +3,7 @@ from utils import features, scenarios from tests.appsec.smoke_tests.utils import ( BaseApiSecuritySmokeTests, + BaseIastSmokeTests, BaseRaspSmokeTests, BaseRemoteConfigSmokeTests, BaseTelemetrySmokeTests, @@ -52,3 +53,10 @@ class Test_SecuritySmoke_ApiSecurity(BaseApiSecuritySmokeTests): @scenarios.security_smoke class Test_SecuritySmoke_UserEvents(BaseUserEventsSmokeTests): pass + + +@features.iast_sink_path_traversal +@features.iast_stack_trace +@scenarios.security_smoke +class Test_SecuritySmoke_Iast(BaseIastSmokeTests): + pass diff --git a/tests/appsec/smoke_tests/utils.py b/tests/appsec/smoke_tests/utils.py index 1a3ea1da4ac..7d34589bca7 100644 --- a/tests/appsec/smoke_tests/utils.py +++ b/tests/appsec/smoke_tests/utils.py @@ -2,8 +2,14 @@ # This product includes software developed at Datadog (https://www.datadoghq.com/). # Copyright 2021 Datadog, Inc. -"""Shared AAP smoke tests verifying payload carriers at backend intake.""" +"""Shared security smoke tests verifying payload carriers at backend intake.""" +import json +from typing import Any + +import jsonschema + +from tests.appsec.utils import IAST_VULNERABILITY_SCHEMA_PATH from utils import context, interfaces, remote_config as rc, weblog from utils._weblog import HttpResponse from utils.dd_constants import SamplingPriority @@ -436,3 +442,109 @@ def test_login_success_smoke(self) -> None: return raise AssertionError("Agent spans should include user login event tags") + + +# --------------------------------------------------------------------------- +# IAST +# --------------------------------------------------------------------------- + +# The harness mounts this directory in every weblog. No traversal or application file is needed. +_SMOKE_PATH = "/var/log/system-tests" +_SCHEMA = json.loads(IAST_VULNERABILITY_SCHEMA_PATH.read_text(encoding="utf-8")) + + +def _assert_report(report: dict[str, Any]) -> set[str]: + """Check the source/evidence link in this carrier and return the referenced stack IDs.""" + jsonschema.validate(report, _SCHEMA) + source_indices = { + i + for i, source in enumerate(report.get("sources", [])) + if source.get("name") == "path" and source.get("value") == _SMOKE_PATH + } + assert source_indices, "IAST report lost the submitted path source" + + path_findings = [finding for finding in report["vulnerabilities"] if finding["type"] == "PATH_TRAVERSAL"] + assert path_findings, "IAST report lost the path finding" + # Other path findings on the request may come from other sources; only the one for the submitted path is checked. + findings = [ + finding + for finding in path_findings + if any( + part.get("source") in source_indices and _SMOKE_PATH in part.get("value", "") + for part in finding["evidence"].get("valueParts", []) + ) + ] + assert findings, "IAST evidence does not point to the submitted path" + stack_ids = set() + for finding in findings: + stack_id = finding["location"].get("stackId") + assert isinstance(stack_id, str), "IAST finding lost its stackId" + assert stack_id, "IAST finding has an empty stackId" + stack_ids.add(stack_id) + return stack_ids + + +def _assert_stacks(span: DataDogAgentSpan, expected: set[str]) -> None: + stacks = span.get_structured_payloads("_dd.stack") + assert stacks, "Backend did not receive the IAST stack carrier" + for payload in stacks: + seen = set() + for stack in payload.get("vulnerability", []): + if stack.get("id") in expected: + assert isinstance(stack.get("language"), str) + assert stack["language"], "IAST stack lost its language" + frames = stack.get("frames") + assert isinstance(frames, list) + assert frames, "IAST stack lost its frames" + assert all(isinstance(frame, dict) and frame for frame in frames), "IAST stack has empty frames" + seen.add(stack["id"]) + assert expected <= seen, f"IAST stacks missing for findings: {expected - seen}" + + +def _has_executed_sink_metric() -> bool: + # Telemetry metrics carry no request or span ID, so this cannot be tied to the smoke request: other requests in + # the scenario that reach a path traversal sink (e.g. /rasp/lfi) emit the same series. It checks that sink + # telemetry reaches the intake with the expected namespace, metric and tag, not which request produced it. + for data in interfaces.mocked_backend.get_telemetry_data(flatten_message_batches=False): + content = data["request"]["content"] + if content.get("request_type") != "generate-metrics": + continue + payload = content["payload"] + for series in payload.get("series", []): + if ( + (series.get("namespace") or payload.get("namespace")) == "iast" + and series.get("metric") == "executed.sink" + and series.get("type", "count") == "count" + and "vulnerability_type:path_traversal" in map(str.lower, series.get("tags", [])) + and any(value > 0 for _, value in series.get("points", [])) + ): + return True + return False + + +class BaseIastSmokeTests: + """Verify the IAST report, stack and retention carriers of a native smoke request, and that path traversal + sink telemetry reaches the intake (scenario-wide, not correlated to the request). + """ + + def setup_iast_smoke(self) -> None: + self.r = weblog.post("/iast/path_traversal/test_insecure", data={"path": _SMOKE_PATH}) + + def test_iast_smoke(self) -> None: + assert self.r.status_code == 200 + report_spans = [ + (span, reports) + for _, span in interfaces.mocked_backend.get_spans(self.r) + if (reports := span.get_structured_payloads("iast", "_dd.iast.json")) + ] + assert report_spans, "Backend did not receive an IAST report for this request" + for span, reports in report_spans: + assert span.get_sampling_priority() == SamplingPriority.USER_KEEP + enabled = span.metrics.get("_dd.iast.enabled", span.meta.get("_dd.iast.enabled")) + assert not isinstance(enabled, bool) + assert enabled in (1, "1"), f"Unexpected _dd.iast.enabled: {enabled!r}" + for report in reports: + _assert_stacks(span, _assert_report(report)) + assert _has_executed_sink_metric(), ( + "Backend did not receive positive IAST executed.sink telemetry for path traversal" + ) diff --git a/tests/appsec/utils.py b/tests/appsec/utils.py index 565f1059868..26e5fe71f2e 100644 --- a/tests/appsec/utils.py +++ b/tests/appsec/utils.py @@ -1,11 +1,14 @@ from collections.abc import Generator, Iterable import os +from pathlib import Path from utils import interfaces from utils import remote_config from utils.dd_constants import RemoteConfigApplyState from utils.dd_types import DataDogLibrarySpan +IAST_VULNERABILITY_SCHEMA_PATH = Path(__file__).parent / "utils" / "vulnerability_schema.json" + BLOCKED_IPS_COUNT_ENV_VAR = "_SYSTEM_TESTS_BLOCKED_IPS_COUNT" DEFAULT_BLOCKED_IPS_COUNT = 12500 # _blocked_ip() lays the denylist out over 12.8.0.0-12.9.255.255, using the second octet as an diff --git a/tests/appsec/iast/vulnerability_schema.json b/tests/appsec/utils/vulnerability_schema.json similarity index 100% rename from tests/appsec/iast/vulnerability_schema.json rename to tests/appsec/utils/vulnerability_schema.json diff --git a/utils/build/docker/python/django/app/urls.py b/utils/build/docker/python/django/app/urls.py index 26f4a3f6f1e..94fd023e329 100644 --- a/utils/build/docker/python/django/app/urls.py +++ b/utils/build/docker/python/django/app/urls.py @@ -536,7 +536,12 @@ def view_cmdi_secure(request): @csrf_exempt def view_iast_path_traversal_insecure(request): path = request.POST.get("path", "") - os.mkdir(path) + try: + os.mkdir(path) + except FileExistsError: + # Still exercise mkdir on every request, including for the pre-mounted smoke directory. + if not os.path.isdir(path): + raise return HttpResponse("OK")