Skip to content

Commit 8d94ec7

Browse files
committed
fix(gmail): sanitize attachment mimeType in Content-Type header
attachment.mimeType was written verbatim into the Content-Type header, leaving the same CRLF-injection path the rest of the PR closes.
1 parent b56c171 commit 8d94ec7

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

apps/sim/tools/gmail/utils.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,25 @@ describe('buildMimeMessage', () => {
283283
)
284284
})
285285

286+
it('strips embedded CRLF from the attachment mimeType', () => {
287+
const injected = 'text/plain\r\nBcc: attacker@example.com'
288+
const message = buildMimeMessage({
289+
to: 'a@example.com',
290+
body: 'hello',
291+
attachments: [
292+
{
293+
filename: 'note.txt',
294+
mimeType: injected,
295+
content: Buffer.from('hi'),
296+
},
297+
],
298+
})
299+
const lines = message.split('\n')
300+
const bccLines = lines.filter((line) => line.startsWith('Bcc:'))
301+
expect(bccLines).toHaveLength(0)
302+
expect(message).toContain('Content-Type: text/plain Bcc: attacker@example.com')
303+
})
304+
286305
it('preserves legitimate ASCII, Unicode, and multi-recipient values unchanged', () => {
287306
const message = buildMimeMessage({
288307
to: 'a@example.com, b@example.com',

apps/sim/tools/gmail/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export function buildMimeMessage(params: BuildMimeMessageParams): string {
533533

534534
for (const attachment of attachments) {
535535
messageParts.push(`--${mixedBoundary}`)
536-
messageParts.push(`Content-Type: ${attachment.mimeType}`)
536+
messageParts.push(`Content-Type: ${sanitizeHeaderValue(attachment.mimeType)}`)
537537
messageParts.push(
538538
`Content-Disposition: attachment; filename="${sanitizeHeaderValue(attachment.filename)}"`
539539
)

0 commit comments

Comments
 (0)