-
Notifications
You must be signed in to change notification settings - Fork 53
prevent pasting large input on secure compose #4914
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
Changes from all commits
db62744
9646d45
3349f70
b90f9a5
f61d1e5
fae387d
0d21743
82782ac
8b394b3
7188655
d1f23e7
691c5df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ import { ParsedRecipients } from '../../../js/common/api/email-provider/email-pr | |
| import { Str } from '../../../js/common/core/common.js'; | ||
| import { Xss } from '../../../js/common/platform/xss.js'; | ||
| import { ViewModule } from '../../../js/common/view-module.js'; | ||
| import { Ui } from '../../../js/common/browser/ui.js'; | ||
| import { ComposeView } from '../compose.js'; | ||
| import { Lang } from '../../../js/common/lang.js'; | ||
|
|
||
| export class ComposeInputModule extends ViewModule<ComposeView> { | ||
| public squire = new window.Squire(this.view.S.cached('input_text').get(0)); | ||
|
|
@@ -78,12 +80,25 @@ export class ComposeInputModule extends ViewModule<ComposeView> { | |
| return this.view.sendBtnModule.popover.choices.richtext; | ||
| }; | ||
|
|
||
| public willInputLimitBeExceeded = (textToPaste: string, targetInputField: HTMLElement, selectionLengthGetter: () => number | undefined) => { | ||
| const limit = 50000; | ||
| const toBeRemoved = selectionLengthGetter() || 0; | ||
| const currentLength = targetInputField.innerText.trim().length; | ||
| const isInputLimitExceeded = currentLength - toBeRemoved + textToPaste.length > limit; | ||
| return isInputLimitExceeded; | ||
| }; | ||
|
|
||
| private handlePaste = () => { | ||
| this.squire.addEventListener('willPaste', (e: WillPasteEvent) => { | ||
| this.squire.addEventListener('willPaste', async (e: WillPasteEvent) => { | ||
| const div = document.createElement('div'); | ||
| div.appendChild(e.fragment); | ||
| const html = div.innerHTML; | ||
| const sanitized = this.isRichText() ? Xss.htmlSanitizeKeepBasicTags(html, 'IMG-KEEP') : Xss.htmlSanitizeAndStripAllTags(html, '<br>', false); | ||
| if (this.willInputLimitBeExceeded(sanitized, this.squire.getRoot(), () => this.squire.getSelectedText().length)) { | ||
| e.preventDefault(); | ||
| await Ui.modal.warning(Lang.compose.inputLimitExceededOnPaste); | ||
| return; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right - you are correct. So that |
||
| Xss.setElementContentDANGEROUSLY(div, sanitized); // xss-sanitized | ||
| e.fragment.appendChild(div); | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.