Skip to content

Commit 714df9e

Browse files
ci(iast): fix flaky test [backport 3.19] (#15754)
Backport 381404b from #15749 to 3.19. The urlparse function was imported inside the async function view_iast_ssrf_secure, which caused a race condition in multiprocess mode where: - The IAST validator wrapper for urlparse is set up at module startup - But importing inside a function can bypass or inconsistently apply the wrapper - This caused the secure mark to not be applied reliably, leading to false SSRF vulnerability reports Flaky tests IDs: DD_1PGYGI DD_ONKXDT DD_U2V880 DD_954GJO DD_O236KS Signed-off-by: Alberto Vara <[email protected]> Co-authored-by: Alberto Vara <[email protected]>
1 parent 0cab93b commit 714df9e

File tree

2 files changed

+3
-5
lines changed
  • ddtrace/appsec/_iast/taint_sinks
  • tests/appsec/integrations/fastapi_tests

2 files changed

+3
-5
lines changed

ddtrace/appsec/_iast/taint_sinks/_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def _rel_path(file_name: str) -> str:
144144
# If the path contains site-packages anywhere, return 'site-packages/<rest>'
145145
# Normalize separators to forward slashes for consistency
146146
if (idx := file_name_norm.find("/site-packages/")) != -1:
147-
print(f"file_name_norm({idx}): {file_name_norm}")
148147
return file_name_norm[idx:]
149148
return ""
150149

tests/appsec/integrations/fastapi_tests/app.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import subprocess
66
import time
77
from urllib.parse import parse_qs
8+
from urllib.parse import urlparse
89

910
from fastapi import FastAPI
1011
from fastapi import Form
@@ -107,17 +108,15 @@ async def cmdi(filename: str):
107108

108109
@app.post("/iast/ssrf/test_secure", response_class=PlainTextResponse)
109110
async def view_iast_ssrf_secure(url: str = Form(...)):
110-
from urllib.parse import urlparse
111-
112111
# Validate the URL and enforce whitelist
113112
allowed_domains = ["example.com", "api.example.com", "www.datadoghq.com", "localhost"]
114-
if type(url) == bytes:
113+
if isinstance(url, bytes):
115114
url = url.decode("utf-8")
116115
parsed_url = urlparse(url)
117116
if parsed_url.hostname not in allowed_domains:
118117
return PlainTextResponse("Forbidden", status_code=403)
119118
try:
120-
requests.get(parsed_url.geturl())
119+
requests.get(url)
121120
except Exception:
122121
pass
123122

0 commit comments

Comments
 (0)