Problem/Motivation
#2466931: Valid Twig syntax is incorrectly escaped in Views rewrites introduced Xss::filterAdmin() as a #post_render callback in \Drupal\views\Plugin\views\PluginBase::viewsTokenReplace(). This is stripping out namespaced attributes added by the RDF module.
Using viewsTokenReplace() replaces the token with proper value but it does not repects foaf vocabulary specification. When you render the image using viewsTokenReplace(), this is what the HTML looks like:

When I am rendering the image using renderRoot() this is what the HTML looks like:

Proposed resolution
Debug and fix the bug.
Steps to replicate the bug
See #6
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff-15-17.txt | 954 bytes | mpdonadio |
| #17 | xss_filteradmin_-2556051-17.patch | 1.51 KB | mpdonadio |
| #17 | xss_filteradmin_-2556051-test-only.patch | 1003 bytes | mpdonadio |
| #15 | xss_filteradmin_-2556051-test-only.patch | 923 bytes | mpdonadio |
| #8 | viewstokenreplace_not-2556051-8.patch | 582 bytes | subhojit777 |
Comments
Comment #2
subhojit777I changed the views setting and now I am showing images both from direct rendering and token rendering.

foaf:Imageis added to direct rendering but not in case of token rendering.mpdonadio in IRC said that this has nothing to do with views module, and there might be some problem with
rdfmodule and he added to look intordf_preprocess_image(). I debugged$variablesarray. Attributefoaf:Imagewas added to array during token rendering of image, but propertyschema:imageis not present.schema:imageproperty is present if I see the image in node page.Comment #3
subhojit777$variablesarray ofrdf_preprocess_image()in node page:$variablesarray ofrdf_preprocess_image()in views page:Comment #4
mpdonadio@subhojit777, can you export a view that generates the correct and incorrect output as in #2, but not using your custom module, and attach it to the issue? This does look like it could be a Views problem, but it is a little hard to tell where.
Comment #5
subhojit777Thanks @mpdonadio will look into it tonight.
Comment #6
subhojit777Steps:
typeofasfoaf:ImagetypeofasImageViews with image rendering properly:
Views with image rendering incorrectly:
Comment #7
subhojit777Comment #8
subhojit777Comment #10
subhojit777Just want to know whether I am going in the right direction before proceeding any further.
Comment #11
mpdonadio@subhojit777, I don't think that is the right path. We need to trace this through the render process and see where that attribute is getting messed up. I will take a look at it tonight (I'm UTC-4).
Comment #12
mpdonadioConfirmed. Let me play with this tonight to see where things are breaking down in the render process.
Comment #13
mpdonadioLooks like @subhojit777 was on the right path. The patch in #2466931: Valid Twig syntax is incorrectly escaped in Views rewrites introduced this problem. The Xss::filterAdmin() #post_render callback is stripping the namespace from the RDF attribute.
The culprit is the final preg_replace_callback():
The comment there is from #2501403: Document SafeMarkup::set in Xss::filter, but the SafeMarkup::set() was removed in #2506195: Remove SafeMarkup::set() from Xss::filter(). Can't quite tell what is going wrong in the regex there.
Going to make a unit test that demonstrates this.
Comment #14
mpdonadioEnough for me for the night. Here is a test that demonstrates the problem. Run `phpunit tests/Drupal/Tests/Component/Utility/XssTest.php` from CLI to see what happens.
Not really sure what the proper parent issue is here, if if matters.
Comment #15
mpdonadioComment #17
mpdonadioRoot cause is the attribute list that can contain semicolons in Xss::attributes() needs to be expanded. Not sure what others are needed for RDF.
Comment #19
olli commentedComment #20
mpdonadioYeah, this is a dup of #2544110: XSS attribute filtering is inconsistent and strips valid attributes.