The Entity Embed module has some interesting use cases of data elements in HTML:

From https://github.com/drupal-media/entity_embed#display-plugins:

<drupal-entity ... data-entity-embed-display="entity_reference:entity_reference_entity_view" data-entity-embed-settings='{"view_mode":"teaser"}' />

The data-entity-embed-display attribute stores a plugin ID. By default in Drupal 8, plugin IDs that are "derivatives" contain a colon. The data-entity-embed-settings attribute stores a JSON-encoded array of the options that are provided by the formatter provided in the data-entity-embed-display attribute.

When this HTML is run through core's 'Basic HTML' text format, the code ends up looking like this:

<drupal-entity ... data-entity-embed-display="entity_reference_entity_view" data-entity-embed-settings=':"teaser"}' />

Everything before the first colon in the attributes is stripped out due to Xss::filter() calling Xss::attributes(), which then blindly calls UrlHelper::filterBadProtocol on all attribute elements. And our URL protocol filtering is mind-numbingly dumb that it only checks for the presence of a colon to be triggered.

Proposed Solution

Data attributes are supposed to store all kinds of random, crazy things that we need to store and do not have any presentational purpose unless some custom JavaScript is involved. I propose that any data attribute should skip the filterBadProtocol call.

Comments

dave reid’s picture

Issue summary: View changes
dave reid’s picture

Issue tags: +Needs backport to D7

This also affects Drupal 7.

wim leers’s picture

Status: Active » Closed (duplicate)
Related issues: +#2105841: Xss filter() mangles image captions and title/alt/data attributes

This is a duplicate of #2105841: Xss filter() mangles image captions and title/alt/data attributes. I've spent many, many hours working on a fix for this. Hopefully you can drive it home — a fresh set of eyes will surely help! :)

dave reid’s picture

I'll definitely take a look, but this is definitely proposing a different solution that might be easier to get in for now. Should we re-open it?

dave reid’s picture

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new2.08 KB

This is my proposed solution.

sun’s picture

jhedstrom’s picture

Status: Needs review » Needs work

Setting to Needs Work until it can be determined if this is distinct enough from the 2 issues mentioned above:

berdir’s picture

Issue tags: +Novice

#2105841: Xss filter() mangles image captions and title/alt/data attributes got in, will need to test if this is now solved. Tagging novice, maybe someone at dev days can look into this?

Just try to reproduce the problem with latest drupal core, if it is no longer happening, the other issue fixed it.

berdir’s picture

Duplicate comment.

cs_shadow’s picture

Status: Needs work » Closed (duplicate)

Just checked with latest version of Core and entity_embed seems to work fine. I'm pretty sure that it was fixed by #2105841: Xss filter() mangles image captions and title/alt/data attributes and so I'm closing this issue as a duplicate.

David_Rothstein’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Closed (duplicate) » Needs work

That issue was committed to Drupal 8 but not Drupal 7. I'm not really sure which of the two is appropriate to backport to Drupal 7, but reopening this one for now.

David_Rothstein’s picture

Status: Needs work » Closed (duplicate)

Looks like #2105841: Xss filter() mangles image captions and title/alt/data attributes has progressed a fair amount since then and now has an active backport. The solution is basically similar to this one, but it's a little farther along and handles title/alt too. So, closing as a duplicate after all.