Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix: address review — path security, async safety, accessibility

cyhhao81c9d4e21f72
diff --git a/ui/src/components/steps/ChannelList.tsx b/ui/src/components/steps/ChannelList.tsx
index 444229343..47bb3813a 100644
--- a/ui/src/components/steps/ChannelList.tsx
+++ b/ui/src/components/steps/ChannelList.tsx
@@ -453,7 +453,7 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
require_mention: rawConfig.require_mention !== undefined ? rawConfig.require_mention : def.require_mention,
};
- const effectiveCwd = channelConfig.custom_cwd || config.runtime?.default_cwd || '.';
+ const effectiveCwd = channelConfig.custom_cwd || config.runtime?.default_cwd || '~/work';
const opencodeOptions = opencodeOptionsByCwd[effectiveCwd];
const claudeAgents = claudeAgentsByCwd[effectiveCwd] || [];
return (
diff --git a/ui/src/components/ui/directory-browser.tsx b/ui/src/components/ui/directory-browser.tsx
index e93193f67..e0f40c624 100644
--- a/ui/src/components/ui/directory-browser.tsx
+++ b/ui/src/components/ui/directory-browser.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useState, useCallback } from 'react';
+import React, { useEffect, useState, useCallback, useRef } from 'react';
import { Folder, FolderOpen, ChevronRight, ArrowUp, X, Check, RefreshCw } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useApi } from '../../context/ApiContext';
@@ -27,12 +27,31 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
+ // Guard against setState after unmount / stale responses
+ const mountedRef = useRef(true);
+ const reqIdRef = useRef(0);
+
+ useEffect(() => {
+ return () => { mountedRef.current = false; };
+ }, []);
+
+ // Esc key to close
+ useEffect(() => {
+ const onKey = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') onClose();
+ };
+ window.addEventListener('keydown', onKey);
+ return () => window.removeEventListener('keydown', onKey);
+ }, [onClose]);
+
const browse = useCallback(
async (path: string) => {
+ const id = ++reqIdRef.current;
setLoading(true);
setError(null);
try {
const result = await api.browseDirectory(path);
+ if (!mountedRef.current || reqIdRef.current !== id) return;
if (result.ok) {
setCurrentPath(result.path ?? path);
setParent(result.parent ?? null);
@@ -41,9 +60,12 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
setError(result.error ?? 'Unknown error');
}
} catch (e: any) {
+ if (!mountedRef.current || reqIdRef.current !== id) return;
setError(e.message ?? String(e));
} finally {
- setLoading(false);
+ if (mountedRef.current && reqIdRef.current === id) {
+ setLoading(false);
+ }
}
},
[api],
@@ -67,8 +89,16 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
}, [])
: [];
+ const canConfirm = !!currentPath && !loading && !error;
+
return (
- <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40" onClick={onClose}>
+ <div
+ className="fixed inset-0 z-50 flex items-center justify-center bg-black/40"
+ role="dialog"
+ aria-modal="true"
+ aria-label={t('directoryBrowser.title')}
+ onClick={onClose}
+ >
<div
className="bg-panel border border-border rounded-xl shadow-xl w-full max-w-lg max-h-[70vh] flex flex-col"
onClick={(e) => e.stopPropagation()}
@@ -140,11 +170,17 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({
{/* Footer — current path + confirm */}
<div className="px-4 py-3 border-t border-border flex items-center gap-2">
<code className="flex-1 text-xs font-mono text-text bg-bg border border-border rounded px-2 py-1.5 truncate">
- {currentPath}
+ {currentPath || '—'}
</code>
<button
- onClick={() => onSelect(currentPath)}
- className="flex items-center gap-1.5 px-4 py-1.5 bg-accent hover:bg-accent/90 text-white rounded-lg text-sm font-medium transition-colors shrink-0"
+ onClick={() => canConfirm && onSelect(currentPath)}
+ disabled={!canConfirm}
+ className={clsx(
+ 'flex items-center gap-1.5 px-4 py-1.5 rounded-lg text-sm font-medium transition-colors shrink-0',
+ canConfirm
+ ? 'bg-accent hover:bg-accent/90 text-white'
+ : 'bg-neutral-200 text-muted cursor-not-allowed',
+ )}
>
<Check size={14} />
{t('directoryBrowser.select')}
diff --git a/vibe/api.py b/vibe/api.py
index ed404f148..55f867de9 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -25,37 +25,41 @@ logger = logging.getLogger(__name__)
_OPENCODE_OPTIONS_CACHE: dict[str, dict] = {}
_OPENCODE_OPTIONS_TTL_SECONDS = 30.0
-# Directories to hide in the browse_directory listing
-_HIDDEN_DIR_PREFIXES = (".", "__")
-
def browse_directory(path: str) -> dict:
"""List sub-directories of *path* for the directory browser UI.
+ Restricted to the user's home directory tree. Symlinks are not
+ followed when scanning entries, preventing escape via crafted links.
+
Returns ``{"ok": True, "path": <abs>, "parent": <abs|None>, "dirs": [...]}``
where each entry in *dirs* is ``{"name": ..., "path": ...}``.
"""
try:
- expanded = os.path.expanduser(path or "~")
- abs_path = os.path.abspath(expanded)
+ home = Path.home().resolve()
+ target = Path(os.path.expanduser(path or "~")).resolve()
+
+ # Restrict browsing to within the user's home directory
+ try:
+ target.relative_to(home)
+ except ValueError:
+ return {"ok": False, "error": "path_out_of_scope"}
- if not os.path.isdir(abs_path):
- return {"ok": False, "error": f"Not a directory: {abs_path}"}
+ if not target.is_dir():
+ return {"ok": False, "error": f"Not a directory: {target}"}
- parent = os.path.dirname(abs_path) if abs_path != "/" else None
+ abs_path = str(target)
+ parent = str(target.parent) if target != home else None
entries: list[dict[str, str]] = []
try:
- names = sorted(os.listdir(abs_path), key=str.lower)
+ for entry in sorted(os.scandir(abs_path), key=lambda e: e.name.lower()):
+ if entry.name.startswith("."):
+ continue
+ if entry.is_dir(follow_symlinks=False):
+ entries.append({"name": entry.name, "path": str(target / entry.name)})
except PermissionError:
- return {"ok": True, "path": abs_path, "parent": parent, "dirs": []}
-
- for name in names:
- if any(name.startswith(p) for p in _HIDDEN_DIR_PREFIXES):
- continue
- full = os.path.join(abs_path, name)
- if os.path.isdir(full):
- entries.append({"name": name, "path": full})
+ return {"ok": False, "error": "permission_denied"}
return {"ok": True, "path": abs_path, "parent": parent, "dirs": entries}
except Exception as exc:
diff --git a/vibe/runtime.py b/vibe/runtime.py
index 6806ed3e9..36dfd6e4f 100644
--- a/vibe/runtime.py
+++ b/vibe/runtime.py
@@ -82,11 +82,13 @@ def ensure_dirs():
def default_config():
+ work_dir = Path.home() / "work"
+ work_dir.mkdir(parents=True, exist_ok=True)
return V2Config(
mode="self_host",
version="v2",
slack=SlackConfig(bot_token="", app_token=""),
- runtime=RuntimeConfig(default_cwd=str(Path.home() / "work")),
+ runtime=RuntimeConfig(default_cwd=str(work_dir)),
agents=AgentsConfig(
default_backend="opencode",
opencode=OpenCodeConfig(enabled=True, cli_path="opencode"),