Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Draft: Fix svg images not correctly displaying in e2ee rooms #8325

Closed

Conversation

justjanne
Copy link
Contributor

@justjanne justjanne commented Apr 14, 2022

Type: Defect
Related: element-hq/element-web#15094
Related: element-hq/element-web#18526


Here's what your changelog entry will look like:

🐛 Bug Fixes

  • Draft: Fix svg images not correctly displaying in e2ee rooms (#8325). Contributed by @justjanne.

@github-actions github-actions bot added the T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems label Apr 14, 2022
@codecov
Copy link

codecov bot commented Apr 14, 2022

Codecov Report

Merging #8325 (dfac604) into develop (f95106d) will decrease coverage by 0.00%.
The diff coverage is 14.28%.

@@             Coverage Diff             @@
##           develop    #8325      +/-   ##
===========================================
- Coverage    29.88%   29.88%   -0.01%     
===========================================
  Files          879      879              
  Lines        50074    50086      +12     
  Branches     12741    12743       +2     
===========================================
  Hits         14966    14966              
- Misses       35108    35120      +12     
Impacted Files Coverage Δ
...components/views/messages/DownloadActionButton.tsx 0.00% <0.00%> (ø)
src/components/views/messages/MAudioBody.tsx 2.56% <0.00%> (ø)
src/components/views/messages/MFileBody.tsx 30.18% <0.00%> (ø)
src/components/views/messages/MImageBody.tsx 0.48% <0.00%> (ø)
src/components/views/messages/MVideoBody.tsx 0.90% <ø> (ø)
src/utils/MediaEventHelper.ts 32.25% <16.66%> (-7.75%) ⬇️

- store original mimetype of blobs as well
- if they differ, use a data url instead of a blob url (data urls have a unique origin)
@justjanne justjanne force-pushed the justjanne/fix/15094-18526-e2ee-broken-svg-embed branch from 6506f08 to c779376 Compare April 14, 2022 14:07
@justjanne justjanne marked this pull request as ready for review April 14, 2022 14:36
@justjanne justjanne requested a review from a team as a code owner April 14, 2022 14:36
@justjanne
Copy link
Contributor Author

This PR uses data URLs for embedded SVGs in E2EE rooms and other situations where no PNG version is available. This ensures we get a high quality preview without the risk of exposing our origin to user-defined scripts.

Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this, though it's not something we can merge easily. In addition to the comments below, I think this needs explicit review from the security team.

Comment on lines +55 to +60
public get sourceBlob() {
return this.sourceTypedBlob.value.then(it => it.data);
}
public get thumbnailBlob() {
return this.thumbnailTypedBlob.value.then(it => it.data);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these need return types, and a blank line between them

Comment on lines -35 to -36
public readonly sourceBlob: LazyValue<Blob>;
public readonly thumbnailBlob: LazyValue<Blob>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were deliberately exposed and should not be hidden. It's for overall performance of the app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also used by projects downstream of us)

if (this.media.isEncrypted) {
const content = this.event.getContent<IMediaEventContent>();
return decryptFile(content.file, content.info);
return decryptFile(content.file, content.info).then(data => {
return { mimetype: content.info.mimetype, data };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info might not exist, and decryptFile should be responsible for mimetype detection.

if (!this.media.hasThumbnail) return Promise.resolve(null);

if (this.media.isEncrypted) {
const content = this.event.getContent<IMediaEventContent>();
if (content.info?.thumbnail_file) {
return decryptFile(content.info.thumbnail_file, content.info.thumbnail_info);
return decryptFile(content.info.thumbnail_file, content.info.thumbnail_info).then(data => {
return { mimetype: content.info.thumbnail_info.mimetype, data };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info might not exist, and decryptFile should be responsible for mimetype detection.

thumbnail_info also might not exist

}

async function createDataUrl(blob: ITypedBlob): Promise<string> {
return `data:${blob.mimetype};base64,${await blob.data.text().then(btoa)}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This opens us up to XSS attacks, which we do not want.

@justjanne
Copy link
Contributor Author

@turt2live I appreciate the review, after all this is just a first attempt at experimenting with potential solutions that allow us to get SVG previews working.

I'll experiment further with this over the easter weekend, though I don't expect that I'll get a clean fix done soon.

(I actually thought I had left the PR in draft status, but that may have gotten lost at some point)

@justjanne justjanne changed the title Fix svg images not correctly displaying in e2ee rooms Draft: Fix svg images not correctly displaying in e2ee rooms Apr 14, 2022
@turt2live
Copy link
Member

ah, apologies for the early review then 😅

This is a relatively security sensitive area though, particularly the object URL handling.

@t3chguy t3chguy marked this pull request as draft April 19, 2022 08:35
@justjanne justjanne closed this Apr 25, 2022
@justjanne justjanne deleted the justjanne/fix/15094-18526-e2ee-broken-svg-embed branch May 19, 2022 10:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants