-
-
Notifications
You must be signed in to change notification settings - Fork 830
Draft: Fix svg images not correctly displaying in e2ee rooms #8325
Draft: Fix svg images not correctly displaying in e2ee rooms #8325
Conversation
Codecov Report
@@ 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
|
- 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)
6506f08
to
c779376
Compare
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. |
There was a problem hiding this 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.
public get sourceBlob() { | ||
return this.sourceTypedBlob.value.then(it => it.data); | ||
} | ||
public get thumbnailBlob() { | ||
return this.thumbnailTypedBlob.value.then(it => it.data); | ||
} |
There was a problem hiding this comment.
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
public readonly sourceBlob: LazyValue<Blob>; | ||
public readonly thumbnailBlob: LazyValue<Blob>; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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)}`; |
There was a problem hiding this comment.
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.
@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) |
ah, apologies for the early review then 😅 This is a relatively security sensitive area though, particularly the object URL handling. |
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