-
-
Notifications
You must be signed in to change notification settings - Fork 791
Description
When running DOMPurify.sanitize(<...>)
, some settings are "sticky".
Specifically, if passing in the HTML_INTEGRATION_POINTS: {'foreignobject': true}
on the config the first time, the setting will carry over even to future invocations of sanitize
that do not have the HTML_INTEGRATION_POINTS
on the config. That shouldn't be the case... right?
Running example:
- Open https://zlatkovsky.github.io/DOMPurifyMystery/
- Select version
3.2.4
or3.2.6
in the "Select a version" dropdown. Leave the "HTML integration points" checkbox as OFF for now. - Click "Sanitize!". Note that in the "After sanitization" section, the text in the blue box is missing. This is a known issue due to DOMPurify 3.1.7 breaks Mermaid diagrams using
foreignObject
#1002 .
- Now turn ON the "Enable HTML integration points" checkbox and press "Sanitize!" again. This time the label will show up in the blue box, as expected.
- Finally, turn the "Enable HTML integration points" OFF again and press "Sanitize!"
I would have expected the result of #5
to be the same as #3
, i.e., the label should be missing again since the checkbox is OFF. But instead, the label is still visible because the HTML_INTEGRATION_POINTS
isn't reset.
The source code for the above site can be found at https://github.com/Zlatkovsky/DOMPurifyMystery/blob/main/index.html.
Tracing through DOMPurify code, it appears that:
- On invocation of
DOMPurify.sanitize
,_parseConfig
is called:
- Specifically, this means that the following line is invoked:
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
- If the first call to
DOMPurify.sanitize
hadHTML_INTEGRATION_POINTS: {'foreignobject': true}
in the config, the bundle-scopedHTML_INTEGRATION_POINTS
variable will be set. - On follow-up invocations of
DOMPurify.sanitize
that do NOT haveHTML_INTEGRATION_POINTS
set, the line from#2
is hit again. Becausecfg.HTML_INTEGRATION_POINTS
is undefined,HTML_INTEGRATION_POINTS
gets set to just itself. BUT, since it never gets reset acrossDOMPurify.sanitize
invocations, it just stays as whatever the last config that had this setting set it to.