You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been using the Cleaner since v1.16.1 to sanitize SVG by removing script.
After upgrading from v1.19.1 to v1.20.1, the behavior has changed and the text of the script is no longer removed.
With all versions from v1.16.1 through v1.19.1, this results in <svg></svg> with all the script removed.
But with v1.20.1, it now results in <svg>alert("test")</svg>.
Interesting find! And thanks for the clear report.
The underlying issue was that as we improved namespace support, the SVG Script element's contents were not parsed as Data, but as regular Text.
In jsoup, when the Cleaner encounters an unsafe tag and drops it, it preserves that element's Text, but will drop Data.
As far as I can tell we were parsing foreign content according to the spec. There are no tokenization steps there to push the tokenizer into a Data text state, and so the content will be parsed as Text.
However on comparison to Chrome I see the content is parsed as Data. So I have added an explicit push to the Data state in jsoup's impl.
I also added support for custom tags when in foreign content to be parsed as data.
Just looking at SVG Script spec, the examples have the script content wrapped as <![CDATA[ ... ]]>, as its in XML. And CData is supported in HTML in foreign content mode, so I guess that's how the spec expects script data to be provided. But in practice UAs work as mentioned above without the CData requirement.
Activity
jhy commentedon May 6, 2025
Interesting find! And thanks for the clear report.
The underlying issue was that as we improved namespace support, the SVG Script element's contents were not parsed as Data, but as regular Text.
In jsoup, when the Cleaner encounters an unsafe tag and drops it, it preserves that element's Text, but will drop Data.
As far as I can tell we were parsing foreign content according to the spec. There are no tokenization steps there to push the tokenizer into a Data text state, and so the content will be parsed as Text.
However on comparison to Chrome I see the content is parsed as Data. So I have added an explicit push to the Data state in jsoup's impl.
I also added support for custom tags when in foreign content to be parsed as data.
jhy commentedon May 6, 2025
Just looking at SVG Script spec, the examples have the script content wrapped as
<![CDATA[ ... ]]>, as its in XML. And CData is supported in HTML in foreign content mode, so I guess that's how the spec expects script data to be provided. But in practice UAs work as mentioned above without the CData requirement.script in svg should be parsed as ScriptData
chore(deps): update all non-major dependencies (mulk/mulkcms2!58)