Skip to content

Commit

Permalink
fix(iast): xss vulnerability for jinja2
Browse files Browse the repository at this point in the history
  • Loading branch information
avara1986 committed Feb 6, 2025
1 parent 9ba79f4 commit 7ccb223
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 9 additions & 1 deletion ddtrace/appsec/_iast/taint_sinks/xss.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ def patch():
)

_set_metric_iast_instrumented_sink(VULN_XSS)
_set_metric_iast_instrumented_sink(VULN_XSS)
# Even when starting the application with `ddtrace-run ddtrace-run`, `jinja2.FILTERS` is created before this patch
# function executes. Therefore, we update the in-memory object with the newly patched version.
try:
from jinja2.filters import FILTERS
from jinja2.filters import do_mark_safe

FILTERS["safe"] = do_mark_safe
except (ImportError, KeyError):
pass


def unpatch():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,6 @@ async def test_route(request: Request):

with override_global_config(dict(_iast_enabled=True, _iast_request_sampling=100.0)):
patch_iast({"xss": True})
from jinja2.filters import FILTERS
from jinja2.filters import do_mark_safe

FILTERS["safe"] = do_mark_safe
_aux_appsec_prepare_tracer(tracer)
resp = client.get(
"/index.html?iast_queryparam=test1234",
Expand Down
4 changes: 0 additions & 4 deletions tests/appsec/integrations/flask_tests/test_iast_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def setUp(self):
patch_header_injection()
patch_xss_injection()
patch_json()
from jinja2.filters import FILTERS
from jinja2.filters import do_mark_safe

FILTERS["safe"] = do_mark_safe
super(FlaskAppSecIASTEnabledTestCase, self).setUp()
self.tracer._configure(api_version="v0.4", appsec_enabled=True, iast_enabled=True)
oce.reconfigure()
Expand Down

0 comments on commit 7ccb223

Please sign in to comment.