Problem/Motivation

Xss::filter() does not handle HTML tags inside attributes. The respective core issue for this is #3227831: Xss::filter() does not handle HTML tags inside attribute values. However, since the core issue requires changing Xss::filter(), it's unlikely to be solved any time soon. Ideally we could change how attributes are encoded to ensure compatibility with Xss::filter(). This is required for for #3222808: Follow-up for #3201646: markup in image captions is lost. However, this could be reproduced outside of that issue in some edge cases. For example, if I wanted to add alt="</em> a strange alt text" attribute to an img element, CKEditor 5 would happily allow us to do that through the UI.

Proposed resolution

Encode attributes to match expectations by Xss::filter().

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork ckeditor5-3247246

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lauriii created an issue. See original summary.

Wim Leers’s picture

For example, if I wanted to add alt="</em> a strange alt text" attribute to an img element, CKEditor 5 would happily allow us to do that through the UI.

But this is not a case where we need to support it: we only need to support it for data-caption. For all other attributes, we can strip away all HTML, can't we? Even if CKEditor 5 does not do that by default.

effulgentsia’s picture

Re #3222808-20: Follow-up for #3201646: markup in image captions is lost, HEAD's Html::normalize() function already converts < and > inside of attribute values to &lt; and &gt;.

So a possible solution here is to make sure Html::normalize() is called before Xss:filter(). The question is where? I think the best option would be to call Html::normalize() when saving. Not sure where the best place to do that would be if the goal is to only do it when saving a textarea that was edited by CKE5.

Wim Leers’s picture

Not sure where the best place to do that would be if the goal is to only do it when saving a textarea that was edited by CKE5.

We can't do that, at all.

We should not be processing the HTML generated by CKE5 after it's done its job and before it gets saved. That'd be violating the abstraction layer provided by the Text Editor module.

effulgentsia’s picture

Another approach is to change FilterHtml::process() to call Html::normalize() before calling Xss::filter(). It already normalizes the HTML after calling that, via filterAttributes(), so given that, I don't think that normalizing before as well would regress anything. But if we're going to take this approach, let's do it as a separate core issue, since then that's not scoped to ckeditor5 module.

Wim Leers’s picture

That's my point exactly: either we need to modify Drupal core (and that has huge risks, not in the least in terms of timeline), or we need to tweak CKEditor 5. We previously concluded we needed to tweak CKEditor 5. We got the infrastructure we needed to be able to do that. But … it appears to be inadequate, I just don't understand why yet. See #3222808-26: Follow-up for #3201646: markup in image captions is lost, where I'm asking @lauriii for clarifications — because I definitely feel lost right now 😳.

lauriii’s picture

We can encode the attributes to match Xss::filter() expectations by overriding the CKEditor HTML Writer as mentioned in #3222808-26: Follow-up for #3201646: markup in image captions is lost. I created this spinoff because I realized this problem goes beyond just caption markup. This is about < and > characters in all attributes.

But this is not a case where we need to support it: we only need to support it for data-caption. For all other attributes, we can strip away all HTML, can't we? Even if CKEditor 5 does not do that by default.

If we want to match CKEditor 4 behavior closely as possible, we would have to encode HTML in all attributes.

lauriii’s picture

Status: Active » Needs review
Wim Leers’s picture

Wim Leers’s picture

Add Nightwatch tests for DrupalHtmlBuilder 😅

🚀

Wim Leers’s picture

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-prettier".

(The package "eslint-plugin-prettier" was not found when loaded as a Node module from the directory "/var/www/html".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

    npm install eslint-plugin-prettier@latest --save-dev

The plugin "eslint-plugin-prettier" was referenced from the config file in "../.eslintrc.json » ./core/.eslintrc.json".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Any idea what could cause this? 😳

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

This looks great, no further remarks, just the single failure left to be addressed! 🥳

EPIC work!

bnjmnm made their first commit to this issue’s fork.

  • lauriii committed 53a6bbe on 1.0.x
    Issue #3247246 by lauriii, Wim Leers: Attribute value encoding not...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.