feat(attachments): allow Office documents as outbound attachments
Bots had to zip .pptx decks because the outbound allowlist only covered images, audio/video, pdf, zip and plain-text files. Add docx/xlsx/pptx (checked for the ZIP local-file-header signature) and legacy doc/xls/ppt (checked for the OLE2 compound-file signature). The 8MB cap and the allowed-directory rules are unchanged. Prompt format lists are updated so agents stop zipping these files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,9 @@ const MINIMAL_MP4 = Buffer.from([
|
||||
]);
|
||||
const MINIMAL_PDF = Buffer.from('%PDF-1.4\n', 'ascii');
|
||||
const MINIMAL_ZIP = Buffer.from([0x50, 0x4b, 0x03, 0x04, 0x14, 0x00]);
|
||||
const MINIMAL_OLE2 = Buffer.from([
|
||||
0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1, 0x00, 0x00,
|
||||
]);
|
||||
|
||||
const cleanupDirs: string[] = [];
|
||||
const cleanupFiles: string[] = [];
|
||||
@@ -178,6 +181,46 @@ describe('validateOutboundAttachments', () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('accepts Office documents with matching container signatures', () => {
|
||||
const dir = makeTempDir(os.tmpdir(), 'ejclaw-office-');
|
||||
const names = [
|
||||
['report.docx', MINIMAL_ZIP],
|
||||
['table.xlsx', MINIMAL_ZIP],
|
||||
['slides.pptx', MINIMAL_ZIP],
|
||||
['legacy.doc', MINIMAL_OLE2],
|
||||
['legacy.xls', MINIMAL_OLE2],
|
||||
['legacy.ppt', MINIMAL_OLE2],
|
||||
] as const;
|
||||
const paths = names.map(([name, content]) => writeFile(dir, name, content));
|
||||
|
||||
const result = validateOutboundAttachments(
|
||||
paths.map((filePath) => ({ path: filePath })),
|
||||
);
|
||||
|
||||
expect(result.rejected).toEqual([]);
|
||||
expect(result.files.map((file) => file.name)).toEqual(
|
||||
names.map(([name]) => name),
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects Office documents whose signature does not match', () => {
|
||||
const dir = makeTempDir(os.tmpdir(), 'ejclaw-office-bad-');
|
||||
const fakePptx = writeFile(dir, 'fake.pptx', MINIMAL_OLE2);
|
||||
const fakePpt = writeFile(dir, 'fake.ppt', MINIMAL_ZIP);
|
||||
const textPptx = writeFile(dir, 'text.pptx', 'not a deck\n');
|
||||
|
||||
expect(
|
||||
validateOutboundAttachments([
|
||||
{ path: fakePptx },
|
||||
{ path: fakePpt },
|
||||
{ path: textPptx },
|
||||
]).rejected,
|
||||
).toEqual([
|
||||
{ path: fakePptx, reason: 'invalid-file-signature' },
|
||||
{ path: fakePpt, reason: 'invalid-file-signature' },
|
||||
{ path: textPptx, reason: 'invalid-file-signature' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateOutboundAttachments policy checks', () => {
|
||||
|
||||
@@ -35,6 +35,14 @@ const SUPPORTED_ATTACHMENT_MIMES: Record<string, string> = {
|
||||
'.flac': 'audio/flac',
|
||||
'.pdf': 'application/pdf',
|
||||
'.zip': 'application/zip',
|
||||
'.docx':
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'.pptx':
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'.doc': 'application/msword',
|
||||
'.xls': 'application/vnd.ms-excel',
|
||||
'.ppt': 'application/vnd.ms-powerpoint',
|
||||
'.txt': 'text/plain',
|
||||
'.md': 'text/markdown',
|
||||
'.csv': 'text/csv',
|
||||
@@ -222,6 +230,23 @@ function detectSupportedMime(filePath: string): string | null {
|
||||
header.subarray(0, 4).equals(Buffer.from([0x50, 0x4b, 0x07, 0x08]))
|
||||
? expectedMime
|
||||
: null;
|
||||
// Office Open XML files are ZIP containers and always start with a local
|
||||
// file header.
|
||||
case '.docx':
|
||||
case '.xlsx':
|
||||
case '.pptx':
|
||||
return header.subarray(0, 4).equals(Buffer.from([0x50, 0x4b, 0x03, 0x04]))
|
||||
? expectedMime
|
||||
: null;
|
||||
// Legacy Office files use the OLE2 compound file signature.
|
||||
case '.doc':
|
||||
case '.xls':
|
||||
case '.ppt':
|
||||
return header
|
||||
.subarray(0, 8)
|
||||
.equals(Buffer.from([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]))
|
||||
? expectedMime
|
||||
: null;
|
||||
case '.txt':
|
||||
case '.md':
|
||||
case '.csv':
|
||||
|
||||
Reference in New Issue
Block a user