Closed (duplicate)
Project:
htmLawed
Version:
8.x-3.0
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
29 Sep 2016 at 13:48 UTC
Updated:
3 Dec 2016 at 06:46 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
juanramonperez commentedComment #3
alpha2zee commentedHi... sorry for the delay in responding. I tested the htmLawed module with the latest version of Drupal 8, with text formats with either CKEditor enabled or disabled. With CKEditor disabled, the htmLawed filtering occurs as expected, with 'style' attribute and values passing the filter. However, with CKEditor enabled, I do see that an input such as
<p style="background-color:#fafafa;">Hello</p>when put in as 'source' in the CKEditor editor ends up becoming
<p>Hello</p>I suspect that this is a CKEditor issue. E.g., see https://www.drupal.org/node/2510970. Could it be that CKEditor itself is removing 'style'?
Comment #4
juanramonperez commentedThanks for your response.
I did some debugging and I found that if your filter type is of type
FilterInterface::TYPE_HTML_RESTRICTORthe editor module is calling to theDrupal\editor\EditorXssFilter\Standard::filterXss( )function which calls toDrupal\Component\Utility\Xss::filter( )(this function ALWAYS stripes the style attribute, no matter the configuration that you passed, is hardcoded) when the editor is loaded. Thats because the style attribute is removed on the editor side and not when the content is rendered. As a workaround I implemented thehook_editor_xss_filter_alterand then pass my ownXssFilterclass.on
mymodule.modulefileon
src/EditorXssFilter/Htmlawed.phpfileHope this helps
Comment #5
alpha2zee commentedThanks for looking into this. So, do you think I can put the suggested or similar code within the htmLawed module?
I did a test but the code suggested in your post is not working; when I try to edit content using an htmLawed filter-enabled format, I get a page with "The website encountered an unexpected error. Please try again later." and the error log shows:
TypeError: Argument 2 passed to htmlawed_editor_xss_filter_alter() must be an instance of FilterFormatInterface, instance of Drupal\filter\Entity\FilterFormat given...To test the code, I had done the following.
(1) Modified current htmlawed/htmLawed.module file so it includes:
(2) Created file htmlawed/src/EditorXssFilter/Filterhtmlawed.php with:
I will appreciate your feedback. Thanks.
Comment #6
collin.rickford commentedHave you added
use Drupal\filter\FilterFormatInterface;to htmlawed/htmLawed.module?
Comment #7
alpha2zee commentedI have now tried adding use Drupal\filter\FilterFormatInterface; to the .module file, but it doesn't help. When I create new content using an htmLawed-using text format, I the text object Object is shown in the editor window.
Comment #8
collin.rickford commentedIt appears the hooks in htmLawed.module don't run unless they match the module name (case-sensitive). I have added the exact code above and renamed the module from
htmLawed.moduletohtmlawed.module- now working for me.Patch rolled against 8.x-3.x branch
Comment #9
alpha2zee commented@juanramonperez, @collin.rockford: Thanks for your various suggestions. The codes work, though I am not finding a need to lowercase the 'l' in the 'htmLawed.module' filename.
One problem with the current code noted above for function 'filterXss' is that it raises a security risk when the text editor is in use in WYSIWYG mode (in which rendered HTML and not HTML source is displayed).
It seems the best way to deal with this is to implement the 'getHtmlRestrictions' function, as suggested in this issue.
I am now closing this particular issue.