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

Clipped decrypted large messages #4841

Closed
wants to merge 4 commits into from

Conversation

martgil
Copy link
Collaborator

@martgil martgil commented Dec 15, 2022

This PR clipped the decrypted large message to prevent the app from crashing

close https://github.com/FlowCrypt/flowcrypt-security/issues/215


Tests (delete all except exactly one):

  • Tests added or updated

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities
  • is documented clearly and usefully, or doesn't need documentation

@martgil martgil changed the title Clipped decrypted large message Clipped decrypted large messages Dec 15, 2022
@martgil martgil marked this pull request as draft December 15, 2022 08:44
@martgil martgil marked this pull request as ready for review December 15, 2022 09:28
@martgil
Copy link
Collaborator Author

martgil commented Dec 15, 2022

@rrrooommmaaa ready for review. thank you!

let renderableAttachments: Attachment[] = [];
let decryptedContent = decryptedBytes.toUtfStr();
let isHtml: boolean = false;
// todo - replace with MsgBlockParser.fmtDecryptedAsSanitizedHtmlBlocks, then the extract/strip methods could be private?
if (decryptedContent.length > maxDecryptedContentLength) {
decryptedContent = decryptedContent.substring(0, maxDecryptedContentLength) + ' [clipped - message too large]';
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, if the decrypted content doesn't resemble Mime message, then this decryptedContent goes into line 234 etc.
But if it does, then it goes to line 243 and then it's not clipped (restored from the non-clipped decryptedBytes).
Won't the browser extension crash if it is too long there?

And also a question: should we clip the message before or after extracting FcAttachments, replyToken and public keys. If after (which is preferred unless it consumes a lot of processing time), then we should also think about limiting the number of attachments and public keys, as too many may also crash the frame or make it otherwise unusable. If before, the output may look a bit ugly, if a pubkey or attachment link is clipped midway.

Copy link
Collaborator Author

@martgil martgil Jan 28, 2023

Choose a reason for hiding this comment

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

@rrrooommmaaa thank you sir for your helpful comments.

ok, if the decrypted content doesn't resemble Mime message, then this decryptedContent goes into line 234 etc.
But if it does, then it goes to line 243 and then it's not clipped (restored from the non-clipped decryptedBytes).
Won't the browser extension crash if it is too long there?

thank you. right it's a mistake. things should be clipped in both situation (mime/non-mime).

And also a question: should we clip the message before or after extracting FcAttachments, replyToken and public keys. If after (which is preferred unless it consumes a lot of processing time), then we should also think about limiting the number of attachments and public keys, as too many may also crash the frame or make it otherwise unusable. If before, the output may look a bit ugly, if a pubkey or attachment link is clipped midway.

Thank you for the question - this gives me more realization about the situation.

  1. We're dealing with inline attachment from web portal so that is one problem when it comes to limiting attachments.
  2. If we disregard the item no.1 (dealing with inline attachment) - I think we don't need to worry about attachments through secure message as it has 25mb? For encrypted mime messages, I think that's something we need to limit.
  3. I think it's reasonable to add a limit for number of public keys as we displayed their details on the page (we had check before rendering that it has to be a valid public key).

For now, do you think we could add limit text messages from decrypted data and then discuss about attachments, inline attachments, and pubkey limits later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@martgil were there any issues with this PR or something else should be implemented before we can finish this PR?

@sosnovsky No blocking issues. May I hear your suggestion for the following question above? I might just re-create this PR afterward. Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think here we should clip text in decrypted data after extracting all attachments, so it'll affect only rendered message text:

  • decrypt full data
  • extract all attachments
  • if message text is longer than max length - clip it
  • for attachments and public keys need to check how they affect page performance and then set MAX_ATTACHMENTS_NUMBER - maybe it'll work well even for 50 attachments

Copy link
Contributor

@rrrooommmaaa rrrooommmaaa left a comment

Choose a reason for hiding this comment

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

I'd also recommend to implement creation of a dummy message (for both MIME and non-MIME encrypted data) of an arbitrary long size (can be later adjusted) on the fly, so that we can test better how the extension reacts to extremely big messages and where exactly it hangs or crashes. We'll have to customize our mock GoogleData.getMessage() to provide a message of the required size based on id.

@martgil martgil marked this pull request as draft January 16, 2023 07:18
@martgil
Copy link
Collaborator Author

martgil commented Jan 28, 2023

I'd also recommend to implement creation of a dummy message (for both MIME and non-MIME encrypted data) of an arbitrary long size (can be later adjusted) on the fly, so that we can test better how the extension reacts to extremely big messages and where exactly it hangs or crashes. We'll have to customize our mock GoogleData.getMessage() to provide a message of the required size based on id.

You're right, we should be testing mime and non-mime messages though both will crash for extremely long messages. I'm still unsure how we could test for the right length before it crashes. I mean, let's assume that rendering 10 million chars (encrypted) will work on the better machines but that 10 million chars may be too much to handle for a dual-core PC or less (though it's acceptable as it's a comprised limitation of it).

let renderableAttachments: Attachment[] = [];
let decryptedContent: string | undefined;
let isHtml = false;
// todo - replace with MsgBlockParser.fmtDecryptedAsSanitizedHtmlBlocks, then the extract/strip methods could be private?
if (decryptedContent.length > maxDecryptedContentLength) {
decryptedContent = decryptedContent.substring(0, maxDecryptedContentLength) + ' [clipped - message too large]';

Check failure

Code scanning / CodeQL

Property access on null or undefined Error

The base expression of this property access is always undefined.
let renderableAttachments: Attachment[] = [];
let decryptedContent: string | undefined;
let isHtml = false;
// todo - replace with MsgBlockParser.fmtDecryptedAsSanitizedHtmlBlocks, then the extract/strip methods could be private?
if (decryptedContent.length > maxDecryptedContentLength) {
decryptedContent = decryptedContent.substring(0, maxDecryptedContentLength) + ' [clipped - message too large]';

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

The value assigned to decryptedContent here is unused.
let renderableAttachments: Attachment[] = [];
let decryptedContent: string | undefined;
let isHtml = false;
// todo - replace with MsgBlockParser.fmtDecryptedAsSanitizedHtmlBlocks, then the extract/strip methods could be private?
if (decryptedContent.length > maxDecryptedContentLength) {

Check failure

Code scanning / CodeQL

Property access on null or undefined Error

The base expression of this property access is always undefined.
@sosnovsky
Copy link
Collaborator

@martgil were there any issues with this PR or something else should be implemented before we can finish this PR?

@martgil martgil closed this Jun 25, 2023
@sosnovsky sosnovsky deleted the security-issue-215-clip-large-message branch August 7, 2023 10:24
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.

None yet

4 participants