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

Comments

Jelle_S created an issue. See original summary.

jelle_s’s picture

Status: Active » Needs review
StatusFileSize
new2.13 KB

Patch that fixes the issue.

jelle_s’s picture

Issue summary: View changes
mahtab_alam’s picture

StatusFileSize
new885 bytes

Status: Needs review » Needs work

The last submitted patch, 4: 2979389-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jelle_s’s picture

Status: Needs work » Needs review

@mahtab_alam what is the purpose of the patch without the tests? The tests need to pass or the developers can't commit this.

msupko’s picture

The patch in #2 solved my immediate problem, but resulted in a warning:

Warning: array_key_exists(): The first argument should be either a string or an integer in Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build() (line 237 of modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php).

This patch casts the $title variable to a string before passing it to array_key_exists() to suppress this warning.

daggerhart’s picture

Status: Needs review » Reviewed & tested by the community

#7 Works, applies cleanly, and includes updated tests.

  1. +++ b/src/EasyBreadcrumbBuilder.php
    @@ -232,9 +233,8 @@ class EasyBreadcrumbBuilder implements BreadcrumbBuilderInterface {
    -
    

    Very minor nit-pick, this line removal seems unnecessary. Probably not worth holding up this patch, just noting it.

  2. +++ b/src/EasyBreadcrumbBuilder.php
    @@ -232,9 +233,8 @@ class EasyBreadcrumbBuilder implements BreadcrumbBuilderInterface {
    +            if ($title && array_key_exists((string)$title, $replacedTitles)) {
    

    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).

loopduplicate’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.61 KB

Rerolling. No functional changes from #7.

  • loopduplicate committed eb8d0db on 8.x-1.x
    Issue #2979389 by Jelle_S, mahtab_alam, msupko, loopduplicate,...
loopduplicate’s picture

Status: Needs review » Fixed

Thanks :)

loopduplicate’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

greggles’s picture

greg boggs’s picture

Thanks @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.

greggles’s picture

@Greg Boggs - please.

tatarbj’s picture

I'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.

mahmoud barhouma’s picture

Thanks , :)

tatarbj’s picture

eescribanoc’s picture

StatusFileSize
new3.77 KB

The 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.

adixb’s picture

Re-rolled patch for 8.x-1.12.

greg boggs’s picture

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.

~G

maskedjellybean’s picture

Hi @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.

greg boggs’s picture

I believe this issue is where the latest work is:

https://www.drupal.org/project/easy_breadcrumb/issues/2990464

maskedjellybean’s picture

Thanks. 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.

greg boggs’s picture

Sounds like a great solution to me. Patches encouraged. :)

jepster_’s picture

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.

jepster_’s picture

greg boggs’s picture

Hi 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.

jepster_’s picture

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?

tobiberlin’s picture

StatusFileSize
new489 bytes

I can reproduce the issue, see attached screenshot. It is a term name.

The patch #28 resolved the issue but leads to the following warnings:

Warning: array_key_exists(): The first argument should be either a string or an integer in Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build() (line 405 of modules\contrib\easy_breadcrumb\src\EasyBreadcrumbBuilder.php).

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.

tobiberlin’s picture

StatusFileSize
new489 bytes

My first patch misses an "use" statement.

tobiberlin’s picture

StatusFileSize
new863 bytes

Now a patch really working :-/

nimoatwoodway’s picture

StatusFileSize
new936 bytes

#33 works for me. Just rerolled patch with fixed typo.

greg boggs’s picture

I 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.

nimoatwoodway’s picture

Dev branch works!
Thanks Greg Boggs!

Anonymous’s picture

Sorry, but the latest dev release did not fix this for me (I even removed the existing installation and started over with the dev version).

greg boggs’s picture

What character are you using with the extra escapes?

Anonymous’s picture

I have the ampersand in a number of term names, and it's still being displayed in breadcrumbs as & when using the latest dev release.

greg boggs’s picture

StatusFileSize
new47.07 KB

I'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.

stephane aimar’s picture

See 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 &amp 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.

markconroy’s picture

Issue summary: View changes