Skip to content

Commit a91a228

Browse files
avara1986github-actions[bot]
authored andcommitted
chore(iast): xss vulnerability for jinja2 (#12238)
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. ## 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) (cherry picked from commit a8dfadf)
1 parent 1247ac2 commit a91a228

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

ddtrace/appsec/_iast/taint_sinks/xss.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ def patch():
6464
)
6565

6666
_set_metric_iast_instrumented_sink(VULN_XSS)
67-
_set_metric_iast_instrumented_sink(VULN_XSS)
67+
# Even when starting the application with `ddtrace-run ddtrace-run`, `jinja2.FILTERS` is created before this patch
68+
# function executes. Therefore, we update the in-memory object with the newly patched version.
69+
try:
70+
from jinja2.filters import FILTERS
71+
from jinja2.filters import do_mark_safe
72+
73+
FILTERS["safe"] = do_mark_safe
74+
except (ImportError, KeyError):
75+
pass
6876

6977

7078
def unpatch():

tests/appsec/integrations/fastapi_tests/test_fastapi_appsec_iast.py

-4
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,6 @@ async def test_route(request: Request):
10031003

10041004
with override_global_config(dict(_iast_enabled=True, _iast_request_sampling=100.0)):
10051005
patch_iast({"xss": True})
1006-
from jinja2.filters import FILTERS
1007-
from jinja2.filters import do_mark_safe
1008-
1009-
FILTERS["safe"] = do_mark_safe
10101006
_aux_appsec_prepare_tracer(tracer)
10111007
resp = client.get(
10121008
"/index.html?iast_queryparam=test1234",

tests/appsec/integrations/flask_tests/test_iast_flask.py

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ def setUp(self):
5151
patch_header_injection()
5252
patch_xss_injection()
5353
patch_json()
54-
from jinja2.filters import FILTERS
55-
from jinja2.filters import do_mark_safe
56-
57-
FILTERS["safe"] = do_mark_safe
5854
super(FlaskAppSecIASTEnabledTestCase, self).setUp()
5955
self.tracer._configure(api_version="v0.4", appsec_enabled=True, iast_enabled=True)
6056
oce.reconfigure()

0 commit comments

Comments
 (0)