Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mbovan created an issue. See original summary.

mbovan’s picture

Issue summary: View changes

Issue summary update.

mbovan’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
43.26 KB
29.67 KB
5.71 KB

Providing a patch. Added <main> tag (to wrap message body?) and applied some touched parts by following #2820004 #15).

Content / Plain text part:

HTML:

miro_dietiker’s picture

Priority: Normal » Major
Status: Needs review » Needs work

That looks very nice and i would love to add some improved Body output.
But we need to properly address the problems here...

+++ b/inmail.module
@@ -372,9 +372,14 @@ function inmail_theme() {
+  $variables['body']['html'] = $view_mode == 'full' ? $message->getHtml() : NULL;

+++ b/templates/inmail-message.html.twig
@@ -69,8 +69,12 @@
+            <div class="inmail-message--body__content">{{ body.content|raw|nl2br }}</div>
...
+                <div class="inmail-message--body__html">{{ body.html|raw }}</div>

We need to apply XSS protection here!

Let's add a test that adds some XSS <script> tag and make sure it's not output in the HTML.

Follow-Up: We need to discuss if we should allow opening the mail as break-out without filtering. But as this is delivered through the same domain, it contains risks of API / abuse through JS... Needs an issue to discuss... At least it could likely be that the mail is not properly displayed inside our theme and we need to check what we can do.

miro_dietiker’s picture

Ah and... just removing script tags won't help, since an onclick or onXYZ handler can contain any inline script.

So let's put caring about raw / extended HTML into a follow-up and properly output XSS filtered HTML with this issue. Always.

mbovan’s picture

Adding XSS protection by filtering tags and allowing admin tags only.

Here is how it looks with filtered tags (admin tags allowed):

Edit:
About
+ <div class="inmail-message--body__content">{{ body.content|raw|nl2br }}</div>

In the plain text, all tags are already stripped.

mbovan’s picture

Created a follow-up to discuss possibilities to improve HTML mail output.

Berdir’s picture

|raw is generally discouraged and should be avoided, instead, the object should be marked as safe

But why is the raw even necessary when it is plain text? Is there double escaping without it? You could also mark the checkefd string as save by making it a Markup object with Markup::create()

Another possibility would be to do it like \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::viewValue, to get the "technical" part out of the real twig template. Not sure if that really makes sense here.

miro_dietiker’s picture

Status: Needs review » Needs work
mbovan’s picture

But why is the raw even necessary when it is plain text? Is there double escaping without it?

Exactly. For instance, > is displayed as &gt;.

Switched to Markup::create() in this patch.

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/MIME/Message.php
    @@ -79,4 +80,12 @@ class Message extends Entity implements MessageInterface {
    +    return $content_type == 'text/html' ? Xss::filterAdmin($this->getDecodedBody()) : '';
    

    The message itself should not filter. This is a MIME Entity that should return unchanged raw data.
    Filtering is a matter of preprocessing and presentation.

  2. +++ b/src/MIME/MultipartMessage.php
    @@ -62,4 +63,18 @@ class MultipartMessage extends MultipartEntity implements MessageInterface {
    +  public function getHtml() {
    ...
    +        $markups[$key] = Xss::filterAdmin($part->getDecodedBody());
    ...
    +    return implode('', $markups);
    

    This doesn't help as a blackbox method.
    Also blindly chaining the HTML parts seems strange. We should pick the first one for the mail body display.

    For semantic indexing, this method extracting all HTML could make sense, but then it should be designed for advanced multipart conversion, supporting file conversion such as PDF text extraction and should be multipart aware.. For the basics we have getPlainText().

    If you look at the mockup, you will see that the message element needs to keep track about what parts have been used for body / html and attachments, because all unused parts are listed as unknown.

mbovan’s picture

Re #11.1: Yeah, makes sense.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/inmail.module
@@ -372,9 +374,16 @@ function inmail_theme() {
+  $content = trim($message->getPlainText());
...
+  $variables['body']['content'] = $view_mode == 'teaser' ? Markup::create(substr($content, 0, 300)) : Markup::create($content);
+  $variables['body']['html'] = $view_mode == 'full' ? Markup::create($filtered_html) : NULL;

html is as much content as plain text. I think we should rename it.

Wanted to commit to allow quick progress also in theming body / establishing the tabs, but it contains lots of conflicts with the recent changes.

mbovan’s picture

Status: Needs work » Needs review
FileSize
6.28 KB

Replaced (body) "content" with "plain" (text) and rerolled.

johnchque’s picture

Status: Needs review » Needs work
+++ b/templates/inmail-message.html.twig
@@ -52,20 +52,16 @@
+      <div class="inmail-message--body__html">{{ body.html }}</div>

I think we might want to use: inmail-message__body__html :)

+++ b/templates/inmail-message.html.twig
@@ -52,20 +52,16 @@
+       {{ message.getHeader().getFieldBody('Subject') }}</div>

Not sure if here the closing div should go in the next line maybe (?)

mbovan’s picture

#15.1: Yeah, I added element part as well.

#15.2: Oh, don't know why I changed this at all.

johnchque’s picture

Status: Needs review » Reviewed & tested by the community

#15.1 I was talking about the underscore before body. Now looks niiice.

  • miro_dietiker committed 4f8cced on 8.x-1.x authored by mbovan
    Issue #2820989 by mbovan, miro_dietiker: Identify message body content
    
miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Time to move forward! :-)

Status: Fixed » Closed (fixed)

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