Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove enable-frame-flattening and iframe for message body #740

Closed
wants to merge 1 commit into from

Conversation

rothn
Copy link
Contributor

@rothn rothn commented Sep 9, 2023

This attempts to revive #732 which contains an extremely important usability fix. Original message from @ibuclaw below:

As of WebKitGTK 2.40, enable-frame-flattening is no longer supported, the property does nothing, resulting in all messages in the thread viewer being cut off at around 150px, making all long messages unreadable.

I initially had a look into seeing whether the iframe height could be set programmatically with webkit_dom_html_iframe_element_set_height from the content of the iframe via webkit_dom_element_get_scroll_height. However nothing worked at page load time of an email thread, the content scroll height remained at 150 throughout the entire ThreadView_on_load_changed pass (because iframes are rendered lazily after the main window thread has finished? Can't think of any other reason why this was observed). The scroll height was only found to update after the thread had finished loading, and triggering a hide/show toggle on each message.

Another option would be to use the JavaScriptCore API, and have all the logic to manipulate the height of the iframe in JS. Two possible problems with this: Firstly enable-javascript is explicitly disabled in Astroid's WebKit settings; second, potentially all of the webextension code may need to be rewritten in JS - given the huge amount of deprecation warnings when building Astroid, this likely will have to be done in anger at some point in the future anyway.

I gave up going down the path of manipulating the iframe after setting srcdoc, and replaced the iframe with a div instead. CSS has been fixed up and theme version bumped as it would be a breaking change for all existing users that override the theme of the UI.

I can't see any concernable difference between before and after when viewing both text/html and text/plain messages, though it is difficult to gauge as my starting point is broken messages.

The AstroidExtension::reload_images code path is the least tested of all the changes. The minimal check I did to see whether the logic is still fine was to send myself an email with a CID attachment, and observe it render correctly after pressing C-i in thread view.

As far as this change is concerned, this is one way to fix #720 that suits my use of Astroid. I'm not convinced that it is the correct way to go about it though, as I have no reason to dismiss the rationale for using iframes in the first place - see comments delete by this patch that make reference to style issues, deadlocks and security concerns by not having the content contained to its own iframe.

As of WebKitGTK 2.40, enable-frame-flattening is no longer supported,
the property does nothing, resulting in all messages in the thread
viewer being cut off at around 150px, making all long messages
unreadable.

I initially had a look into seeing whether the iframe height could be
set programmatically with `webkit_dom_html_iframe_element_set_height`
from the content of the iframe via `webkit_dom_element_get_scroll_height`.
However nothing worked at page load time of an email thread, the content
scroll height remained at 150 throughout the entire
`ThreadView_on_load_changed` pass (because iframes are rendered lazily
after the main window thread has finished?  Can't think of any other
reason why this was observed). The scroll height was only found to
update after the thread had finished loading, and triggering a hide/show
toggle on each message.

Another option would be to use the JavaScriptCore API, and have all the
logic to manipulate the height of the iframe in JS. Two possible
problems with this: Firstly `enable-javascript` is explicitly disabled
in Astroid's WebKit settings; second, potentially all of the
`webextension` code may need to be rewritten in JS - given the huge
amount of deprecation warnings when building Astroid, this likely will
have to be done in anger at some point in the future anyway.

I gave up going down the path of manipulating the iframe after setting
`srcdoc`, and replaced the iframe with a div instead. CSS has been fixed
up and theme version bumped as it would be a breaking change for all
existing users that override the theme of the UI.

I can't see any concernable difference between before and after when
viewing both text/html and text/plain messages, though it is difficult
to gauge as my starting point is broken messages.

The `AstroidExtension::reload_images` code path is the least tested of
all the changes. The minimal check I did to see whether the logic is
still fine was to send myself an email with a CID attachment, and
observe it render correctly after pressing C-i in thread view.

As far as this change is concerned, this is one way to fix astroidmail#720 that
suits my use of Astroid. I'm not convinced that it is the correct way to
go about it though, as I have no reason to dismiss the rationale for
using iframes in the first place - see comments delete by this patch
that make reference to style issues, deadlocks and security concerns by
not having the content contained to its own iframe.
@gauteh
Copy link
Member

gauteh commented Sep 10, 2023

I think that going away from the iframe the content needs to be sanitized, to avoid harmful HTML or possibly JavaScript. It could in theory re-write the entire UI and make it appear as if the email is from someone else etc. Sanitizing is difficult to get right, and critical to get right. Luckily, it is a problem that is pretty common so there should exist good tools and libraries. That is, we should not roll our own solution. If there is no C++ library it might be possible to filter it through some command.

@rothn
Copy link
Contributor Author

rothn commented Sep 10, 2023

Hmm, yes, Geary had these issues:

A similar approach could approach for us, since Geary also did not go down the iframe path. I'm not sure what you mean by "harmful HTML" though-- could you clarify?

@rothn
Copy link
Contributor Author

rothn commented Sep 10, 2023

Actually, it looks like Astroid takes a more aggressive security posture on Javascript than Geary by disabling it entirely:

"enable-javascript", FALSE,

I don't think this is an issue here. Curious as to your thoughts, @gauteh

@gauteh
Copy link
Member

gauteh commented Sep 10, 2023

It is possible to enable javascript in astroid. But that's a conscious choice. If the body text or HTML in the email body breaks the thread-view HTML it can change an entire thread. Or it can just make an enormous blank box, moving everything else out of the way so that it appears to be emails from someone else. I'm not sure if that's exactly how it works, but that's why we usually show the text part and don't render the HTML.

@rothn
Copy link
Contributor Author

rothn commented Sep 10, 2023

It is possible to enable javascript in astroid. But that's a conscious choice.

In that case, how would you feel about adding "enable-javascript-markup", FALSE to the config? If I understand correctly, this would protect the people who choose to manually enable javascript unless they explicitly allow javascript markup by editing the code.

If the body text or HTML in the email body breaks the thread-view HTML it can change an entire thread. Or it can just make an enormous blank box, moving everything else out of the way so that it appears to be emails from someone else.

I can't easily disprove that this might be possible. However, compared to the alternative of most email being broken, and since I have not had this issue, I would suggest dealing with this if it ever comes up.

EDIT: One thing we can do about this is roll back on the first sign that this is breaking peoples' workflows. At that point, we would also have more information on what specifically breaks, how it's broken, and we'd have a test-case as well.

@rothn
Copy link
Contributor Author

rothn commented Sep 13, 2023

@gauteh How would you feel about the path I suggested a couple of days ago?

@gauteh
Copy link
Member

gauteh commented Sep 13, 2023

I understand the argument, and usually I don't think "deal with it when it becomes a problem" is a deal-breaker. However, I don't think it is a good idea to ignore a known security risk, that will expose our users. There is no way back from that, and it is not ethical. We should deal with the issue in a good enough matter now, that solution probably had to be sanitize html and JavaScript. That is what makes this issue so hard to fix.

@ibuclaw
Copy link
Contributor

ibuclaw commented Sep 13, 2023

FWIW I concur with @gauteh. I still run with this patch though as for me, my email account only receives messages from text-only mailing lists, so would never hit HTML issues as pointed out both in the issue, and the code comment that gets removed by this patch.

@ibuclaw
Copy link
Contributor

ibuclaw commented Sep 13, 2023

Anyone with a little reading into this would know that Astroid wasn't the only application affected by this deprecation.

  • Gfeeds just deleted the code with no apparent effect.
  • Remmina ifdef'd the code out and seems like it wasn't required as well.
  • Evolution more closely resembles astroid, they moved the logic into Javascript client render code, but then suffered many, many, many, many fallout issues from doing that.

@jorsn
Copy link
Member

jorsn commented Sep 16, 2023

It is possible to enable javascript in astroid. But that's a conscious choice.
-- @gauteh

How is this possible? Only by modifying the source code? Then, I wouldn't call it configuration and hold everyone who does it responsible on their own.

@gauteh
Copy link
Member

gauteh commented Sep 16, 2023

You're right, JavaScript is disabled now (09b5c4f). Used to be possible outside the message content I think. At least we had mathjax support previously. It is still possible to mess up the view in a harmful way with just html and css.

jorsn added a commit to jorsn/astroid that referenced this pull request Sep 16, 2023
yzhs pushed a commit to yzhs/astroid that referenced this pull request Mar 30, 2024
jorsn added a commit to jorsn/astroid that referenced this pull request May 28, 2024
- fixes astroidmail#720
- alternative to removing iframes as in astroidmail#740 or astroidmail#732
  or the semi-working astroidmail#743

This does not allow the document (message content) to execute
javascript, as can be verified with the following email,
which displays "no scripts" by default, but "scripts active" when js is
active.

```
Date: Tue, 1 January 1970 00:00:00 +0000
From:
Subject:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="=-TUjG03Ah9OcLtWE56Ucm"

--=-TUjG03Ah9OcLtWE56Ucm
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<div id=3D"jscontent">
  no scripts
</div>

<script>
  d =3D document.getElementById('jscontent');
  d.innerHTML =3D "scripts active";
</script>

--=-TUjG03Ah9OcLtWE56Ucm
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" lang xml:lang>
<head>
  <meta charset=3D"utf-8" />
  <meta name=3D"generator" content=3D"pandoc" />
  <meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=3D=
1.0, user-scalable=3Dyes" />
  <style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
</head>
<body>
<div id=3D"jscontent">
<p>no scripts</p>
</div>
<script>
  d =3D document.getElementById('jscontent');
  d.innerHTML =3D "scripts active";
</script>
</body>
</html>

--=-TUjG03Ah9OcLtWE56Ucm--
```
@jorsn
Copy link
Member

jorsn commented May 28, 2024

Btw, a problem with this here is that I cannot scroll using the mouse any more, only with keyboard. Especially, touchpad scrolling is helpful at the laptop.

@jorsn jorsn mentioned this pull request May 31, 2024
jorsn added a commit to jorsn/astroid that referenced this pull request Jun 3, 2024
- fixes astroidmail#720
- alternative to removing iframes as in astroidmail#740 or astroidmail#732
  or the semi-working astroidmail#743

This does not allow the document (message content) to execute
javascript, as can be verified with the following email,
which displays "no scripts" by default, but "scripts active" when js is
active.

```
Date: Tue, 1 January 1970 00:00:00 +0000
From:
Subject:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="=-TUjG03Ah9OcLtWE56Ucm"

--=-TUjG03Ah9OcLtWE56Ucm
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<div id=3D"jscontent">
  no scripts
</div>

<script>
  d =3D document.getElementById('jscontent');
  d.innerHTML =3D "scripts active";
</script>

--=-TUjG03Ah9OcLtWE56Ucm
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" lang xml:lang>
<head>
  <meta charset=3D"utf-8" />
  <meta name=3D"generator" content=3D"pandoc" />
  <meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=3D=
1.0, user-scalable=3Dyes" />
  <style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
</head>
<body>
<div id=3D"jscontent">
<p>no scripts</p>
</div>
<script>
  d =3D document.getElementById('jscontent');
  d.innerHTML =3D "scripts active";
</script>
</body>
</html>

--=-TUjG03Ah9OcLtWE56Ucm--
```
jorsn added a commit to jorsn/astroid that referenced this pull request Jun 4, 2024
- fixes astroidmail#720
- alternative to removing iframes as in astroidmail#740 or astroidmail#732
  or the semi-working astroidmail#743

This does not allow the document (message content) to execute
javascript, as can be verified with the following email,
which displays "no scripts" by default, but "scripts active" when js is
active.

```
Date: Tue, 1 January 1970 00:00:00 +0000
From:
Subject:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="=-TUjG03Ah9OcLtWE56Ucm"

--=-TUjG03Ah9OcLtWE56Ucm
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<div id=3D"jscontent">
  no scripts
</div>

<script>
  d =3D document.getElementById('jscontent');
  d.innerHTML =3D "scripts active";
</script>

--=-TUjG03Ah9OcLtWE56Ucm
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" lang xml:lang>
<head>
  <meta charset=3D"utf-8" />
  <meta name=3D"generator" content=3D"pandoc" />
  <meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=3D=
1.0, user-scalable=3Dyes" />
  <style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
</head>
<body>
<div id=3D"jscontent">
<p>no scripts</p>
</div>
<script>
  d =3D document.getElementById('jscontent');
  d.innerHTML =3D "scripts active";
</script>
</body>
</html>

--=-TUjG03Ah9OcLtWE56Ucm--
```
@jorsn jorsn closed this in #747 Jun 4, 2024
yzhs pushed a commit to yzhs/astroid that referenced this pull request Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webkit_settings_set_enable_frame_flattening() deprecation
4 participants