Skip to content

Commit a82e060

Browse files
andris9claude
andcommitted
fix: enforce disableFileAccess/disableUrlAccess for raw message option
MailComposer.compile() built the root MimeNode for a message-level `raw` option with only { newline }, omitting the disableFileAccess / disableUrlAccess flags that every other content-node builder threads. As a result `raw: { path: '/etc/passwd' }` or `raw: { href: 'http://169.254.169.254/...' }` was read/fetched even when an application set those flags to sandbox untrusted input, and the file or HTTP-response bytes became the delivered RFC822 message for all transports — arbitrary local-file disclosure and full-response SSRF. Thread both flags onto the raw root node so _getStream() enforces them consistently with attachments, alternatives, html/text and icalEvent. Add regression tests asserting raw:{path}/raw:{href} reject with EFILEACCESS/EURLACCESS when the flags are set. Refs GHSA-p6gq-j5cr-w38f Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 4e58450 commit a82e060

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎lib/mail-composer/index.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class MailComposer {
3232

3333
// Compose MIME tree
3434
if (this.mail.raw) {
35-
this.message = new MimeNode('message/rfc822', { newline: this.mail.newline }).setRaw(this.mail.raw);
35+
this.message = new MimeNode('message/rfc822', {
36+
newline: this.mail.newline,
37+
disableUrlAccess: this.mail.disableUrlAccess,
38+
disableFileAccess: this.mail.disableFileAccess
39+
}).setRaw(this.mail.raw);
3640
} else if (this._useMixed) {
3741
this.message = this._createMixed();
3842
} else if (this._useAlternative) {

‎test/mail-composer/mail-composer-test.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,56 @@ describe('MailComposer unit tests', () => {
11341134
done();
11351135
});
11361136
});
1137+
1138+
it('should load raw message from file', (t, done) => {
1139+
let data = {
1140+
raw: {
1141+
path: __dirname + '/fixtures/attachment.bin'
1142+
}
1143+
};
1144+
1145+
let mail = new MailComposer(data).compile();
1146+
mail.build((err, message) => {
1147+
assert.ok(!err);
1148+
// raw content is emitted verbatim (not base64-encoded like an attachment)
1149+
assert.ok(message.toString().includes('õkva'));
1150+
done();
1151+
});
1152+
});
1153+
1154+
it('should not load raw message from file if disableFileAccess is set', (t, done) => {
1155+
let data = {
1156+
raw: {
1157+
path: __dirname + '/fixtures/attachment.bin'
1158+
},
1159+
disableFileAccess: true
1160+
};
1161+
1162+
let mail = new MailComposer(data).compile();
1163+
mail.build((err, message) => {
1164+
assert.ok(err);
1165+
assert.strictEqual(err.code, 'EFILEACCESS');
1166+
assert.ok(!message);
1167+
done();
1168+
});
1169+
});
1170+
1171+
it('should not load raw message from url if disableUrlAccess is set', (t, done) => {
1172+
let data = {
1173+
raw: {
1174+
href: 'http://localhost:1/raw'
1175+
},
1176+
disableUrlAccess: true
1177+
};
1178+
1179+
let mail = new MailComposer(data).compile();
1180+
mail.build((err, message) => {
1181+
assert.ok(err);
1182+
assert.strictEqual(err.code, 'EURLACCESS');
1183+
assert.ok(!message);
1184+
done();
1185+
});
1186+
});
11371187
});
11381188
});
11391189

0 commit comments

Comments
 (0)