From ed5e91e5816c2cfb13b32a4d3e34755276d126a7 Mon Sep 17 00:00:00 2001 From: tianzishen Date: Mon, 2 Nov 2026 15:15:06 +0800 Subject: [PATCH 1/3] fix(projects): validate OMP profile names before they reach the spawn A workspace profile name omp rejects (e.g. containing a space) was saved without complaint, then made every message in that workspace fail with HTTP 500 because the spawned omp --profile exited at startup. - lib/omp-profile.ts: shared validator mirroring omp's rule (^[a-z0-9][a-z0-9._-]{0,63}$, no trailing '.', no Windows reserved device names, with or without extension) - Launch-config dialog and add-workspace picker show the naming rule, flag invalid names live, and disable save/select - POST/PATCH /api/projects reject invalid profiles with 400 invalid_profile (subsumes the old dash-prefix-only check) - Registry reads drop invalid stored profiles so stale bad data can no longer break session spawns - extraArgs may not carry --profile / --profile= either: the forms are reserved launch args now, so they cannot bypass the validated profile field (route 400s, stored copies are dropped) - Launch-config dialog keeps its primitive's overflow scrolling so the footer stays reachable with the new hint line - i18n for en/zh-CN/ja; unit tests for the validator, read-side filter, and the --profile extraArgs bypass --- CHANGELOG.md | 1 + app/api/projects/route.ts | 3 +- components/DirectoryPicker.tsx | 9 ++++-- components/ProjectLaunchConfigDialog.tsx | 11 +++++-- lib/i18n/locales/en.json | 3 ++ lib/i18n/locales/ja.json | 3 ++ lib/i18n/locales/zh-CN.json | 3 ++ lib/omp-profile.test.mjs | 37 ++++++++++++++++++++++++ lib/omp-profile.ts | 30 +++++++++++++++++++ lib/project-registry.test.mjs | 15 +++++++--- lib/project-registry.ts | 14 ++++++--- 11 files changed, 115 insertions(+), 14 deletions(-) create mode 100644 lib/omp-profile.test.mjs create mode 100644 lib/omp-profile.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 304da937a..0acd67301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **No blank band above the composer on phones either.** Scrolling to the newest message could also shift the message area itself up, leaving an empty band above the composer until the page was reloaded. Scrolling can no longer shift the message area (Safari 16 and later; older Safari keeps the old behavior). - **Sending to a session another omp process has open no longer leaves a dead fork.** When omp moved the resumed session to a new file during startup, the tab kept the old id, the event stream failed with "Failed to connect to the agent event stream", the prompt never went, and the forked session was reaped two minutes later. The requested id now stays routable alongside the new one. - **Changing Advisor keeps a moved session on the right conversation.** A tab still using the pre-move session ID now restarts the current session file on its owning host when toggling Advisor, instead of reopening the original file, selecting another host’s copy, or returning “Session not found” if the original was removed. +- **Workspace profile names are validated before they can break sessions.** A profile containing a space (or any name omp rejects, such as uppercase letters or `CON`) was saved without complaint, then made every message in that workspace fail with an HTTP 500 because the spawned `omp --profile …` exited at startup. The profile inputs (add-workspace picker and launch-config dialog) now show the naming rule, flag invalid names live, and disable the action; the API rejects such profiles with a 400, and a stale invalid name already on disk is ignored instead of reaching the spawn. --- diff --git a/app/api/projects/route.ts b/app/api/projects/route.ts index af286fef5..612fff9c3 100644 --- a/app/api/projects/route.ts +++ b/app/api/projects/route.ts @@ -1,4 +1,5 @@ import { apiErrorResponse, opErrorResponse, resolveHostOrError } from "@/lib/api-utils"; +import { isValidOmpProfile } from "@/lib/omp-profile"; import { allowFileRoot } from "@/lib/file-access"; import { LOCAL_HOST_ID } from "@/lib/hosts/registry"; import { listProjectsAllHosts } from "@/lib/hosts/session-index"; @@ -15,7 +16,7 @@ function parseLaunchConfig(value: unknown): ProjectLaunchConfig | undefined { const raw = value as Record; const profile = raw.profile === undefined ? undefined : typeof raw.profile === "string" && raw.profile.trim() ? raw.profile.trim() : undefined; if (raw.profile !== undefined && !profile) throw new ProjectPathError("invalid_profile", "Profile must be a non-empty string"); - if (profile?.startsWith("-")) throw new ProjectPathError("invalid_profile", "Profile must not start with '-'"); + if (profile !== undefined && !isValidOmpProfile(profile)) throw new ProjectPathError("invalid_profile", "Profile names must match ^[a-z0-9][a-z0-9._-]{0,63}$, cannot end with '.', and cannot be a Windows reserved device name (CON, PRN, AUX, NUL, COM0-9, LPT0-9, or any of those with an extension)"); const advisor = raw.advisor === undefined ? undefined : raw.advisor; if (advisor !== undefined && typeof advisor !== "boolean") throw new ProjectPathError("invalid_advisor", "Advisor must be a boolean"); if (raw.extraArgs !== undefined && (!Array.isArray(raw.extraArgs) || raw.extraArgs.length > MAX_EXTRA_ARGS)) throw new ProjectPathError("invalid_extra_args", "Extra args must contain at most 32 arguments"); diff --git a/components/DirectoryPicker.tsx b/components/DirectoryPicker.tsx index 54807ed2f..f01a7d92f 100644 --- a/components/DirectoryPicker.tsx +++ b/components/DirectoryPicker.tsx @@ -3,6 +3,7 @@ import { FormEvent, useCallback, useEffect, useRef, useState } from "react"; import { createPortal } from "react-dom"; import { useModalDialog } from "@/hooks/useModalDialog"; +import { isValidOmpProfile } from "@/lib/omp-profile"; import { useI18n } from "@/lib/i18n"; import { formatApiError } from "@/lib/i18n/api-error"; import { appendProgress, cloneDirectoryName } from "@/lib/git-clone"; @@ -134,7 +135,8 @@ export function DirectoryPicker({ onCancel, onSelect, busy = false, error, host const hasUncommittedPath = pathInput.trim() !== currentPath; const cloneName = cloneUrl.trim() ? cloneDirectoryName(cloneUrl) : null; const cloneTarget = cloneName && currentPath ? `${currentPath.replace(/[\\/]+$/, "")}${currentPath.includes("\\") ? "\\" : "/"}${cloneName}` : null; - const canSelect = Boolean(currentPath) && !loading && !hasUncommittedPath && !locked && (!cloneUrl.trim() || cloneName !== null); + const profileInvalid = profile.trim() !== "" && !isValidOmpProfile(profile.trim()); + const canSelect = Boolean(currentPath) && !loading && !hasUncommittedPath && !locked && (!cloneUrl.trim() || cloneName !== null) && !profileInvalid; const goDisabled = loading || locked || !pathInput.trim(); const canNavigateUp = !locked && (Boolean(parentDirectory) || isWindowsDriveRoot(currentPath)); const submitSelection = async () => { @@ -359,7 +361,10 @@ export function DirectoryPicker({ onCancel, onSelect, busy = false, error, host {cloneLog.replace(/\r/g, "")} )} - setProfile(event.target.value)} placeholder={t("directoryPicker.profilePlaceholder")} aria-label={t("directoryPicker.profileLabel")} style={{ width: "100%", height: 30, boxSizing: "border-box", marginBottom: 7, padding: "0 8px", background: "var(--bg-panel)", border: "1px solid var(--border)", borderRadius: 6, color: "var(--text)", fontFamily: "var(--font-mono)", fontSize: 11 }} /> + setProfile(event.target.value)} placeholder={t("directoryPicker.profilePlaceholder")} aria-label={t("directoryPicker.profileLabel")} aria-invalid={profileInvalid || undefined} style={{ width: "100%", height: 30, boxSizing: "border-box", marginBottom: profileInvalid || profile.trim() ? 3 : 7, padding: "0 8px", background: "var(--bg-panel)", border: `1px solid ${profileInvalid ? "var(--status-error)" : "var(--border)"}`, borderRadius: 6, color: "var(--text)", fontFamily: "var(--font-mono)", fontSize: 11 }} /> + {profileInvalid + ?
{t("projectLaunchConfig.profileInvalid")}
+ : profile.trim() ?
{t("projectLaunchConfig.profileRule")}
: null}