Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(security): harden #79 terminal file-drop + dedupe onto pathForFile

Chaitanya Giria1893ec98ee0
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 6557f527..a91dcef6 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -370,13 +370,6 @@ const api = {
ipcRenderer.invoke('pty:spawn', opts),
writePty: (id: string, data: string): Promise<{ ok: boolean; error?: string }> =>
ipcRenderer.invoke('pty:write', id, data),
- /** Resolve the absolute filesystem path of a dropped/selected File. Electron 32
- * removed `File.path`; `webUtils.getPathForFile` is the supported replacement
- * and must run in the preload (it isn't on `window`). Returns '' if unknown
- * (e.g. a synthetic File that never came from disk). */
- getFilePath: (file: File): string => {
- try { return webUtils.getPathForFile(file) || ''; } catch { return ''; }
- },
resizePty: (id: string, cols: number, rows: number): Promise<{ ok: boolean; error?: string }> =>
ipcRenderer.invoke('pty:resize', id, cols, rows),
killPty: (id: string): Promise<{ ok: boolean; error?: string }> =>
diff --git a/src/renderer/src/components/PtyTerminalView.tsx b/src/renderer/src/components/PtyTerminalView.tsx
index b7e01a63..03d17b56 100644
--- a/src/renderer/src/components/PtyTerminalView.tsx
+++ b/src/renderer/src/components/PtyTerminalView.tsx
@@ -287,11 +287,21 @@ export function PtyTerminalView({ ptyId, onStreamData, onUserPrompt, onToggleFul
if (files.length === 0) return; // not a file drop — let xterm handle it
e.preventDefault();
const paths = files
- .map((f) => window.cth.getFilePath(f))
+ .map((f) => window.cth.pathForFile(f))
.filter(Boolean)
- // Backslash-escape whitespace/quotes so each path lands as a single token,
- // matching what a real terminal emits on drag-drop.
- .map((p) => p.replace(/(["'\\ \t])/g, '\\$1'));
+ // SECURITY: a dropped filename is attacker-controllable; inject it as an
+ // INERT single token. (1) Strip ALL control chars - newline/CR would be
+ // delivered as Enter by writePty and AUTO-SUBMIT the line; ESC would inject
+ // raw terminal escape sequences. (2) Wrap the cleaned path in POSIX single
+ // quotes (embedded quote -> close/escape/reopen) so $ ` ; | & space and
+ // every other shell metacharacter is literal and cannot run even on Enter.
+ // (String.fromCharCode keeps backslashes/control chars out of this source.)
+ .map((p) => {
+ const SQ = String.fromCharCode(39);
+ const BS = String.fromCharCode(92);
+ const CTRL = new RegExp('[' + String.fromCharCode(0) + '-' + String.fromCharCode(31) + String.fromCharCode(127) + ']', 'g');
+ return SQ + p.replace(CTRL, '').split(SQ).join(SQ + BS + SQ + SQ) + SQ;
+ });
if (paths.length === 0) return;
// Trailing space separates consecutive drops and lets the user keep typing.
void window.cth.writePty(ptyId, paths.join(' ') + ' ');