Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(app): install file drop guard to prevent unwanted navigation

Steven Enamakelbecc99a348f6
diff --git a/app/src/App.tsx b/app/src/App.tsx
index fa3f3c4102..beb2237ee4 100644
--- a/app/src/App.tsx
+++ b/app/src/App.tsx
@@ -50,6 +50,7 @@ import {
import { persistor, store } from './store';
import { DEV_FORCE_ONBOARDING } from './utils/config';
import { installExternalLinkGuard } from './utils/externalLinkGuard';
+import { installFileDropGuard } from './utils/fileDropGuard';
startNativeNotificationsService();
// Connectivity status (#1527): wire navigator.onLine + start core sidecar
@@ -77,6 +78,11 @@ function App() {
// router, so it is live for the whole session.
useEffect(() => installExternalLinkGuard(), []);
+ // Same one-way trap for a dropped file: unclaimed, the webview opens it as
+ // the top-level document. Only an open chat thread takes files; everywhere
+ // else the drop is refused.
+ useEffect(() => installFileDropGuard(), []);
+
// On mobile (iOS or Android) the SocketProvider would try to connect to the
// local core HTTP socket, which does not exist on device (the core runs on
// the remote desktop). Gate it out to prevent spurious connection errors —
diff --git a/app/src/utils/fileDropGuard.ts b/app/src/utils/fileDropGuard.ts
index 34fffdbe10..d82b41c187 100644
--- a/app/src/utils/fileDropGuard.ts
+++ b/app/src/utils/fileDropGuard.ts
@@ -1,6 +1,6 @@
-import debug from 'debug';
+import debugFactory from 'debug';
-const log = debug('file-drop-guard');
+const log = debugFactory('openhuman:file-drop-guard');
/** True when the drag carries OS files, as opposed to text or an in-app payload. */
export function isFileDrag(event: DragEvent): boolean {
@@ -43,7 +43,7 @@ export function installFileDropGuard(doc: Document = document): () => void {
const onDrop = (event: DragEvent) => {
if (event.defaultPrevented || !isFileDrag(event) || isNativeFileInput(event.target)) return;
event.preventDefault();
- log('refused file drop outside a drop target');
+ log('[file-drop-guard] refused file drop outside a drop target');
};
doc.addEventListener('dragover', onDragOver);