Do not use patches from this issue
As per comment #22:
Hi Folks. This issue is closed because the approach in this patch introduces a flaw. Please do not use the patch in this thread on your website.
Please follow #2990464: Breadcrumb markup should allow some tags such as italics or strong instead.
---
Coming from #2290941: Breadcrumb shows escaped HTML tags on core admin pages, I'm creating a new issue, as per the request of the maintainer.
Problem/Motivation
When a title contains special characters like "&", they are printed as "&" in the breadcrumb.
As per the documentation, strings returned by TitleResolverInterface::getTitle are already escaped, and they are escaped again when we later turn them into a link using the Link class, since they aren't marked as 'safe'.
Steps to reproduce
Create a new view with a title like 'News & events'. Add a page display and navigate to that page. The breadcrumb will display 'News & events'
Proposed resolution
Mark the titles as safe before passing them to the Link class
Remaining tasks
Write the patch
User interface changes
None (except for some breadcrumbs that had this issue that will now be rendered correctly).
API changes
Drupal\easy_breadcrumb\EasyBreadCrumbBuilder::getTitleString will now return a \Drupal\Core\Render\Markup object instead of a string, which shouldn't be a problem since it implements the __toString() method.
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | Screen Shot 2020-06-17 at 10.26.52 AM.png | 47.07 KB | greg boggs |
| #34 | double_escaped_titles-2979389-34.patch | 936 bytes | nimoatwoodway |
| #33 | double_escaped_titles-2979389-33.patch | 863 bytes | tobiberlin |
| #28 | 2979389-27-easy_breadcrumb_double_escape.patch | 1.14 KB | jepster_ |
| #21 | 2979389-easy_breadcrumb_double_escape.patch | 2.84 KB | adixb |
Comments
Comment #2
jelle_sPatch that fixes the issue.
Comment #3
jelle_sComment #4
mahtab_alam commentedComment #6
jelle_s@mahtab_alam what is the purpose of the patch without the tests? The tests need to pass or the developers can't commit this.
Comment #7
msupko commentedThe patch in #2 solved my immediate problem, but resulted in a warning:
This patch casts the $title variable to a string before passing it to array_key_exists() to suppress this warning.
Comment #8
daggerhart commented#7 Works, applies cleanly, and includes updated tests.
Very minor nit-pick, this line removal seems unnecessary. Probably not worth holding up this patch, just noting it.
Casting the title to a string seems reasonable to me since
getTitleString()does the same thing in the case of FormattableMarkup.There is a duplicate efforts in the issue queue at #2290941: Breadcrumb shows escaped HTML tags on core admin pages. Since that issue (2290941) does not include updates to the test, we should probably re-close it and continue with this one (2979389).
Comment #9
loopduplicate commentedRerolling. No functional changes from #7.
Comment #11
loopduplicate commentedThanks :)
Comment #12
loopduplicate commentedComment #14
gregglesThere's an important followup at #2990464: Breadcrumb markup should allow some tags such as italics or strong.
Comment #15
greg boggsThanks @greggles.
Should we also update the source of the trouble?
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Controlle...
Namely the documentation says, "If the method returns a string and it is not marked safe then it will be auto-escaped." However, it's clearly not auto-escaped.
Comment #16
greggles@Greg Boggs - please.
Comment #17
tatarbjI've reverted in 8.x-1.x branch the introduced changes from this issue and under the related one I'm gonna attach a patch that delivers the feature request and does not introduce the reported vulnerability.
Comment #18
mahmoud barhouma commentedThanks , :)
Comment #19
tatarbjComment #20
eescribanoc commentedThe patches don't apply in any of the versions of the module, so I just remade it against the branch 8.x-1.x from github.
Comment #21
adixb commentedRe-rolled patch for 8.x-1.12.
Comment #22
greg boggsHi Folks. This issue is closed because the approach in this patch introduces a flaw. Please do not use the patch in this thread on your website.
~G
Comment #23
maskedjellybeanHi @Greg Boggs. If we shouldn't use this patch, can you point me to a version of this module where this has been resolved? I've tried 1.x-dev with no luck.
Comment #24
greg boggsI believe this issue is where the latest work is:
https://www.drupal.org/project/easy_breadcrumb/issues/2990464
Comment #25
maskedjellybeanThanks. I really needed a fix for this, so I just preprocessed the breadcrumb block and ran the titles through https://www.php.net/manual/en/function.htmlspecialchars-decode.php . I'm sure there's some reason this issue is more complicated and maybe that's not a secure solution, but it works well enough for me.
Comment #26
greg boggsSounds like a great solution to me. Patches encouraged. :)
Comment #27
jepster_The issue is still active in the latest stable version of Easy Breadcrumb (1.12.0).
Could not apply the patch from #21. However, the contained changes solved my issue. Rerolled the patch for version 1.12.0 of Easy Breadcrumb.
Please create an new stable release which is containing the fix.
Comment #28
jepster_Comment #29
greg boggsHi Peter! Thanks for your work so far on the patch. I believe you've coded a cross-site scripting vulnerability in your latest patch, can you take another look and ensure that the mark up object doesn't allow JavaScript?
Basically, it means that anyone with any ability to publish a crumb title would be able to become the admin user if a currently logged in admin loaded the page.
Comment #30
jepster_I currently cannot reproduce the issue anymore. However, there is executed the following code a little bit above the return. The code is creating markup from a title which has been already sanitized. Can you still reproduce the issue?
Comment #31
tobiberlinI can reproduce the issue, see attached screenshot. It is a term name.
The patch #28 resolved the issue but leads to the following warnings:
In the patch the method getTitleString() is changed in a bad manner as it does not return a string anymore but a Markup instance. I suggest the attached patch as it turns the title string into the Markup instance when the build() method has done all its magic.
Comment #32
tobiberlinMy first patch misses an "use" statement.
Comment #33
tobiberlinNow a patch really working :-/
Comment #34
nimoatwoodway#33 works for me. Just rerolled patch with fixed typo.
Comment #35
greg boggsI believe this is fixed in the latest dev branch. Can you try? The patch in 33 is a security vulnerability. Do not use it on your website if you have any logins that are not Admin users.
Comment #36
nimoatwoodwayDev branch works!
Thanks Greg Boggs!
Comment #37
Anonymous (not verified) commentedSorry, but the latest dev release did not fix this for me (I even removed the existing installation and started over with the dev version).
Comment #38
greg boggsWhat character are you using with the extra escapes?
Comment #39
Anonymous (not verified) commentedI have the ampersand in a number of term names, and it's still being displayed in breadcrumbs as & when using the latest dev release.
Comment #40
greg boggsI'm not sure, see a screen shot from my dev site. Have you tried clearing the cache and double checking that you're on the latest dev? Before the switch to Markup, this was certainly broken.
Comment #41
stephane aimar commentedSee here https://www.drupal.org/project/easy_breadcrumb/issues/3056018#comment-13...
In some cases like in the title of a view as a page, the & is & it need a fix there is 2 patch files for 8.1.13 & 8.1.x dev version on the other link of the issue.
Comment #42
markconroy commented