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.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 2327341-filter-attribute-value-skip-data-attributes.patch | 2.08 KB | dave reid |
Comments
Comment #1
dave reidComment #2
dave reidThis also affects Drupal 7.
Comment #3
wim leersThis 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! :)
Comment #4
dave reidI'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?
Comment #5
dave reidYeah, I don't think the approach in #2105841: Xss filter() mangles image captions and title/alt/data attributes is what I want to try.
Comment #6
dave reidThis is my proposed solution.
Comment #7
sunThis issue seemingly duplicates #952964: String stripped from title and alt attribute if contains a colon
Comment #8
jhedstromSetting to Needs Work until it can be determined if this is distinct enough from the 2 issues mentioned above:
Comment #9
berdir#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.
Comment #10
berdirDuplicate comment.
Comment #11
cs_shadow commentedJust 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.
Comment #12
David_Rothstein commentedThat 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.
Comment #13
David_Rothstein commentedLooks 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.