feat: support Office documents in chat attachments

Users can now attach Microsoft Office documents (.docx, .pptx, and .xlsx) and OpenDocument files (.odt, .odp, and .ods) from the shared web, desktop, mobile, and VS Code chat surfaces.

Document text is extracted locally and sent as a text/plain file part with the original filename, keeping the visible user message clean. Supported embedded PNG, JPEG, GIF, and WebP images are sent as separate image parts, with matching [filename] citations preserved near their source paragraph, slide object, spreadsheet cell anchor, or OpenDocument position. Presentation notes, spreadsheet values, headers, and footers are included where available.

Document expansion is metadata-validated and bounded against oversized entries, excessive uncompressed data, unsafe paths, invalid image signatures, attachment-name races, and dangling citations after truncation. Generated document parts are published to the composer atomically.

Add fflate for worker-backed ZIP extraction and narrowly allow blob workers in the VS Code webview CSP without permitting blob scripts. Include focused fixtures for every supported format, extraction limits, positional citations, collision recovery, atomic attachment state, and CSP behavior.
This commit is contained in:
Bohdan Triapitsyn
2026-07-22 13:11:42 +03:00
parent d7a93c5ec0
commit fd0f6a6bac
12 changed files with 985 additions and 25 deletions
+2
View File
@@ -39,6 +39,8 @@ Keep `bridge.ts` as a thin orchestration layer that delegates message handling t
- dropped-file parsing and attachment reading
- models metadata fetch helper
The webview CSP permits `blob:` only for `worker-src` so shared UI parsers can run bounded local decompression off the main thread. Blob scripts remain disallowed by `script-src`.
- `bridge-localfs-proxy-runtime.ts`
- Local `/api/fs/read` and `/api/fs/raw` proxy helpers and shared proxy utility helpers.
+16
View File
@@ -0,0 +1,16 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { describe, test } from 'node:test';
const source = readFileSync(new URL('./webviewHtml.ts', import.meta.url), 'utf8');
describe('VS Code webview content security policy', () => {
test('allows blob URLs for workers without allowing blob scripts', () => {
const workerSource = source.match(/const workerSrc = ([^\n]+);/)?.[1] ?? '';
const scriptSource = source.match(/const scriptSrc = ([^\n]+);/)?.[1] ?? '';
assert.match(workerSource, /'blob:'/);
assert.doesNotMatch(scriptSource, /'blob:'/);
assert.match(source, /worker-src \$\{workerSrc\}/);
});
});
+3 -1
View File
@@ -68,7 +68,9 @@ export function getWebviewHtml(options: WebviewHtmlOptions): string {
const connectSrc = uniqueTokens(['*', 'ws:', 'wss:', 'http:', 'https:', devServerOrigin]);
const imgSrc = uniqueTokens([webview.cspSource, 'data:', 'https:', devServerOrigin]);
const fontSrc = uniqueTokens([webview.cspSource, 'data:', devServerOrigin]);
const workerSrc = uniqueTokens([webview.cspSource, devServerOrigin]);
// fflate's async browser inflater creates blob-backed workers. Keep blob:
// scoped to worker-src so document decompression works without allowing blob scripts.
const workerSrc = uniqueTokens([webview.cspSource, 'blob:', devServerOrigin]);
const themeKind = getThemeKindName(vscode.window.activeColorTheme.kind);