Skip to content

Commit 7085e18

Browse files
fix: encrypted message wrongly hides plain text
1 parent e18f3c5 commit 7085e18

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

extension/js/common/message-renderer.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,10 @@ export class MessageRenderer {
370370
loaderContext.prependEncryptedAttachment(a);
371371
return 'replaced'; // native should be hidden, custom should appear instead
372372
} else if (treatAs === 'encryptedMsg') {
373-
this.setMsgBodyAndStartProcessing(loaderContext, treatAs, messageInfo.printMailInfo, messageInfo.from?.email, renderModule =>
374-
this.processEncryptedMsgAttachment(a, renderModule, messageInfo.from?.email, messageInfo.isPwdMsgBasedOnMsgSnippet, messageInfo.plainSubject)
373+
this.setMsgBodyAndStartProcessing(
374+
loaderContext, treatAs, messageInfo.printMailInfo, messageInfo.from?.email,
375+
renderModule => this.processEncryptedMsgAttachment(a, renderModule, messageInfo.from?.email, messageInfo.isPwdMsgBasedOnMsgSnippet, messageInfo.plainSubject),
376+
'append'
375377
);
376378
return 'hidden'; // native attachment should be hidden, the "attachment" goes to the message container
377379
} else if (treatAs === 'privateKey') {
@@ -802,10 +804,11 @@ export class MessageRenderer {
802804
type: string, // for diagnostics
803805
printMailInfo: PrintMailInfo | undefined,
804806
senderEmail: string | undefined,
805-
cb: (renderModule: RenderInterface) => Promise<{ publicKeys?: string[] }>
807+
cb: (renderModule: RenderInterface) => Promise<{ publicKeys?: string[] }>,
808+
method: 'set' | 'append' = 'set'
806809
) => {
807810
const { frameId, frameXssSafe } = this.factory.embeddedMsg(type); // xss-safe-factory
808-
loaderContext.setMsgBody_DANGEROUSLY(frameXssSafe, 'set'); // xss-safe-value
811+
loaderContext.setMsgBody_DANGEROUSLY(frameXssSafe, method); // xss-safe-value
809812
this.relayAndStartProcessing(this.relayManager, this.factory, frameId, printMailInfo, senderEmail, cb);
810813
};
811814

extension/js/content_scripts/webmail/gmail/gmail-loader-context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export class GmailLoaderContext implements LoaderContextInterface {
4444
} else if (method === 'append') {
4545
if (replace) {
4646
const parent = msgBody.parent();
47-
const wrapper = msgBody.wrap(this.wrapMsgBodyEl(''));
48-
wrapper.append(newHtmlContent_MUST_BE_XSS_SAFE); // xss-reinsert // xss-safe-value
49-
this.ensureHasParentNode(wrapper); // Gmail is using msgBody.parentNode (#2271)
47+
const existingHtml = msgBody.html() || ''; // xss-direct - preserving existing Gmail-rendered content
48+
msgBody.replaceWith(this.wrapMsgBodyEl(existingHtml + newHtmlContent_MUST_BE_XSS_SAFE)); // xss-safe-value
49+
this.ensureHasParentNode(msgBody); // Gmail is using msgBody.parentNode (#2271)
5050
return parent.find('.message_inner_body'); // need to return new selector - old element was replaced
5151
} else {
5252
return msgBody.append(newHtmlContent_MUST_BE_XSS_SAFE); // xss-safe-value

test/source/tests/decrypt.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -608,17 +608,17 @@ export const defineDecryptTests = (testVariant: TestVariant, testWithBrowser: Te
608608
`decrypt - [gpgmail] encrypted utf8`,
609609
testWithBrowser(async (t, browser) => {
610610
const { authHdr } = await BrowserRecipe.setupCommonAcctWithAttester(t, browser, 'compatibility');
611-
await BrowserRecipe.pgpBlockVerifyDecryptedContent(
612-
t,
613-
browser,
614-
'161b2ac5a73d4097',
615-
{
616-
content: ['Prozent => %', 'Scharf-S => ß', 'Ue => Ü', 'Ae => Ä'],
617-
encryption: 'encrypted',
618-
signature: 'could not verify signature: missing pubkey 9BBE40BC1E8CE4A3',
619-
},
620-
authHdr
621-
);
611+
const gmailPage = await browser.newPage(t, `${t.context.urls?.mockGmailUrl()}/161b2ac5a73d4097`, undefined, authHdr);
612+
await gmailPage.waitAll('iframe');
613+
const pgpBlockFrame = await gmailPage.getFrame(['pgp_block.htm']);
614+
await BrowserRecipe.pgpBlockCheck(t, pgpBlockFrame, {
615+
content: ['Prozent => %', 'Scharf-S => ß', 'Ue => Ü', 'Ae => Ä'],
616+
encryption: 'encrypted',
617+
signature: 'could not verify signature: missing pubkey 9BBE40BC1E8CE4A3',
618+
});
619+
await gmailPage.waitForContent('.message_inner_body', '1io | Sales & Marketing');
620+
await gmailPage.waitForContent('.message_inner_body', '1io GmbH');
621+
await gmailPage.close();
622622
})
623623
);
624624

0 commit comments

Comments
 (0)