Closed (fixed)
Project:
Drupal core
Version:
8.1.x-dev
Component:
views.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
16 Oct 2015 at 15:33 UTC
Updated:
2 Aug 2016 at 11:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ccmorris commentedPossible duplicate of #2584655: Views field "Global > Custom Text" incorrectly escapes HTML, though token replacement is not necessary to repeat the problem. There is a workaround for the bug there as well.
Comment #3
ccmorris commented#2584655: Views field "Global > Custom Text" incorrectly escapes HTML covers the incorrect escaping using "Custom text" field. Fixing that issue would likely solve the escaping for the "Content: Path" rewrite. I have changed the title of this issue in case it does not.
Priority changed to Major since this is a regression.
Comment #4
ccmorris commentedThe related issue for Custom Text #2579427: Outputting markup from custom text field is not possible is fixed in 8.0.x-dev. That patch did not fix this issue.
Comment #5
ccmorris commentedI decided to try to tackle this myself. I have attached a patch that needs review. Is it safe to use ViewsRenderPipelineMarkup on the alias URL after a Xss::filterAdmin?
This should probably have tests too.
Comment #6
dawehnerIMHO the right thing to do would be to return a simple render eoement with just
['#markup']ViewsRenderPipelineMarkupis really more about internals of views.Comment #7
rakesh.gectcrComment #8
rakesh.gectcr@dawehner,
++, patch changed according to above comment. and tested manually.
Comment #9
dawehnerWe need automated tests, sorry
Comment #10
cilefen commentedComment #12
mikeker commentedRemoved UUID from the added test view.
Comment #13
mikeker commentedSince my change was very minor I'm going to RTBC this. The code change looks good and relies on Twig's auto-escaping -- always a good thing.
Thank you, @cilefen, for the tests!
Comment #15
mikeker commentedHiding test-only patches...
Comment #16
dawehner+1 for this fix. We applied similar strategies in other areas.
Comment #17
catchI was confused why this works reading the patch. What's getting escaped is not the canonical URL for the node, but the altered text - so I could not figure out why making the URL #markup would affect anything.
Reading through, it looks like it will be this hunk in FieldPluginBase::renderText():
So the problem is that the 'safeness' of the rewritten text is based on the 'safeness' of the original text.
To me that looks like a much deeper issue with SafeMarkup and field rewrites, and at a minimum we should look at a follow-up + comments here explaining why it works like this.
Comment #18
ccmorris commentedI see what you mean. The 'safeness' of the rewrite should be independent from the 'safeness' of the original value.
In FieldPluginBase::renderText(), the returned text is autoescaped by Twig if the original text is unsafe. Could we escape unsafe text before rewriting, rather than after?
Comment #19
mikeker commentedFrom #17:
At
core/modules/views/src/Plugin/views/field/FieldPluginBase.php:1140therender()method is called and, if a render array is returned it's converted to a Render\Markup object. WhenFieldPluginBase::renderTextis later called,$value_is_safeis (correctly) set to true asviewsTokenReplace()will return an XSS admin filtered string.If
Path::render()returns just a URL string, then$value_is_safeends up as false. Perhaps incorrectly? We could mark the return fromPath::render()as safe, but I thought we were trying to get away from that...Comment #20
mikeker commentedThough this does raise a point:
renderText()does an awful lot of string replacements and whatnot. All of these need to be (at a minimum)Xss::filterAdmin()'ed and by packing them all in one long method with a comment at the top seems like a security issue waiting to happen.But that cleanup should happen in a followup issue...
Comment #22
mikeker commentedPossibly related issue.
Comment #23
dawehnerFiled this followup: #2760143: Refactor views rewrite to be a) sane and b) secure
Nitpick on commit: Remove the
@fileheader.Comment #24
alexpottCommitted and pushed 8fb4440373a148a04f631090fc924ba74d44362e to 8.2.x and 61301b5 to 8.1.x. Thanks!
And yes views rewriting and safeness is hard and complex.
Fixes on commit: